d3d12: Copy descriptors when reused instead of recreating them.

Thanks Matías N. Goldberg for the tip !
This commit is contained in:
Vincent Lejeune 2016-02-22 19:55:24 +01:00
parent 7ae680d9d1
commit 263e5beb26
3 changed files with 39 additions and 20 deletions

View File

@ -179,6 +179,12 @@ D3D12GSRender::D3D12GSRender()
m_device->CreateDescriptorHeap(&render_target_descriptor_heap_desc, IID_PPV_ARGS(&m_backbuffer_descriptor_heap[1])); m_device->CreateDescriptorHeap(&render_target_descriptor_heap_desc, IID_PPV_ARGS(&m_backbuffer_descriptor_heap[1]));
m_device->CreateRenderTargetView(m_backbuffer[1].Get(), &renter_target_view_desc, m_backbuffer_descriptor_heap[1]->GetCPUDescriptorHandleForHeapStart()); m_device->CreateRenderTargetView(m_backbuffer[1].Get(), &renter_target_view_desc, m_backbuffer_descriptor_heap[1]->GetCPUDescriptorHandleForHeapStart());
D3D12_DESCRIPTOR_HEAP_DESC current_texture_descriptors_desc = { D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 16 };
CHECK_HRESULT(m_device->CreateDescriptorHeap(&current_texture_descriptors_desc, IID_PPV_ARGS(m_current_texture_descriptors.GetAddressOf())));
D3D12_DESCRIPTOR_HEAP_DESC current_sampler_descriptors_desc = { D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, 16 };
CHECK_HRESULT(m_device->CreateDescriptorHeap(&current_sampler_descriptors_desc, IID_PPV_ARGS(m_current_sampler_descriptors.GetAddressOf())));
ComPtr<ID3DBlob> root_signature_blob = get_shared_root_signature_blob(); ComPtr<ID3DBlob> root_signature_blob = get_shared_root_signature_blob();
m_device->CreateRootSignature(0, m_device->CreateRootSignature(0,
@ -344,20 +350,19 @@ void D3D12GSRender::end()
{ {
upload_textures(get_current_resource_storage().command_list.Get(), texture_count); upload_textures(get_current_resource_storage().command_list.Get(), texture_count);
// Bind texture and samplers m_device->CopyDescriptorsSimple(16,
for (u32 i = 0; i < texture_count; i++) CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
{ .Offset((UINT)get_current_resource_storage().descriptors_heap_index, m_descriptor_stride_srv_cbv_uav),
ID3D12Resource *tex_resource; CD3DX12_CPU_DESCRIPTOR_HANDLE(m_current_texture_descriptors->GetCPUDescriptorHandleForHeapStart()),
D3D12_SHADER_RESOURCE_VIEW_DESC srv; D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV
std::tie(tex_resource, srv) = m_current_shader_resources[i]; );
m_device->CreateShaderResourceView(tex_resource, &srv,
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart()) m_device->CopyDescriptorsSimple(16,
.Offset((UINT)get_current_resource_storage().descriptors_heap_index + i, m_descriptor_stride_srv_cbv_uav) CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetCPUDescriptorHandleForHeapStart())
); .Offset((UINT)get_current_resource_storage().current_sampler_index, m_descriptor_stride_samplers),
m_device->CreateSampler(&m_current_samplers[i], CD3DX12_CPU_DESCRIPTOR_HANDLE(m_current_sampler_descriptors->GetCPUDescriptorHandleForHeapStart()),
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetCPUDescriptorHandleForHeapStart()) D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER
.Offset((UINT)get_current_resource_storage().current_sampler_index + i, m_descriptor_stride_samplers)); );
}
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(TEXTURES_SLOT, get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(TEXTURES_SLOT,
CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart()) CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())

View File

@ -129,8 +129,8 @@ private:
// Currently used shader resources / samplers descriptor // Currently used shader resources / samplers descriptor
u32 m_current_transform_constants_buffer_descriptor_id; u32 m_current_transform_constants_buffer_descriptor_id;
std::array<std::tuple<ID3D12Resource*, D3D12_SHADER_RESOURCE_VIEW_DESC>, 16> m_current_shader_resources = {}; ComPtr<ID3D12DescriptorHeap> m_current_texture_descriptors;
std::array<D3D12_SAMPLER_DESC, 16> m_current_samplers = {}; ComPtr<ID3D12DescriptorHeap> m_current_sampler_descriptors;
public: public:
D3D12GSRender(); D3D12GSRender();
virtual ~D3D12GSRender(); virtual ~D3D12GSRender();

View File

@ -194,14 +194,22 @@ void D3D12GSRender::upload_textures(ID3D12GraphicsCommandList *command_list, siz
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0, D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0,
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0, D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0,
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0); D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0);
m_current_shader_resources[i] = std::make_tuple(m_dummy_texture, shader_resource_view_desc);
m_device->CreateShaderResourceView(m_dummy_texture, &shader_resource_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_current_texture_descriptors->GetCPUDescriptorHandleForHeapStart())
.Offset((UINT)i, m_descriptor_stride_srv_cbv_uav)
);
D3D12_SAMPLER_DESC sampler_desc = {}; D3D12_SAMPLER_DESC sampler_desc = {};
sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT; sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
sampler_desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP; sampler_desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP; sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
m_current_samplers[i] = sampler_desc;
m_device->CreateSampler(&sampler_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_current_sampler_descriptors->GetCPUDescriptorHandleForHeapStart())
.Offset((UINT)i, m_descriptor_stride_samplers));
continue; continue;
} }
size_t w = textures[i].width(), h = textures[i].height(); size_t w = textures[i].width(), h = textures[i].height();
@ -354,7 +362,10 @@ void D3D12GSRender::upload_textures(ID3D12GraphicsCommandList *command_list, siz
break; break;
} }
m_current_shader_resources[i] = std::make_tuple(vram_texture, shared_resource_view_desc); m_device->CreateShaderResourceView(vram_texture, &shared_resource_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_current_texture_descriptors->GetCPUDescriptorHandleForHeapStart())
.Offset((UINT)i, m_descriptor_stride_srv_cbv_uav)
);
if (get_current_resource_storage().current_sampler_index + 16 > 2048) if (get_current_resource_storage().current_sampler_index + 16 > 2048)
{ {
@ -368,7 +379,10 @@ void D3D12GSRender::upload_textures(ID3D12GraphicsCommandList *command_list, siz
}; };
command_list->SetDescriptorHeaps(2, descriptors); command_list->SetDescriptorHeaps(2, descriptors);
} }
m_current_samplers[i] = get_sampler_desc(textures[i]);
m_device->CreateSampler(&get_sampler_desc(textures[i]),
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_current_sampler_descriptors->GetCPUDescriptorHandleForHeapStart())
.Offset((UINT)i, m_descriptor_stride_samplers));
} }
} }
#endif #endif