mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-02-21 18:39:57 +00:00
d3d12: Copy descriptors when reused instead of recreating them.
Thanks Matías N. Goldberg for the tip !
This commit is contained in:
parent
7ae680d9d1
commit
263e5beb26
@ -179,6 +179,12 @@ D3D12GSRender::D3D12GSRender()
|
||||
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());
|
||||
|
||||
|
||||
D3D12_DESCRIPTOR_HEAP_DESC current_texture_descriptors_desc = { D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 16 };
|
||||
CHECK_HRESULT(m_device->CreateDescriptorHeap(¤t_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(¤t_sampler_descriptors_desc, IID_PPV_ARGS(m_current_sampler_descriptors.GetAddressOf())));
|
||||
|
||||
ComPtr<ID3DBlob> root_signature_blob = get_shared_root_signature_blob();
|
||||
|
||||
m_device->CreateRootSignature(0,
|
||||
@ -344,20 +350,19 @@ void D3D12GSRender::end()
|
||||
{
|
||||
upload_textures(get_current_resource_storage().command_list.Get(), texture_count);
|
||||
|
||||
// Bind texture and samplers
|
||||
for (u32 i = 0; i < texture_count; i++)
|
||||
{
|
||||
ID3D12Resource *tex_resource;
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC srv;
|
||||
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())
|
||||
.Offset((UINT)get_current_resource_storage().descriptors_heap_index + i, m_descriptor_stride_srv_cbv_uav)
|
||||
);
|
||||
m_device->CreateSampler(&m_current_samplers[i],
|
||||
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 + i, m_descriptor_stride_samplers));
|
||||
}
|
||||
m_device->CopyDescriptorsSimple(16,
|
||||
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),
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_current_texture_descriptors->GetCPUDescriptorHandleForHeapStart()),
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV
|
||||
);
|
||||
|
||||
m_device->CopyDescriptorsSimple(16,
|
||||
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),
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_current_sampler_descriptors->GetCPUDescriptorHandleForHeapStart()),
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER
|
||||
);
|
||||
|
||||
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(TEXTURES_SLOT,
|
||||
CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())
|
||||
|
@ -129,8 +129,8 @@ private:
|
||||
|
||||
// Currently used shader resources / samplers descriptor
|
||||
u32 m_current_transform_constants_buffer_descriptor_id;
|
||||
std::array<std::tuple<ID3D12Resource*, D3D12_SHADER_RESOURCE_VIEW_DESC>, 16> m_current_shader_resources = {};
|
||||
std::array<D3D12_SAMPLER_DESC, 16> m_current_samplers = {};
|
||||
ComPtr<ID3D12DescriptorHeap> m_current_texture_descriptors;
|
||||
ComPtr<ID3D12DescriptorHeap> m_current_sampler_descriptors;
|
||||
public:
|
||||
D3D12GSRender();
|
||||
virtual ~D3D12GSRender();
|
||||
|
@ -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);
|
||||
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 = {};
|
||||
sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
|
||||
sampler_desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
sampler_desc.AddressV = 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;
|
||||
}
|
||||
size_t w = textures[i].width(), h = textures[i].height();
|
||||
@ -354,7 +362,10 @@ void D3D12GSRender::upload_textures(ID3D12GraphicsCommandList *command_list, siz
|
||||
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)
|
||||
{
|
||||
@ -368,7 +379,10 @@ void D3D12GSRender::upload_textures(ID3D12GraphicsCommandList *command_list, siz
|
||||
};
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user