@@ -65,33 +65,28 @@ static u32 s_debug_scope_depth = 0;
6565#endif
6666
6767static constexpr const u32 s_mipmap_blit_vs[] = {
68- 0x43425844 , 0xe0f571cf , 0x51234ef3 , 0x3a6beab4 , 0x141cd2ef , 0x00000001 , 0x000003ac , 0x00000005 , 0x00000034 ,
69- 0x00000144 , 0x00000178 , 0x000001d0 , 0x00000310 , 0x46454452 , 0x00000108 , 0x00000001 , 0x00000068 , 0x00000001 ,
70- 0x0000003c , 0xfffe0500 , 0x00008100 , 0x000000e0 , 0x31314452 , 0x0000003c , 0x00000018 , 0x00000020 , 0x00000028 ,
71- 0x00000024 , 0x0000000c , 0x00000000 , 0x0000005c , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 ,
72- 0x00000001 , 0x00000001 , 0x424f4255 , 0x6b636f6c , 0xababab00 , 0x0000005c , 0x00000001 , 0x00000080 , 0x00000010 ,
73- 0x00000000 , 0x00000000 , 0x000000a8 , 0x00000000 , 0x00000010 , 0x00000002 , 0x000000bc , 0x00000000 , 0xffffffff ,
74- 0x00000000 , 0xffffffff , 0x00000000 , 0x72735f75 , 0x65725f63 , 0x66007463 , 0x74616f6c , 0xabab0034 , 0x00030001 ,
75- 0x00040001 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x000000b3 , 0x7263694d ,
76- 0x666f736f , 0x52282074 , 0x4c482029 , 0x53204c53 , 0x65646168 , 0x6f432072 , 0x6c69706d , 0x31207265 , 0x00312e30 ,
77- 0x4e475349 , 0x0000002c , 0x00000001 , 0x00000008 , 0x00000020 , 0x00000000 , 0x00000006 , 0x00000001 , 0x00000000 ,
78- 0x00000101 , 0x565f5653 , 0x65747265 , 0x00444978 , 0x4e47534f , 0x00000050 , 0x00000002 , 0x00000008 , 0x00000038 ,
79- 0x00000000 , 0x00000000 , 0x00000003 , 0x00000000 , 0x00000c03 , 0x00000041 , 0x00000000 , 0x00000001 , 0x00000003 ,
80- 0x00000001 , 0x0000000f , 0x43584554 , 0x44524f4f , 0x5f565300 , 0x69736f50 , 0x6e6f6974 , 0xababab00 , 0x58454853 ,
81- 0x00000138 , 0x00010050 , 0x0000004e , 0x0100086a , 0x04000059 , 0x00208e46 , 0x00000000 , 0x00000001 , 0x04000060 ,
68+ 0x43425844 , 0x1790f572 , 0x2810683a , 0xdff0fe9d , 0x8f210489 , 0x00000001 , 0x000002e0 , 0x00000005 , 0x00000034 ,
69+ 0x000000a0 , 0x000000d4 , 0x0000012c , 0x00000244 , 0x46454452 , 0x00000064 , 0x00000000 , 0x00000000 , 0x00000000 ,
70+ 0x0000003c , 0xfffe0500 , 0x00008100 , 0x0000003c , 0x31314452 , 0x0000003c , 0x00000018 , 0x00000020 , 0x00000028 ,
71+ 0x00000024 , 0x0000000c , 0x00000000 , 0x7263694d , 0x666f736f , 0x52282074 , 0x4c482029 , 0x53204c53 , 0x65646168 ,
72+ 0x6f432072 , 0x6c69706d , 0x31207265 , 0x00312e30 , 0x4e475349 , 0x0000002c , 0x00000001 , 0x00000008 , 0x00000020 ,
73+ 0x00000000 , 0x00000006 , 0x00000001 , 0x00000000 , 0x00000101 , 0x565f5653 , 0x65747265 , 0x00444978 , 0x4e47534f ,
74+ 0x00000050 , 0x00000002 , 0x00000008 , 0x00000038 , 0x00000000 , 0x00000000 , 0x00000003 , 0x00000000 , 0x00000c03 ,
75+ 0x00000041 , 0x00000000 , 0x00000001 , 0x00000003 , 0x00000001 , 0x0000000f , 0x43584554 , 0x44524f4f , 0x5f565300 ,
76+ 0x69736f50 , 0x6e6f6974 , 0xababab00 , 0x58454853 , 0x00000110 , 0x00010050 , 0x00000044 , 0x0100086a , 0x04000060 ,
8277 0x00101012 , 0x00000000 , 0x00000006 , 0x03000065 , 0x00102032 , 0x00000000 , 0x04000067 , 0x001020f2 , 0x00000001 ,
8378 0x00000001 , 0x02000068 , 0x00000001 , 0x0b00008c , 0x00100012 , 0x00000000 , 0x00004001 , 0x00000001 , 0x00004001 ,
8479 0x00000001 , 0x0010100a , 0x00000000 , 0x00004001 , 0x00000000 , 0x07000001 , 0x00100042 , 0x00000000 , 0x0010100a ,
85- 0x00000000 , 0x00004001 , 0x00000002 , 0x05000056 , 0x00100032 , 0x00000000 , 0x00100086 , 0x00000000 , 0x0b000032 ,
86- 0x00102032 , 0x00000000 , 0x00100046 , 0x00000000 , 0x00208ae6 , 0x00000000 , 0x00000000 , 0x00208046 , 0x00000000 ,
87- 0x00000000 , 0x0f000032 , 0x00102032 , 0x00000001 , 0x00100046 , 0x00000000 , 0x00004002 , 0x40000000 , 0xc0000000 ,
88- 0x00000000 , 0x00000000 , 0x00004002 , 0xbf800000 , 0x3f800000 , 0x00000000 , 0x00000000 , 0x08000036 , 0x001020c2 ,
89- 0x00000001 , 0x00004002 , 0x00000000 , 0x00000000 , 0x00000000 , 0x3f800000 , 0x0100003e , 0x54415453 , 0x00000094 ,
90- 0x00000007 , 0x00000001 , 0x00000000 , 0x00000003 , 0x00000002 , 0x00000000 , 0x00000001 , 0x00000001 , 0x00000000 ,
80+ 0x00000000 , 0x00004001 , 0x00000002 , 0x05000056 , 0x00100032 , 0x00000000 , 0x00100086 , 0x00000000 , 0x05000036 ,
81+ 0x00102032 , 0x00000000 , 0x00100046 , 0x00000000 , 0x0f000032 , 0x00102032 , 0x00000001 , 0x00100046 , 0x00000000 ,
82+ 0x00004002 , 0x40000000 , 0xc0000000 , 0x00000000 , 0x00000000 , 0x00004002 , 0xbf800000 , 0x3f800000 , 0x00000000 ,
83+ 0x00000000 , 0x08000036 , 0x001020c2 , 0x00000001 , 0x00004002 , 0x00000000 , 0x00000000 , 0x00000000 , 0x3f800000 ,
84+ 0x0100003e , 0x54415453 , 0x00000094 , 0x00000007 , 0x00000001 , 0x00000000 , 0x00000003 , 0x00000001 , 0x00000000 ,
85+ 0x00000001 , 0x00000001 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 ,
86+ 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000002 , 0x00000000 , 0x00000001 , 0x00000000 , 0x00000000 ,
9187 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 ,
92- 0x00000000 , 0x00000001 , 0x00000000 , 0x00000001 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 ,
93- 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 ,
94- 0x00000000 };
88+ 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 ,
89+ };
9590
9691static constexpr const u32 s_mipmap_blit_ps[] = {
9792 0x43425844 , 0x25500f77 , 0x71f24271 , 0x5f83f8b8 , 0x3f405943 , 0x00000001 , 0x0000026c , 0x00000005 , 0x00000034 ,
@@ -1786,11 +1781,23 @@ bool D3D12Device::CreateRootSignatures(Error* error)
17861781 D3D12::SetObjectName (rs.Get (), " Compute Multi Texture Pipeline Layout" );
17871782 }
17881783
1784+ {
1785+ auto & rs = m_mipmap_render_root_signature;
1786+ rsb.AddDescriptorTable (D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 0 , 1 , D3D12_SHADER_VISIBILITY_PIXEL);
1787+ rsb.AddStaticSampler (0 , D3D12Sampler::GetD3DSamplerDesc (GPUSampler::GetLinearConfig ()), D3D12_SHADER_VISIBILITY_PIXEL);
1788+ if (!(rs = rsb.Create (error, true )))
1789+ return false ;
1790+ D3D12::SetObjectName (rs.Get (), " Render Mipmap Pipeline Layout" );
1791+ }
1792+
17891793 return true ;
17901794}
17911795
17921796void D3D12Device::DestroyRootSignatures ()
17931797{
1798+ for (ComPtr<ID3D12PipelineState>& it : m_mipmap_render_pipelines)
1799+ it.Reset ();
1800+ m_mipmap_render_root_signature.Reset ();
17941801 m_root_signatures.enumerate([](auto & it) { it.Reset (); });
17951802}
17961803
@@ -2213,17 +2220,15 @@ void D3D12Device::UnbindTextureBuffer(D3D12TextureBuffer* buf)
22132220void D3D12Device::RenderTextureMipmap (D3D12Texture* texture, u32 dst_level, u32 dst_width, u32 dst_height,
22142221 u32 src_level, u32 src_width, u32 src_height)
22152222{
2216- ID3D12RootSignature* rootsig =
2217- m_root_signatures[0 ][static_cast <size_t >(GPUPipeline::Layout::SingleTextureAndPushConstants)].Get ();
22182223 ComPtr<ID3D12PipelineState>& pipeline = m_mipmap_render_pipelines[static_cast <size_t >(texture->GetFormat ())];
22192224 if (!pipeline)
22202225 {
22212226 D3D12::GraphicsPipelineBuilder gpb;
2222- gpb.SetRootSignature (rootsig );
2227+ gpb.SetRootSignature (m_mipmap_render_root_signature. Get () );
22232228 gpb.SetPrimitiveTopologyType (D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
22242229 gpb.SetRenderTarget (0 , texture->GetDXGIFormat ());
2225- gpb.SetVertexShader (s_mipmap_blit_vs, std::size (s_mipmap_blit_vs));
2226- gpb.SetPixelShader (s_mipmap_blit_ps, std::size (s_mipmap_blit_ps));
2230+ gpb.SetVertexShader (s_mipmap_blit_vs, sizeof (s_mipmap_blit_vs));
2231+ gpb.SetPixelShader (s_mipmap_blit_ps, sizeof (s_mipmap_blit_ps));
22272232 gpb.SetRasterizationState (D3D12_FILL_MODE_SOLID, D3D12_CULL_MODE_NONE, false );
22282233 gpb.SetDepthState (false , false , D3D12_COMPARISON_FUNC_ALWAYS);
22292234 gpb.SetBlendState (0 , false , D3D12_BLEND_ZERO, D3D12_BLEND_ONE, D3D12_BLEND_OP_ADD, D3D12_BLEND_ZERO,
@@ -2266,17 +2271,26 @@ void D3D12Device::RenderTextureMipmap(D3D12Texture* texture, u32 dst_level, u32
22662271 }
22672272 }
22682273
2269- EndRenderPass ();
2274+ if (InRenderPass ())
2275+ EndRenderPass ();
22702276
22712277 // we need a temporary SRV and RTV for each mip level
22722278 // Safe to use the init buffer after exec, because everything will be done with the texture.
22732279 D3D12DescriptorHandle rtv_handle;
22742280 while (!GetRTVHeapManager ().Allocate (&rtv_handle))
2281+ {
22752282 SubmitCommandList (false , " Allocate RTV for RenderTextureMipmap()" );
2283+ if (m_device_was_lost)
2284+ return ;
2285+ }
22762286
22772287 D3D12DescriptorHandle srv_handle;
2278- while (!GetDescriptorHeapManager ().Allocate (&srv_handle))
2279- SubmitCommandList (false , " Allocate SRV for RenderTextureMipmap()" );
2288+ while (!m_command_lists[m_current_command_list].descriptor_allocator .Allocate (1 , &srv_handle))
2289+ {
2290+ SubmitCommandList (false , " Allocate SRV/sampler for RenderTextureMipmap()" );
2291+ if (m_device_was_lost)
2292+ return ;
2293+ }
22802294
22812295 // Setup views. This will be a partial view for the SRV.
22822296 const D3D12_RENDER_TARGET_VIEW_DESC rtv_desc = {.Format = texture->GetDXGIFormat (),
@@ -2317,8 +2331,8 @@ void D3D12Device::RenderTextureMipmap(D3D12Texture* texture, u32 dst_level, u32
23172331 cmdlist->RSSetScissorRects (1 , &scissor);
23182332
23192333 cmdlist->SetPipelineState (pipeline.Get ());
2334+ cmdlist->SetGraphicsRootSignature (m_mipmap_render_root_signature.Get ());
23202335 cmdlist->SetGraphicsRootDescriptorTable (0 , srv_handle);
2321- cmdlist->SetGraphicsRootDescriptorTable (1 , static_cast <D3D12Sampler*>(m_linear_sampler)->GetDescriptor ());
23222336 cmdlist->DrawInstanced (3 , 1 , 0 , 0 );
23232337
23242338 cmdlist->EndRenderPass ();
@@ -2335,7 +2349,6 @@ void D3D12Device::RenderTextureMipmap(D3D12Texture* texture, u32 dst_level, u32
23352349 }
23362350
23372351 // Must destroy after current cmdlist.
2338- DeferDescriptorDestruction (m_descriptor_heap_manager, &srv_handle);
23392352 DeferDescriptorDestruction (m_rtv_heap_manager, &rtv_handle);
23402353
23412354 // Restore for next normal draw.
0 commit comments