diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index f74fb3925..83c94493e 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -5805,8 +5805,6 @@ namespace bgfx { namespace d3d12 m_batch.begin(); -// uint8_t eye = 0; -// uint8_t restartState = 0; viewState.m_rect = _render->m_view[0].m_rect; int32_t numItems = _render->m_numRenderItems; @@ -5932,90 +5930,100 @@ namespace bgfx { namespace d3d12 Bind* bindCached = bindLru.find(bindHash); if (NULL == bindCached) { + uint32_t numSet = 0; D3D12_GPU_DESCRIPTOR_HANDLE srvHandle[BGFX_MAX_COMPUTE_BINDINGS] = {}; uint32_t samplerFlags[BGFX_MAX_COMPUTE_BINDINGS] = {}; - - for (uint8_t stage = 0; stage < maxComputeBindings; ++stage) { - const Binding& bind = renderBind.m_bind[stage]; - if (kInvalidHandle != bind.m_idx) + for (uint8_t stage = 0; stage < maxComputeBindings; ++stage) { - switch (bind.m_type) + const Binding& bind = renderBind.m_bind[stage]; + if (kInvalidHandle != bind.m_idx) { - case Binding::Image: + switch (bind.m_type) { - TextureD3D12& texture = m_textures[bind.m_idx]; + case Binding::Image: + { + TextureD3D12& texture = m_textures[bind.m_idx]; - if (Access::Read != bind.m_access) - { - texture.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); - scratchBuffer.allocUav(srvHandle[stage], texture, bind.m_mip); + if (Access::Read != bind.m_access) + { + texture.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + scratchBuffer.allocUav(srvHandle[stage], texture, bind.m_mip); + } + else + { + texture.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); + scratchBuffer.allocSrv(srvHandle[stage], texture, bind.m_mip); + samplerFlags[stage] = uint32_t(texture.m_flags); + } + + ++numSet; } - else + break; + + case Binding::Texture: { + TextureD3D12& texture = m_textures[bind.m_idx]; texture.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); - scratchBuffer.allocSrv(srvHandle[stage], texture, bind.m_mip); - samplerFlags[stage] = uint32_t(texture.m_flags); + scratchBuffer.allocSrv(srvHandle[stage], texture); + samplerFlags[stage] = (0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & bind.m_samplerFlags) + ? bind.m_samplerFlags + : texture.m_flags + ) & (BGFX_SAMPLER_BITS_MASK | BGFX_SAMPLER_BORDER_COLOR_MASK | BGFX_SAMPLER_COMPARE_MASK) + ; + + ++numSet; } - } - break; + break; - case Binding::Texture: - { - TextureD3D12& texture = m_textures[bind.m_idx]; - texture.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); - scratchBuffer.allocSrv(srvHandle[stage], texture); - samplerFlags[stage] = (0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & bind.m_samplerFlags) - ? bind.m_samplerFlags - : texture.m_flags - ) & (BGFX_SAMPLER_BITS_MASK | BGFX_SAMPLER_BORDER_COLOR_MASK | BGFX_SAMPLER_COMPARE_MASK) - ; - } - break; - - case Binding::IndexBuffer: - case Binding::VertexBuffer: - { - BufferD3D12& buffer = Binding::IndexBuffer == bind.m_type - ? m_indexBuffers[bind.m_idx] - : m_vertexBuffers[bind.m_idx] - ; - - if (Access::Read != bind.m_access) + case Binding::IndexBuffer: + case Binding::VertexBuffer: { - buffer.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); - scratchBuffer.allocUav(srvHandle[stage], buffer); - } - else - { - buffer.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); - scratchBuffer.allocSrv(srvHandle[stage], buffer); + BufferD3D12& buffer = Binding::IndexBuffer == bind.m_type + ? m_indexBuffers[bind.m_idx] + : m_vertexBuffers[bind.m_idx] + ; + + if (Access::Read != bind.m_access) + { + buffer.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + scratchBuffer.allocUav(srvHandle[stage], buffer); + } + else + { + buffer.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); + scratchBuffer.allocSrv(srvHandle[stage], buffer); + } + + ++numSet; } + break; } - break; + } + else + { + samplerFlags[stage] = 0; + scratchBuffer.allocEmpty(srvHandle[stage]); } } - else + + if (0 != numSet) { - samplerFlags[stage] = 0; - scratchBuffer.allocEmpty(srvHandle[stage]); + Bind bind; + bind.m_srvHandle = srvHandle[0]; + bind.m_samplerStateIdx = getSamplerState(samplerFlags, maxComputeBindings, _render->m_colorPalette); + bindCached = bindLru.add(bindHash, bind, 0); + + uint16_t samplerStateIdx = bindCached->m_samplerStateIdx; + if (samplerStateIdx != currentSamplerStateIdx) + { + currentSamplerStateIdx = samplerStateIdx; + m_commandList->SetComputeRootDescriptorTable(Rdt::Sampler, m_samplerAllocator.get(samplerStateIdx) ); + } + m_commandList->SetComputeRootDescriptorTable(Rdt::SRV, bindCached->m_srvHandle); + m_commandList->SetComputeRootDescriptorTable(Rdt::UAV, bindCached->m_srvHandle); } } - - uint16_t samplerStateIdx = getSamplerState(samplerFlags, maxComputeBindings, _render->m_colorPalette); - if (samplerStateIdx != currentSamplerStateIdx) - { - currentSamplerStateIdx = samplerStateIdx; - m_commandList->SetComputeRootDescriptorTable(Rdt::Sampler, m_samplerAllocator.get(samplerStateIdx) ); - } - - m_commandList->SetComputeRootDescriptorTable(Rdt::SRV, srvHandle[0]); - m_commandList->SetComputeRootDescriptorTable(Rdt::UAV, srvHandle[0]); - - Bind bind; - bind.m_srvHandle = srvHandle[0]; - bind.m_samplerStateIdx = samplerStateIdx; - bindLru.add(bindHash, bind, 0); } else { @@ -6315,20 +6323,20 @@ namespace bgfx { namespace d3d12 if (0 != numSet) { - uint16_t samplerStateIdx = getSamplerState(samplerFlags, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, _render->m_colorPalette); + Bind bind; + bind.m_srvHandle = srvHandle[0]; + bind.m_samplerStateIdx = getSamplerState(samplerFlags, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, _render->m_colorPalette); + bindCached = bindLru.add(bindHash, bind, 0); + + uint16_t samplerStateIdx = bindCached->m_samplerStateIdx; if (samplerStateIdx != currentSamplerStateIdx) { currentSamplerStateIdx = samplerStateIdx; m_commandList->SetGraphicsRootDescriptorTable(Rdt::Sampler, m_samplerAllocator.get(samplerStateIdx) ); } - m_commandList->SetGraphicsRootDescriptorTable(Rdt::SRV, srvHandle[0]); - m_commandList->SetGraphicsRootDescriptorTable(Rdt::UAV, srvHandle[0]); - - Bind bind; - bind.m_srvHandle = srvHandle[0]; - bind.m_samplerStateIdx = samplerStateIdx; - bindLru.add(bindHash, bind, 0); + m_commandList->SetGraphicsRootDescriptorTable(Rdt::SRV, bindCached->m_srvHandle); + m_commandList->SetGraphicsRootDescriptorTable(Rdt::UAV, bindCached->m_srvHandle); } } else