Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions Apps/Playground/Scripts/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,32 +328,20 @@
{
"title": "Scissor test",
"playgroundId": "#W7E7CF#34",
"referenceImage": "scissor-test.png",
"excludedGraphicsApis": [ "D3D12" ],
"comments": {
"D3D12": "reenable when automatic mip-maps issue is fixed in bgfx"
}
"referenceImage": "scissor-test.png"
},
{
"title": "Scissor test with 0.9 hardware scaling",
"playgroundId": "#W7E7CF#34",
"replace": "//options//, hardwareScalingLevel = 0.9;",
"referenceImage": "scissor-test-2.png",
"excludedGraphicsApis": [ "D3D12" ],
"errorRatio": 50,
"comments": {
"D3D12": "reenable when automatic mip-maps issue is fixed in bgfx"
}
"errorRatio": 50
},
{
"title": "Scissor test with 1.5 hardware scaling",
"playgroundId": "#W7E7CF#34",
"replace": "//options//, hardwareScalingLevel = 1.5;",
"referenceImage": "scissor-test-3.png",
"excludedGraphicsApis": [ "D3D12" ],
"comments": {
"D3D12": "reenable when automatic mip-maps issue is fixed in bgfx"
}
"referenceImage": "scissor-test-3.png"
},
{
"title": "Scissor test with negative x and y",
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ FetchContent_Declare(base-n
EXCLUDE_FROM_ALL)
FetchContent_Declare(bgfx.cmake
GIT_REPOSITORY https://github.com/BabylonJS/bgfx.cmake.git
GIT_TAG be466af2a964bf2d2d28fdaf1543d89129c7fe21
GIT_TAG a0adee5ccad355a0b91f9247402ed422aaee4f2e
EXCLUDE_FROM_ALL)
FetchContent_Declare(CMakeExtensions
GIT_REPOSITORY https://github.com/BabylonJS/CMakeExtensions.git
Expand Down
10 changes: 8 additions & 2 deletions Plugins/NativeEngine/Source/NativeEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,13 @@ namespace Babylon

if (texture != nullptr)
{
attachments[numAttachments++].init(texture->Handle());
const bgfx::Caps* caps = bgfx::getCaps();
// bgfx validation now asserts when trying to use BGFX_RESOLVE_AUTO_GEN_MIPS with a texture that doesn't have the BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN flag,
// but before it would just ignore the flag and not generate mips without any warning. This prevents validation assert, but rendering might be broken if autogen
// mips were expected. Basically this change preserves previous behavior.
attachments[numAttachments++].init(texture->Handle(), bgfx::Access::Write, 0, 1, 0
, 0 != (caps->formats[texture->Format()] & BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN) ? BGFX_RESOLVE_AUTO_GEN_MIPS : BGFX_RESOLVE_NONE
);
}

bgfx::TextureHandle depthStencilTextureHandle = BGFX_INVALID_HANDLE;
Expand Down Expand Up @@ -1772,7 +1778,7 @@ namespace Babylon
// only allows mipmaps resolve step when mipmapping is asked and for the color texture, not the depth.
// https://github.com/bkaradzic/bgfx/blob/2c21f68998595fa388e25cb6527e82254d0e9bff/src/renderer_d3d11.cpp#L4525
depthStencilAttachmentIndex = numAttachments;
attachments[numAttachments++].init(depthStencilTextureHandle);
attachments[numAttachments++].init(depthStencilTextureHandle, bgfx::Access::Write, 0, 1, 0, BGFX_RESOLVE_NONE);
}

bgfx::FrameBufferHandle frameBufferHandle = bgfx::createFrameBuffer(numAttachments, attachments.data());
Expand Down
13 changes: 10 additions & 3 deletions Plugins/NativeXr/Source/NativeXrImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,22 @@ namespace Babylon
arcana::make_task(m_sessionState->GraphicsContext.AfterRenderScheduler(), arcana::cancellation::none(), [colorTexture, depthTexture, &viewConfig]() {
bgfx::overrideInternal(colorTexture, reinterpret_cast<uintptr_t>(viewConfig.ColorTexturePointer));
bgfx::overrideInternal(depthTexture, reinterpret_cast<uintptr_t>(viewConfig.DepthTexturePointer));
}).then(m_runtimeScheduler, m_sessionState->CancellationSource, [this, thisRef{shared_from_this()}, colorTexture, depthTexture, requiresAppClear, &viewConfig]() {
}).then(m_runtimeScheduler, m_sessionState->CancellationSource, [this, thisRef{shared_from_this()}, colorTexture, depthTexture, colorTextureFormat, requiresAppClear, &viewConfig]() {
const auto eyeCount = std::max(static_cast<uint16_t>(1), static_cast<uint16_t>(viewConfig.ViewTextureSize.Depth));
// TODO (rgerd): Remove old framebuffers from resource table?
viewConfig.FrameBuffers.resize(eyeCount);
for (uint16_t eyeIdx = 0; eyeIdx < eyeCount; eyeIdx++)
{
// See NativeEngine::CreateFrameBuffer: gate BGFX_RESOLVE_AUTO_GEN_MIPS on format caps and
// always pass BGFX_RESOLVE_NONE for depth (depth formats don't support autogen mips).
const bgfx::Caps* caps = bgfx::getCaps();
const uint8_t colorResolve = 0 != (caps->formats[colorTextureFormat] & BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN)
? BGFX_RESOLVE_AUTO_GEN_MIPS
: BGFX_RESOLVE_NONE;

std::array<bgfx::Attachment, 2> attachments{};
attachments[0].init(colorTexture, bgfx::Access::Write, eyeIdx);
attachments[1].init(depthTexture, bgfx::Access::Write, eyeIdx);
attachments[0].init(colorTexture, bgfx::Access::Write, eyeIdx, 1, 0, colorResolve);
attachments[1].init(depthTexture, bgfx::Access::Write, eyeIdx, 1, 0, BGFX_RESOLVE_NONE);

auto frameBufferHandle = bgfx::createFrameBuffer(static_cast<uint8_t>(attachments.size()), attachments.data(), false);

Expand Down
14 changes: 10 additions & 4 deletions Polyfills/Canvas/Source/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,17 @@ namespace Babylon::Polyfills::Internal
bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_RT, mem),
bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT)};

// See NativeEngine::CreateFrameBuffer: bgfx validation now asserts when BGFX_RESOLVE_AUTO_GEN_MIPS is used
// with a texture whose format doesn't have BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN. Gate the color attachment
// on the capability and pass BGFX_RESOLVE_NONE for the depth attachment (depth formats never support autogen).
const bgfx::Caps* caps = bgfx::getCaps();
const uint8_t colorResolve = 0 != (caps->formats[bgfx::TextureFormat::RGBA8] & BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN)
? BGFX_RESOLVE_AUTO_GEN_MIPS
: BGFX_RESOLVE_NONE;

std::array<bgfx::Attachment, textures.size()> attachments{};
for (size_t idx = 0; idx < attachments.size(); ++idx)
{
attachments[idx].init(textures[idx]);
}
attachments[0].init(textures[0], bgfx::Access::Write, 0, 1, 0, colorResolve);
attachments[1].init(textures[1], bgfx::Access::Write, 0, 1, 0, BGFX_RESOLVE_NONE);
auto handle = bgfx::createFrameBuffer(static_cast<uint8_t>(attachments.size()), attachments.data(), true);
assert(handle.idx != bgfx::kInvalidHandle);
m_frameBuffer = std::make_unique<Graphics::FrameBuffer>(m_graphicsContext, handle, m_width, m_height, false, false, false);
Expand Down
14 changes: 10 additions & 4 deletions Polyfills/Canvas/Source/FrameBufferPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@ namespace Babylon::Polyfills
bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_RT | BGFX_SAMPLER_U_BORDER | BGFX_SAMPLER_V_BORDER | BGFX_SAMPLER_BORDER_COLOR(0), mem),
bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT | BGFX_SAMPLER_U_BORDER | BGFX_SAMPLER_V_BORDER | BGFX_SAMPLER_BORDER_COLOR(0))};

