Skip to content

Commit 7418725

Browse files
committed
Log error when binding is missing
1 parent 40abeee commit 7418725

File tree

2 files changed

+182
-43
lines changed

2 files changed

+182
-43
lines changed

src/gpu/d3d12/SDL_gpu_d3d12.c

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,9 @@ struct D3D12CommandBuffer
10271027
D3D12Texture *computeReadOnlyStorageTextures[MAX_STORAGE_TEXTURES_PER_STAGE];
10281028
D3D12Buffer *computeReadOnlyStorageBuffers[MAX_STORAGE_BUFFERS_PER_STAGE];
10291029

1030+
D3D12_CPU_DESCRIPTOR_HANDLE computeReadWriteStorageTextureDescriptorHandles[MAX_COMPUTE_WRITE_TEXTURES];
1031+
D3D12_CPU_DESCRIPTOR_HANDLE computeReadWriteStorageBufferDescriptorHandles[MAX_COMPUTE_WRITE_BUFFERS];
1032+
10301033
// Track these separately because they are bound when the compute pass begins
10311034
D3D12TextureSubresource *computeReadWriteStorageTextureSubresources[MAX_COMPUTE_WRITE_TEXTURES];
10321035
Uint32 computeReadWriteStorageTextureSubresourceCount;
@@ -4906,7 +4909,7 @@ static void D3D12_INTERNAL_SetGPUDescriptorHeaps(D3D12CommandBuffer *commandBuff
49064909
heaps);
49074910
}
49084911

4909-
static void D3D12_INTERNAL_WriteGPUDescriptors(
4912+
static bool D3D12_INTERNAL_WriteGPUDescriptors(
49104913
D3D12CommandBuffer *commandBuffer,
49114914
D3D12_DESCRIPTOR_HEAP_TYPE heapType,
49124915
D3D12_CPU_DESCRIPTOR_HANDLE *resourceDescriptorHandles,
@@ -4915,6 +4918,7 @@ static void D3D12_INTERNAL_WriteGPUDescriptors(
49154918
{
49164919
D3D12DescriptorHeap *heap;
49174920
D3D12_CPU_DESCRIPTOR_HANDLE gpuHeapCpuHandle;
4921+
bool success = true;
49184922

49194923
/* Descriptor overflow, acquire new heaps */
49204924
if (commandBuffer->gpuDescriptorHeaps[heapType]->currentDescriptorIndex >= commandBuffer->gpuDescriptorHeaps[heapType]->maxDescriptors) {
@@ -4928,16 +4932,26 @@ static void D3D12_INTERNAL_WriteGPUDescriptors(
49284932
gpuBaseDescriptor->ptr = heap->descriptorHeapGPUStart.ptr + (heap->currentDescriptorIndex * heap->descriptorSize);
49294933

49304934
for (Uint32 i = 0; i < resourceHandleCount; i += 1) {
4931-
ID3D12Device_CopyDescriptorsSimple(
4932-
commandBuffer->renderer->device,
4933-
1,
4934-
gpuHeapCpuHandle,
4935-
resourceDescriptorHandles[i],
4936-
heapType);
4935+
// This will crash the driver if it gets a null handle! Cool!
4936+
if (resourceDescriptorHandles[i].ptr != 0)
4937+
{
4938+
ID3D12Device_CopyDescriptorsSimple(
4939+
commandBuffer->renderer->device,
4940+
1,
4941+
gpuHeapCpuHandle,
4942+
resourceDescriptorHandles[i],
4943+
heapType);
49374944

4938-
heap->currentDescriptorIndex += 1;
4939-
gpuHeapCpuHandle.ptr += heap->descriptorSize;
4945+
heap->currentDescriptorIndex += 1;
4946+
gpuHeapCpuHandle.ptr += heap->descriptorSize;
4947+
}
4948+
else
4949+
{
4950+
success = false;
4951+
}
49404952
}
4953+
4954+
return success;
49414955
}
49424956

49434957
static void D3D12_INTERNAL_BindGraphicsResources(
@@ -4976,12 +4990,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
49764990
cpuHandles[i] = commandBuffer->vertexSamplerDescriptorHandles[i];
49774991
}
49784992

4979-
D3D12_INTERNAL_WriteGPUDescriptors(
4993+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
49804994
commandBuffer,
49814995
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER,
49824996
cpuHandles,
49834997
graphicsPipeline->vertexSamplerCount,
4984-
&gpuDescriptorHandle);
4998+
&gpuDescriptorHandle))
4999+
{
5000+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing vertex sampler!");
5001+
}
49855002

49865003
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(
49875004
commandBuffer->graphicsCommandList,
@@ -4992,12 +5009,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
49925009
cpuHandles[i] = commandBuffer->vertexSamplerTextureDescriptorHandles[i];
49935010
}
49945011

4995-
D3D12_INTERNAL_WriteGPUDescriptors(
5012+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
49965013
commandBuffer,
49975014
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
49985015
cpuHandles,
49995016
graphicsPipeline->vertexSamplerCount,
5000-
&gpuDescriptorHandle);
5017+
&gpuDescriptorHandle))
5018+
{
5019+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing vertex texture!");
5020+
}
50015021

50025022
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(
50035023
commandBuffer->graphicsCommandList,
@@ -5013,12 +5033,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
50135033
cpuHandles[i] = commandBuffer->vertexStorageTextureDescriptorHandles[i];
50145034
}
50155035

5016-
D3D12_INTERNAL_WriteGPUDescriptors(
5036+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
50175037
commandBuffer,
50185038
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
50195039
cpuHandles,
50205040
graphicsPipeline->vertexStorageTextureCount,
5021-
&gpuDescriptorHandle);
5041+
&gpuDescriptorHandle))
5042+
{
5043+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing vertex storage texture!");
5044+
}
50225045

