1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

d3d12: Remove depth conversion shader

It's actually not needed, raw depth data should be sampled as RGBA8.
This commit is contained in:
Vincent Lejeune 2016-02-22 20:10:44 +01:00
parent 263e5beb26
commit a78ba8a271
4 changed files with 5 additions and 122 deletions

View File

@ -197,7 +197,6 @@ D3D12GSRender::D3D12GSRender()
m_per_frame_storage[1].init(m_device.Get());
m_per_frame_storage[1].reset();
init_convert_shader();
m_output_scaling_pass.init(m_device.Get(), m_command_queue.Get());
CHECK_HRESULT(
@ -236,8 +235,6 @@ D3D12GSRender::~D3D12GSRender()
m_texture_cache.unprotect_all();
m_dummy_texture->Release();
m_convert_pso->Release();
m_convert_root_signature->Release();
m_per_frame_storage[0].release();
m_per_frame_storage[1].release();
m_output_scaling_pass.release();

View File

@ -101,13 +101,6 @@ private:
*/
shader m_output_scaling_pass;
/**
* Data used when depth buffer is converted to uchar textures.
*/
ID3D12PipelineState *m_convert_pso;
ID3D12RootSignature *m_convert_root_signature;
void init_convert_shader();
resource_storage m_per_frame_storage[2];
resource_storage &get_current_resource_storage();
resource_storage &get_non_current_resource_storage();

View File

@ -298,9 +298,7 @@ void D3D12GSRender::copy_render_target_to_dma_location()
int clip_w = rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16;
int clip_h = rsx::method_registers[NV4097_SET_SURFACE_CLIP_VERTICAL] >> 16;
ComPtr<ID3D12Resource> depth_format_conversion_buffer;
ComPtr<ID3D12DescriptorHeap> descriptor_heap;
size_t depth_row_pitch = align(clip_w, 256);
size_t depth_row_pitch = align(clip_w * 4, 256);
size_t depth_buffer_offset_in_heap = 0;
u32 context_dma_color[] =
@ -334,55 +332,10 @@ void D3D12GSRender::copy_render_target_to_dma_location()
if (m_context_dma_z && rpcs3::state.config.rsx.opengl.write_depth_buffer)
{
size_t uav_size = clip_w * clip_h * 2;
CHECK_HRESULT(
m_device->CreateCommittedResource(
&D3D12_HEAP_PROPERTIES{D3D12_HEAP_TYPE_DEFAULT},
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8_UNORM, clip_w, clip_h, 1, 1, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS),
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
nullptr,
IID_PPV_ARGS(depth_format_conversion_buffer.GetAddressOf())
)
);
D3D12_DESCRIPTOR_HEAP_DESC descriptor_heap_desc = { D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV , 2, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE };
CHECK_HRESULT(
m_device->CreateDescriptorHeap(&descriptor_heap_desc, IID_PPV_ARGS(descriptor_heap.GetAddressOf()))
);
D3D12_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {};
shader_resource_view_desc.Format = get_depth_samplable_surface_format(m_surface.depth_format);
shader_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
shader_resource_view_desc.Texture2D.MipLevels = 1;
shader_resource_view_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
m_device->CreateShaderResourceView(std::get<1>(m_rtts.m_bound_depth_stencil), &shader_resource_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(descriptor_heap->GetCPUDescriptorHandleForHeapStart()));
D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc = {};
uav_desc.Format = DXGI_FORMAT_R8_UNORM;
uav_desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
m_device->CreateUnorderedAccessView(depth_format_conversion_buffer.Get(), nullptr, &uav_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(descriptor_heap->GetCPUDescriptorHandleForHeapStart()).Offset(1, m_descriptor_stride_srv_cbv_uav));
// Convert
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(std::get<1>(m_rtts.m_bound_depth_stencil), D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ));
get_current_resource_storage().command_list->SetPipelineState(m_convert_pso);
get_current_resource_storage().command_list->SetComputeRootSignature(m_convert_root_signature);
get_current_resource_storage().command_list->SetDescriptorHeaps(1, descriptor_heap.GetAddressOf());
get_current_resource_storage().command_list->SetComputeRootDescriptorTable(0, descriptor_heap->GetGPUDescriptorHandleForHeapStart());
get_current_resource_storage().command_list->Dispatch(clip_w / 8, clip_h / 8, 1);
D3D12_RESOURCE_BARRIER barriers[] =
{
CD3DX12_RESOURCE_BARRIER::Transition(std::get<1>(m_rtts.m_bound_depth_stencil), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_DEPTH_WRITE),
CD3DX12_RESOURCE_BARRIER::UAV(depth_format_conversion_buffer.Get()),
};
get_current_resource_storage().command_list->ResourceBarrier(2, barriers);
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(depth_format_conversion_buffer.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE));
get_current_resource_storage().command_list->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(m_readback_resources.get_heap(), { depth_buffer_offset_in_heap,{ DXGI_FORMAT_R8_UNORM, (UINT)clip_w, (UINT)clip_h, 1, (UINT)depth_row_pitch } }), 0, 0, 0,
&CD3DX12_TEXTURE_COPY_LOCATION(depth_format_conversion_buffer.Get(), 0), nullptr);
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(std::get<1>(m_rtts.m_bound_depth_stencil), D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_COPY_SOURCE));
get_current_resource_storage().command_list->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(m_readback_resources.get_heap(), { depth_buffer_offset_in_heap,{ DXGI_FORMAT_R32_TYPELESS, (UINT)clip_w, (UINT)clip_h, 1, (UINT)depth_row_pitch } }), 0, 0, 0,
&CD3DX12_TEXTURE_COPY_LOCATION(std::get<1>(m_rtts.m_bound_depth_stencil), 0), nullptr);
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(std::get<1>(m_rtts.m_bound_depth_stencil), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_DEPTH_WRITE));
invalidate_address(address_z);
need_transfer = true;

