Fix crash when using more than 2 constant buffers with D3D12

This commit is contained in:
Wojciech Figat
2022-07-01 13:19:38 +02:00
parent e2319ceca3
commit 427c3a9099
3 changed files with 25 additions and 23 deletions

View File

@@ -346,9 +346,9 @@ void GPUContextDX12::flushSRVs()
// Flush SRV descriptors table
if (_isCompute)
_commandList->SetComputeRootDescriptorTable(2, allocation.GPU);
_commandList->SetComputeRootDescriptorTable(DX12_ROOT_SIGNATURE_SR, allocation.GPU);
else
_commandList->SetGraphicsRootDescriptorTable(2, allocation.GPU);
_commandList->SetGraphicsRootDescriptorTable(DX12_ROOT_SIGNATURE_SR, allocation.GPU);
}
void GPUContextDX12::flushRTVs()
@@ -448,9 +448,9 @@ void GPUContextDX12::flushUAVs()
// Flush UAV descriptors table
if (_isCompute)
_commandList->SetComputeRootDescriptorTable(3, allocation.GPU);
_commandList->SetComputeRootDescriptorTable(DX12_ROOT_SIGNATURE_UA, allocation.GPU);
else
_commandList->SetGraphicsRootDescriptorTable(3, allocation.GPU);
_commandList->SetGraphicsRootDescriptorTable(DX12_ROOT_SIGNATURE_UA, allocation.GPU);
}
void GPUContextDX12::flushCBs()
@@ -464,7 +464,7 @@ void GPUContextDX12::flushCBs()
if (cb)
{
ASSERT(cb->GPUAddress != 0);
_commandList->SetGraphicsRootConstantBufferView(i, cb->GPUAddress);
_commandList->SetGraphicsRootConstantBufferView(DX12_ROOT_SIGNATURE_CB + i, cb->GPUAddress);
}
}
}
@@ -477,7 +477,7 @@ void GPUContextDX12::flushCBs()
if (cb)
{
ASSERT(cb->GPUAddress != 0);
_commandList->SetComputeRootConstantBufferView(i, cb->GPUAddress);
_commandList->SetComputeRootConstantBufferView(DX12_ROOT_SIGNATURE_CB + i, cb->GPUAddress);
}
}
}
@@ -513,9 +513,9 @@ void GPUContextDX12::flushSamplers()
auto allocation = _device->RingHeap_Sampler.AllocateTable(samplersCount);
_device->GetDevice()->CopyDescriptors(1, &allocation.CPU, &samplersCount, samplersCount, srcDescriptorRangeStarts, nullptr, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
if (_isCompute)
_commandList->SetComputeRootDescriptorTable(4, allocation.GPU);
_commandList->SetComputeRootDescriptorTable(DX12_ROOT_SIGNATURE_SAMPLER, allocation.GPU);
else
_commandList->SetGraphicsRootDescriptorTable(4, allocation.GPU);
_commandList->SetGraphicsRootDescriptorTable(DX12_ROOT_SIGNATURE_SAMPLER, allocation.GPU);
}
void GPUContextDX12::flushRBs()

View File

@@ -463,8 +463,7 @@ bool GPUDeviceDX12::Init()
// TODO: maybe create set of different root signatures? for UAVs, for compute, for simple drawing, for post fx?
{
// Descriptor tables
D3D12_DESCRIPTOR_RANGE r[3];
// TODO: separate ranges for pixel/vertex visibility and one shared for all?
D3D12_DESCRIPTOR_RANGE r[3]; // SRV+UAV+Sampler
{
D3D12_DESCRIPTOR_RANGE& range = r[0];
range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
@@ -491,37 +490,35 @@ bool GPUDeviceDX12::Init()
}
// Root parameters
D3D12_ROOT_PARAMETER rootParameters[5];
D3D12_ROOT_PARAMETER rootParameters[GPU_MAX_CB_BINDED + 3];
for (int32 i = 0; i < GPU_MAX_CB_BINDED; i++)
{
D3D12_ROOT_PARAMETER& rootParam = rootParameters[0];
// CB
D3D12_ROOT_PARAMETER& rootParam = rootParameters[DX12_ROOT_SIGNATURE_CB + i];
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
rootParam.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
rootParam.Descriptor.ShaderRegister = 0;
rootParam.Descriptor.ShaderRegister = i;
rootParam.Descriptor.RegisterSpace = 0;
}
{
D3D12_ROOT_PARAMETER& rootParam = rootParameters[1];
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
rootParam.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
rootParam.Descriptor.ShaderRegister = 1;
rootParam.Descriptor.RegisterSpace = 0;
}
{
D3D12_ROOT_PARAMETER& rootParam = rootParameters[2];
// SRVs
D3D12_ROOT_PARAMETER& rootParam = rootParameters[DX12_ROOT_SIGNATURE_SR];
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParam.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
rootParam.DescriptorTable.NumDescriptorRanges = 1;
rootParam.DescriptorTable.pDescriptorRanges = &r[0];
}
{
D3D12_ROOT_PARAMETER& rootParam = rootParameters[3];
// UAVs
D3D12_ROOT_PARAMETER& rootParam = rootParameters[DX12_ROOT_SIGNATURE_UA];
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParam.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
rootParam.DescriptorTable.NumDescriptorRanges = 1;
rootParam.DescriptorTable.pDescriptorRanges = &r[1];
}
{
D3D12_ROOT_PARAMETER& rootParam = rootParameters[4];
// Samplers
D3D12_ROOT_PARAMETER& rootParam = rootParameters[DX12_ROOT_SIGNATURE_SAMPLER];
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParam.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
rootParam.DescriptorTable.NumDescriptorRanges = 1;

View File

@@ -17,6 +17,11 @@
#define DX12_BACK_BUFFER_COUNT 2
#endif
#define DX12_ROOT_SIGNATURE_CB 0
#define DX12_ROOT_SIGNATURE_SR (GPU_MAX_CB_BINDED+0)
#define DX12_ROOT_SIGNATURE_UA (GPU_MAX_CB_BINDED+1)
#define DX12_ROOT_SIGNATURE_SAMPLER (GPU_MAX_CB_BINDED+2)
class Engine;
class WindowsWindow;
class GPUContextDX12;