50235046
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(
50245047
commandBuffer->graphicsCommandList,
@@ -5034,12 +5057,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
50345057
cpuHandles[i] = commandBuffer->vertexStorageBufferDescriptorHandles[i];
50355058
}
50365059

5037-
D3D12_INTERNAL_WriteGPUDescriptors(
5060+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
50385061
commandBuffer,
50395062
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
50405063
cpuHandles,
50415064
graphicsPipeline->vertexStorageBufferCount,
5042-
&gpuDescriptorHandle);
5065+
&gpuDescriptorHandle))
5066+
{
5067+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing vertex storage buffer!");
5068+
}
50435069

50445070
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(
50455071
commandBuffer->graphicsCommandList,
@@ -5067,12 +5093,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
50675093
cpuHandles[i] = commandBuffer->fragmentSamplerDescriptorHandles[i];
50685094
}
50695095

5070-
D3D12_INTERNAL_WriteGPUDescriptors(
5096+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
50715097
commandBuffer,
50725098
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER,
50735099
cpuHandles,
50745100
graphicsPipeline->fragmentSamplerCount,
5075-
&gpuDescriptorHandle);
5101+
&gpuDescriptorHandle))
5102+
{
5103+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing fragment sampler!");
5104+
}
50765105

50775106
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(
50785107
commandBuffer->graphicsCommandList,
@@ -5083,12 +5112,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
50835112
cpuHandles[i] = commandBuffer->fragmentSamplerTextureDescriptorHandles[i];
50845113
}
50855114

5086-
D3D12_INTERNAL_WriteGPUDescriptors(
5115+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
50875116
commandBuffer,
50885117
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
50895118
cpuHandles,
50905119
graphicsPipeline->fragmentSamplerCount,
5091-
&gpuDescriptorHandle);
5120+
&gpuDescriptorHandle))
5121+
{
5122+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing fragment texture!");
5123+
}
50925124

50935125
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(
50945126
commandBuffer->graphicsCommandList,
@@ -5104,12 +5136,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
51045136
cpuHandles[i] = commandBuffer->fragmentStorageTextureDescriptorHandles[i];
51055137
}
51065138