// See NativeEngine::CreateFrameBuffer: bgfx validation now asserts when BGFX_RESOLVE_AUTO_GEN_MIPS is used
// with a texture whose format doesn't have BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN. Gate the color attachment
// on the capability and pass BGFX_RESOLVE_NONE for the depth attachment (depth formats never support autogen).
const bgfx::Caps* caps = bgfx::getCaps();
const uint8_t colorResolve = 0 != (caps->formats[bgfx::TextureFormat::RGBA8] & BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN)
? BGFX_RESOLVE_AUTO_GEN_MIPS
: BGFX_RESOLVE_NONE;

std::array<bgfx::Attachment, textures.size()> attachments{};
for (size_t idx = 0; idx < attachments.size(); ++idx)
{
attachments[idx].init(textures[idx]);
}
attachments[0].init(textures[0], bgfx::Access::Write, 0, 1, 0, colorResolve);
attachments[1].init(textures[1], bgfx::Access::Write, 0, 1, 0, BGFX_RESOLVE_NONE);
TextBuffer = bgfx::createFrameBuffer(static_cast<uint8_t>(attachments.size()), attachments.data(), true);

FrameBuffer = new Graphics::FrameBuffer(*m_graphicsContext, TextBuffer, m_width, m_height, false, false, false);
Expand Down