From f1f31e22f9d5575bc2f002433829c93110a2f2a4 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 27 Sep 2015 18:41:23 +0200 Subject: [PATCH] d3d12: Use d3dx12 structs for Root signature declarations --- rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp | 59 +++++++++------------------ rpcs3/Emu/RSX/D3D12/D3D12Utils.cpp | 28 +++++-------- 2 files changed, 29 insertions(+), 58 deletions(-) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index c8893c8c8b..78ed326847 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -224,49 +224,28 @@ D3D12GSRender::D3D12GSRender() // Common root signatures for (unsigned textureCount = 0; textureCount < 17; textureCount++) { - D3D12_DESCRIPTOR_RANGE descriptorRange[4] = {}; - // Scale Offset data - descriptorRange[0].BaseShaderRegister = 0; - descriptorRange[0].NumDescriptors = 1; - descriptorRange[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV; - // Constants - descriptorRange[1].BaseShaderRegister = 1; - descriptorRange[1].NumDescriptors = 2; - descriptorRange[1].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV; - // Textures - descriptorRange[2].BaseShaderRegister = 0; - descriptorRange[2].NumDescriptors = textureCount; - descriptorRange[2].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; - // Samplers - descriptorRange[3].BaseShaderRegister = 0; - descriptorRange[3].NumDescriptors = textureCount; - descriptorRange[3].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER; - D3D12_ROOT_PARAMETER RP[4] = {}; - RP[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; - RP[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - RP[0].DescriptorTable.pDescriptorRanges = &descriptorRange[0]; - RP[0].DescriptorTable.NumDescriptorRanges = 1; - RP[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; - RP[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - RP[1].DescriptorTable.pDescriptorRanges = &descriptorRange[1]; - RP[1].DescriptorTable.NumDescriptorRanges = 1; - RP[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; - RP[2].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - RP[2].DescriptorTable.pDescriptorRanges = &descriptorRange[2]; - RP[2].DescriptorTable.NumDescriptorRanges = 1; - RP[3].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; - RP[3].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - RP[3].DescriptorTable.pDescriptorRanges = &descriptorRange[3]; - RP[3].DescriptorTable.NumDescriptorRanges = 1; - - D3D12_ROOT_SIGNATURE_DESC rootSignatureDesc = {}; - rootSignatureDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT; - rootSignatureDesc.NumParameters = (textureCount > 0) ? 4 : 2; - rootSignatureDesc.pParameters = RP; + CD3DX12_DESCRIPTOR_RANGE descriptorRange[] = + { + // Scale Offset data + CD3DX12_DESCRIPTOR_RANGE(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0), + // Constants + CD3DX12_DESCRIPTOR_RANGE(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 2, 1), + // Textures + CD3DX12_DESCRIPTOR_RANGE(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, textureCount, 0), + // Samplers + CD3DX12_DESCRIPTOR_RANGE(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, textureCount, 0), + }; + CD3DX12_ROOT_PARAMETER RP[4]; + RP[0].InitAsDescriptorTable(1, &descriptorRange[0]); + RP[1].InitAsDescriptorTable(1, &descriptorRange[1]); + RP[2].InitAsDescriptorTable(1, &descriptorRange[2]); + RP[3].InitAsDescriptorTable(1, &descriptorRange[3]); Microsoft::WRL::ComPtr rootSignatureBlob; Microsoft::WRL::ComPtr errorBlob; - ThrowIfFailed(wrapD3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &rootSignatureBlob, &errorBlob)); + ThrowIfFailed(wrapD3D12SerializeRootSignature( + &CD3DX12_ROOT_SIGNATURE_DESC((textureCount > 0) ? 4 : 2, RP, 0, 0, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), + D3D_ROOT_SIGNATURE_VERSION_1, &rootSignatureBlob, &errorBlob)); m_device->CreateRootSignature(0, rootSignatureBlob->GetBufferPointer(), diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Utils.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Utils.cpp index de92a9c652..d2b74f1d12 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Utils.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Utils.cpp @@ -36,28 +36,20 @@ std::pair compileF32toU8CS() const char *tmp = (const char*)errorBlob->GetBufferPointer(); LOG_ERROR(RSX, tmp); } - D3D12_DESCRIPTOR_RANGE descriptorRange[2] = {}; - // Textures - descriptorRange[0].BaseShaderRegister = 0; - descriptorRange[0].NumDescriptors = 1; - descriptorRange[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; - descriptorRange[1].BaseShaderRegister = 0; - descriptorRange[1].NumDescriptors = 1; - descriptorRange[1].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV; - descriptorRange[1].OffsetInDescriptorsFromTableStart = 1; - D3D12_ROOT_PARAMETER RP[2] = {}; - RP[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; - RP[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - RP[0].DescriptorTable.pDescriptorRanges = &descriptorRange[0]; - RP[0].DescriptorTable.NumDescriptorRanges = 2; + 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), + }; - D3D12_ROOT_SIGNATURE_DESC rootSignatureDesc = {}; - rootSignatureDesc.NumParameters = 1; - rootSignatureDesc.pParameters = RP; + CD3DX12_ROOT_PARAMETER RP; + RP.InitAsDescriptorTable(2, &descriptorRange[0]); ID3DBlob *rootSignatureBlob; - hr = wrapD3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &rootSignatureBlob, &errorBlob); + hr = wrapD3D12SerializeRootSignature(&CD3DX12_ROOT_SIGNATURE_DESC(1, &RP), D3D_ROOT_SIGNATURE_VERSION_1, &rootSignatureBlob, &errorBlob); if (hr != S_OK) { const char *tmp = (const char*)errorBlob->GetBufferPointer();