5107-
D3D12_INTERNAL_WriteGPUDescriptors(
5139+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
51085140
commandBuffer,
51095141
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
51105142
cpuHandles,
51115143
graphicsPipeline->fragmentStorageTextureCount,
5112-
&gpuDescriptorHandle);
5144+
&gpuDescriptorHandle))
5145+
{
5146+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing fragment storage texture!");
5147+
}
51135148

51145149
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(
51155150
commandBuffer->graphicsCommandList,
@@ -5125,12 +5160,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
51255160
cpuHandles[i] = commandBuffer->fragmentStorageBufferDescriptorHandles[i];
51265161
}
51275162

5128-
D3D12_INTERNAL_WriteGPUDescriptors(
5163+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
51295164
commandBuffer,
51305165
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
51315166
cpuHandles,
51325167
graphicsPipeline->fragmentStorageBufferCount,
5133-
&gpuDescriptorHandle);
5168+
&gpuDescriptorHandle))
5169+
{
5170+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing fragment storage buffer!");
5171+
}
51345172

51355173
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(
51365174
commandBuffer->graphicsCommandList,
@@ -5349,6 +5387,7 @@ static void D3D12_BeginComputePass(
53495387
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
53505388

53515389
d3d12CommandBuffer->computeReadWriteStorageTextureSubresources[i] = subresource;
5390+
d3d12CommandBuffer->computeReadWriteStorageTextureDescriptorHandles[i] = subresource->uavHandle.cpuHandle;
53525391

53535392
D3D12_INTERNAL_TrackTexture(
53545393
d3d12CommandBuffer,
@@ -5367,6 +5406,7 @@ static void D3D12_BeginComputePass(
53675406
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
53685407

53695408
d3d12CommandBuffer->computeReadWriteStorageBuffers[i] = buffer;
5409+
d3d12CommandBuffer->computeReadWriteStorageBufferDescriptorHandles[i] = buffer->uavDescriptor.cpuHandle;
53705410

53715411
D3D12_INTERNAL_TrackBuffer(
53725412
d3d12CommandBuffer,
@@ -5420,15 +5460,18 @@ static void D3D12_BindComputePipeline(
54205460
// Bind write-only resources after setting root signature
54215461
if (pipeline->numReadWriteStorageTextures > 0) {
54225462
for (Uint32 i = 0; i < pipeline->numReadWriteStorageTextures; i += 1) {
5423-
cpuHandles[i] = d3d12CommandBuffer->computeReadWriteStorageTextureSubresources[i]->uavHandle.cpuHandle;
5463+
cpuHandles[i] = d3d12CommandBuffer->computeReadWriteStorageTextureDescriptorHandles[i];
54245464
}
54255465

5426-
D3D12_INTERNAL_WriteGPUDescriptors(
5466+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
54275467
d3d12CommandBuffer,
54285468
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
54295469
cpuHandles,
54305470
d3d12CommandBuffer->computeReadWriteStorageTextureSubresourceCount,
5431-
&gpuDescriptorHandle);
5471+
&gpuDescriptorHandle))
5472+
{
5473+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing compute read-write storage texture!");
5474+
}
54325475

54335476
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(
54345477
d3d12CommandBuffer->graphicsCommandList,
@@ -5438,15 +5481,18 @@ static void D3D12_BindComputePipeline(
54385481

54395482
if (pipeline->numReadWriteStorageBuffers > 0) {
54405483
for (Uint32 i = 0; i < pipeline->numReadWriteStorageBuffers; i += 1) {
5441-
cpuHandles[i] = d3d12CommandBuffer->computeReadWriteStorageBuffers[i]->uavDescriptor.cpuHandle;
5484+
cpuHandles[i] = d3d12CommandBuffer->computeReadWriteStorageBufferDescriptorHandles[i];
54425485
}
54435486

5444-
D3D12_INTERNAL_WriteGPUDescriptors(
5487+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
54455488
d3d12CommandBuffer,
54465489
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
54475490
cpuHandles,
54485491
d3d12CommandBuffer->computeReadWriteStorageBufferCount,
5449-
&gpuDescriptorHandle);
5492+
&gpuDescriptorHandle))
5493+
{
5494+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing compute read-write storage buffer!");
5495+
}
54505496

54515497
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(
54525498
d3d12CommandBuffer->graphicsCommandList,
@@ -5597,12 +5643,15 @@ static void D3D12_INTERNAL_BindComputeResources(
55975643
cpuHandles[i] = commandBuffer->computeSamplerDescriptorHandles[i];
55985644
}
55995645

5600-
D3D12_INTERNAL_WriteGPUDescriptors(
5646+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
56015647
commandBuffer,
56025648
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER,
56035649
cpuHandles,
56045650
computePipeline->numSamplers,
5605-
&gpuDescriptorHandle);
5651+
&gpuDescriptorHandle))
5652+
{
5653+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing compute sampler!");
5654+
}
56065655

56075656
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(
56085657
commandBuffer->graphicsCommandList,
@@ -5613,12 +5662,15 @@ static void D3D12_INTERNAL_BindComputeResources(
56135662
cpuHandles[i] = commandBuffer->computeSamplerTextureDescriptorHandles[i];
56145663
}
56155664

5616-
D3D12_INTERNAL_WriteGPUDescriptors(
5665+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
56175666
commandBuffer,
56185667
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
56195668
cpuHandles,
56205669
computePipeline->numSamplers,
5621-
&gpuDescriptorHandle);
5670+
&gpuDescriptorHandle))
5671+
{
5672+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing compute texture!");
5673+
}
56225674

56235675
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(
56245676
commandBuffer->graphicsCommandList,
@@ -5634,12 +5686,15 @@ static void D3D12_INTERNAL_BindComputeResources(
56345686
cpuHandles[i] = commandBuffer->computeReadOnlyStorageTextureDescriptorHandles[i];
56355687
}
56365688

5637-
D3D12_INTERNAL_WriteGPUDescriptors(
5689+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
56385690
commandBuffer,
56395691
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
56405692
cpuHandles,
56415693
computePipeline->numReadOnlyStorageTextures,
5642-
&gpuDescriptorHandle);
5694+
&gpuDescriptorHandle))
5695+
{
5696+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing compute storage texture!");
5697+
}
56435698

56445699
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(
56455700
commandBuffer->graphicsCommandList,
@@ -5655,12 +5710,15 @@ static void D3D12_INTERNAL_BindComputeResources(
56555710
cpuHandles[i] = commandBuffer->computeReadOnlyStorageBufferDescriptorHandles[i];
56565711
}
56575712

5658-
D3D12_INTERNAL_WriteGPUDescriptors(
5713+
if (!D3D12_INTERNAL_WriteGPUDescriptors(
56595714
commandBuffer,
56605715
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
56615716
cpuHandles,
56625717
computePipeline->numReadOnlyStorageBuffers,
5663-
&gpuDescriptorHandle);
5718+
&gpuDescriptorHandle))
5719+
{
5720+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Missing expected compute storage buffer!");
5721+
}
56645722

56655723
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(
56665724
commandBuffer->graphicsCommandList,
@@ -5774,6 +5832,9 @@ static void D3D12_EndComputePass(
57745832
SDL_zeroa(d3d12CommandBuffer->computeSamplerTextureDescriptorHandles);
57755833
SDL_zeroa(d3d12CommandBuffer->computeSamplerDescriptorHandles);
57765834

5835+
SDL_zeroa(d3d12CommandBuffer->computeReadWriteStorageTextureDescriptorHandles);
5836+
SDL_zeroa(d3d12CommandBuffer->computeReadWriteStorageBufferDescriptorHandles);
5837+
57775838
d3d12CommandBuffer->currentComputePipeline = NULL;
57785839
}
57795840

0 commit comments

Comments
 (0)