View File

@ -8,45 +8,6 @@
extern PFN_D3D12_SERIALIZE_ROOT_SIGNATURE wrapD3D12SerializeRootSignature;
extern pD3DCompile wrapD3DCompile;
/**
* returns bytecode and root signature of a Compute Shader converting texture from
* one format to another
*/
static
std::pair<ID3DBlob *, ID3DBlob *> compileF32toU8CS()
{
const char *shaderCode = STRINGIFY(
Texture2D<float> InputTexture : register(t0); \n
RWTexture2D<float> OutputTexture : register(u0);\n
[numthreads(8, 8, 1)]\n
void main(uint3 Id : SV_DispatchThreadID)\n
{ \n
OutputTexture[Id.xy] = InputTexture.Load(uint3(Id.xy, 0));\n
}
);
ID3DBlob *bytecode;
Microsoft::WRL::ComPtr<ID3DBlob> errorBlob;
CHECK_HRESULT(wrapD3DCompile(shaderCode, strlen(shaderCode), "test", nullptr, nullptr, "main", "cs_5_0", 0, 0, &bytecode, errorBlob.GetAddressOf()));
CD3DX12_DESCRIPTOR_RANGE descriptorRange[] =
{
// Textures
CD3DX12_DESCRIPTOR_RANGE(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0),
// UAV (same descriptor heap)
CD3DX12_DESCRIPTOR_RANGE(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 1),
};
CD3DX12_ROOT_PARAMETER RP;
RP.InitAsDescriptorTable(2, &descriptorRange[0]);
ID3DBlob *rootSignatureBlob;
CHECK_HRESULT(wrapD3D12SerializeRootSignature(&CD3DX12_ROOT_SIGNATURE_DESC(1, &RP), D3D_ROOT_SIGNATURE_VERSION_1, &rootSignatureBlob, &errorBlob));
return std::make_pair(bytecode, rootSignatureBlob);
}
void D3D12GSRender::shader::init(ID3D12Device *device, ID3D12CommandQueue *gfx_command_queue)
{
const char *fsCode = STRINGIFY(
@ -213,25 +174,4 @@ void D3D12GSRender::shader::init(ID3D12Device *device, ID3D12CommandQueue *gfx_c
WaitForSingleObjectEx(handle, INFINITE, FALSE);
CloseHandle(handle);
}
void D3D12GSRender::init_convert_shader()
{
const auto &p = compileF32toU8CS();
CHECK_HRESULT(
m_device->CreateRootSignature(0, p.second->GetBufferPointer(), p.second->GetBufferSize(), IID_PPV_ARGS(&m_convert_root_signature))
);
D3D12_COMPUTE_PIPELINE_STATE_DESC computePipelineStateDesc = {};
computePipelineStateDesc.CS.BytecodeLength = p.first->GetBufferSize();
computePipelineStateDesc.CS.pShaderBytecode = p.first->GetBufferPointer();
computePipelineStateDesc.pRootSignature = m_convert_root_signature;
CHECK_HRESULT(
m_device->CreateComputePipelineState(&computePipelineStateDesc, IID_PPV_ARGS(&m_convert_pso))
);
p.first->Release();
p.second->Release();
}
#endif