diff --git a/Apps/Playground/Scripts/config.json b/Apps/Playground/Scripts/config.json index f4c16803b..f3328016f 100644 --- a/Apps/Playground/Scripts/config.json +++ b/Apps/Playground/Scripts/config.json @@ -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", diff --git a/CMakeLists.txt b/CMakeLists.txt index b41cc202c..dc4e48ff8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/Plugins/NativeEngine/Source/NativeEngine.cpp b/Plugins/NativeEngine/Source/NativeEngine.cpp index cd822de9b..38cfb856d 100644 --- a/Plugins/NativeEngine/Source/NativeEngine.cpp +++ b/Plugins/NativeEngine/Source/NativeEngine.cpp @@ -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; @@ -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()); diff --git a/Plugins/NativeXr/Source/NativeXrImpl.cpp b/Plugins/NativeXr/Source/NativeXrImpl.cpp index cd28e629d..72a1185e0 100644 --- a/Plugins/NativeXr/Source/NativeXrImpl.cpp +++ b/Plugins/NativeXr/Source/NativeXrImpl.cpp @@ -275,15 +275,22 @@ namespace Babylon arcana::make_task(m_sessionState->GraphicsContext.AfterRenderScheduler(), arcana::cancellation::none(), [colorTexture, depthTexture, &viewConfig]() { bgfx::overrideInternal(colorTexture, reinterpret_cast(viewConfig.ColorTexturePointer)); bgfx::overrideInternal(depthTexture, reinterpret_cast(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(1), static_cast(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 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(attachments.size()), attachments.data(), false); diff --git a/Polyfills/Canvas/Source/Canvas.cpp b/Polyfills/Canvas/Source/Canvas.cpp index 74c0d51be..ef1332434 100644 --- a/Polyfills/Canvas/Source/Canvas.cpp +++ b/Polyfills/Canvas/Source/Canvas.cpp @@ -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 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(attachments.size()), attachments.data(), true); assert(handle.idx != bgfx::kInvalidHandle); m_frameBuffer = std::make_unique(m_graphicsContext, handle, m_width, m_height, false, false, false); diff --git a/Polyfills/Canvas/Source/FrameBufferPool.cpp b/Polyfills/Canvas/Source/FrameBufferPool.cpp index ea7b415ff..cae0711c2 100644 --- a/Polyfills/Canvas/Source/FrameBufferPool.cpp +++ b/Polyfills/Canvas/Source/FrameBufferPool.cpp @@ -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 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(attachments.size()), attachments.data(), true); FrameBuffer = new Graphics::FrameBuffer(*m_graphicsContext, TextBuffer, m_width, m_height, false, false, false);