@@ -1027,6 +1027,9 @@ struct D3D12CommandBuffer
1027
1027
D3D12Texture * computeReadOnlyStorageTextures [MAX_STORAGE_TEXTURES_PER_STAGE ];
1028
1028
D3D12Buffer * computeReadOnlyStorageBuffers [MAX_STORAGE_BUFFERS_PER_STAGE ];
1029
1029
1030
+ D3D12_CPU_DESCRIPTOR_HANDLE computeReadWriteStorageTextureDescriptorHandles [MAX_COMPUTE_WRITE_TEXTURES ];
1031
+ D3D12_CPU_DESCRIPTOR_HANDLE computeReadWriteStorageBufferDescriptorHandles [MAX_COMPUTE_WRITE_BUFFERS ];
1032
+
1030
1033
// Track these separately because they are bound when the compute pass begins
1031
1034
D3D12TextureSubresource * computeReadWriteStorageTextureSubresources [MAX_COMPUTE_WRITE_TEXTURES ];
1032
1035
Uint32 computeReadWriteStorageTextureSubresourceCount ;
@@ -4906,7 +4909,7 @@ static void D3D12_INTERNAL_SetGPUDescriptorHeaps(D3D12CommandBuffer *commandBuff
4906
4909
heaps );
4907
4910
}
4908
4911
4909
- static void D3D12_INTERNAL_WriteGPUDescriptors (
4912
+ static bool D3D12_INTERNAL_WriteGPUDescriptors (
4910
4913
D3D12CommandBuffer * commandBuffer ,
4911
4914
D3D12_DESCRIPTOR_HEAP_TYPE heapType ,
4912
4915
D3D12_CPU_DESCRIPTOR_HANDLE * resourceDescriptorHandles ,
@@ -4915,6 +4918,7 @@ static void D3D12_INTERNAL_WriteGPUDescriptors(
4915
4918
{
4916
4919
D3D12DescriptorHeap * heap ;
4917
4920
D3D12_CPU_DESCRIPTOR_HANDLE gpuHeapCpuHandle ;
4921
+ bool success = true;
4918
4922
4919
4923
/* Descriptor overflow, acquire new heaps */
4920
4924
if (commandBuffer -> gpuDescriptorHeaps [heapType ]-> currentDescriptorIndex >= commandBuffer -> gpuDescriptorHeaps [heapType ]-> maxDescriptors ) {
@@ -4928,16 +4932,26 @@ static void D3D12_INTERNAL_WriteGPUDescriptors(
4928
4932
gpuBaseDescriptor -> ptr = heap -> descriptorHeapGPUStart .ptr + (heap -> currentDescriptorIndex * heap -> descriptorSize );
4929
4933
4930
4934
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 );
4937
4944
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
+ }
4940
4952
}
4953
+
4954
+ return success ;
4941
4955
}
4942
4956
4943
4957
static void D3D12_INTERNAL_BindGraphicsResources (
@@ -4976,12 +4990,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
4976
4990
cpuHandles [i ] = commandBuffer -> vertexSamplerDescriptorHandles [i ];
4977
4991
}
4978
4992
4979
- D3D12_INTERNAL_WriteGPUDescriptors (
4993
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
4980
4994
commandBuffer ,
4981
4995
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER ,
4982
4996
cpuHandles ,
4983
4997
graphicsPipeline -> vertexSamplerCount ,
4984
- & gpuDescriptorHandle );
4998
+ & gpuDescriptorHandle ))
4999
+ {
5000
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing vertex sampler!" );
5001
+ }
4985
5002
4986
5003
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable (
4987
5004
commandBuffer -> graphicsCommandList ,
@@ -4992,12 +5009,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
4992
5009
cpuHandles [i ] = commandBuffer -> vertexSamplerTextureDescriptorHandles [i ];
4993
5010
}
4994
5011
4995
- D3D12_INTERNAL_WriteGPUDescriptors (
5012
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
4996
5013
commandBuffer ,
4997
5014
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
4998
5015
cpuHandles ,
4999
5016
graphicsPipeline -> vertexSamplerCount ,
5000
- & gpuDescriptorHandle );
5017
+ & gpuDescriptorHandle ))
5018
+ {
5019
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing vertex texture!" );
5020
+ }
5001
5021
5002
5022
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable (
5003
5023
commandBuffer -> graphicsCommandList ,
@@ -5013,12 +5033,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
5013
5033
cpuHandles [i ] = commandBuffer -> vertexStorageTextureDescriptorHandles [i ];
5014
5034
}
5015
5035
5016
- D3D12_INTERNAL_WriteGPUDescriptors (
5036
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5017
5037
commandBuffer ,
5018
5038
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
5019
5039
cpuHandles ,
5020
5040
graphicsPipeline -> vertexStorageTextureCount ,
5021
- & gpuDescriptorHandle );
5041
+ & gpuDescriptorHandle ))
5042
+ {
5043
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing vertex storage texture!" );
5044
+ }
5022
5045
5023
5046
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable (
5024
5047
commandBuffer -> graphicsCommandList ,
@@ -5034,12 +5057,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
5034
5057
cpuHandles [i ] = commandBuffer -> vertexStorageBufferDescriptorHandles [i ];
5035
5058
}
5036
5059
5037
- D3D12_INTERNAL_WriteGPUDescriptors (
5060
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5038
5061
commandBuffer ,
5039
5062
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
5040
5063
cpuHandles ,
5041
5064
graphicsPipeline -> vertexStorageBufferCount ,
5042
- & gpuDescriptorHandle );
5065
+ & gpuDescriptorHandle ))
5066
+ {
5067
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing vertex storage buffer!" );
5068
+ }
5043
5069
5044
5070
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable (
5045
5071
commandBuffer -> graphicsCommandList ,
@@ -5067,12 +5093,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
5067
5093
cpuHandles [i ] = commandBuffer -> fragmentSamplerDescriptorHandles [i ];
5068
5094
}
5069
5095
5070
- D3D12_INTERNAL_WriteGPUDescriptors (
5096
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5071
5097
commandBuffer ,
5072
5098
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER ,
5073
5099
cpuHandles ,
5074
5100
graphicsPipeline -> fragmentSamplerCount ,
5075
- & gpuDescriptorHandle );
5101
+ & gpuDescriptorHandle ))
5102
+ {
5103
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing fragment sampler!" );
5104
+ }
5076
5105
5077
5106
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable (
5078
5107
commandBuffer -> graphicsCommandList ,
@@ -5083,12 +5112,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
5083
5112
cpuHandles [i ] = commandBuffer -> fragmentSamplerTextureDescriptorHandles [i ];
5084
5113
}
5085
5114
5086
- D3D12_INTERNAL_WriteGPUDescriptors (
5115
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5087
5116
commandBuffer ,
5088
5117
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
5089
5118
cpuHandles ,
5090
5119
graphicsPipeline -> fragmentSamplerCount ,
5091
- & gpuDescriptorHandle );
5120
+ & gpuDescriptorHandle ))
5121
+ {
5122
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing fragment texture!" );
5123
+ }
5092
5124
5093
5125
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable (
5094
5126
commandBuffer -> graphicsCommandList ,
@@ -5104,12 +5136,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
5104
5136
cpuHandles [i ] = commandBuffer -> fragmentStorageTextureDescriptorHandles [i ];
5105
5137
}
5106
5138
5107
- D3D12_INTERNAL_WriteGPUDescriptors (
5139
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5108
5140
commandBuffer ,
5109
5141
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
5110
5142
cpuHandles ,
5111
5143
graphicsPipeline -> fragmentStorageTextureCount ,
5112
- & gpuDescriptorHandle );
5144
+ & gpuDescriptorHandle ))
5145
+ {
5146
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing fragment storage texture!" );
5147
+ }
5113
5148
5114
5149
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable (
5115
5150
commandBuffer -> graphicsCommandList ,
@@ -5125,12 +5160,15 @@ static void D3D12_INTERNAL_BindGraphicsResources(
5125
5160
cpuHandles [i ] = commandBuffer -> fragmentStorageBufferDescriptorHandles [i ];
5126
5161
}
5127
5162
5128
- D3D12_INTERNAL_WriteGPUDescriptors (
5163
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5129
5164
commandBuffer ,
5130
5165
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
5131
5166
cpuHandles ,
5132
5167
graphicsPipeline -> fragmentStorageBufferCount ,
5133
- & gpuDescriptorHandle );
5168
+ & gpuDescriptorHandle ))
5169
+ {
5170
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing fragment storage buffer!" );
5171
+ }
5134
5172
5135
5173
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable (
5136
5174
commandBuffer -> graphicsCommandList ,
@@ -5349,6 +5387,7 @@ static void D3D12_BeginComputePass(
5349
5387
D3D12_RESOURCE_STATE_UNORDERED_ACCESS );
5350
5388
5351
5389
d3d12CommandBuffer -> computeReadWriteStorageTextureSubresources [i ] = subresource ;
5390
+ d3d12CommandBuffer -> computeReadWriteStorageTextureDescriptorHandles [i ] = subresource -> uavHandle .cpuHandle ;
5352
5391
5353
5392
D3D12_INTERNAL_TrackTexture (
5354
5393
d3d12CommandBuffer ,
@@ -5367,6 +5406,7 @@ static void D3D12_BeginComputePass(
5367
5406
D3D12_RESOURCE_STATE_UNORDERED_ACCESS );
5368
5407
5369
5408
d3d12CommandBuffer -> computeReadWriteStorageBuffers [i ] = buffer ;
5409
+ d3d12CommandBuffer -> computeReadWriteStorageBufferDescriptorHandles [i ] = buffer -> uavDescriptor .cpuHandle ;
5370
5410
5371
5411
D3D12_INTERNAL_TrackBuffer (
5372
5412
d3d12CommandBuffer ,
@@ -5420,15 +5460,18 @@ static void D3D12_BindComputePipeline(
5420
5460
// Bind write-only resources after setting root signature
5421
5461
if (pipeline -> numReadWriteStorageTextures > 0 ) {
5422
5462
for (Uint32 i = 0 ; i < pipeline -> numReadWriteStorageTextures ; i += 1 ) {
5423
- cpuHandles [i ] = d3d12CommandBuffer -> computeReadWriteStorageTextureSubresources [i ]-> uavHandle . cpuHandle ;
5463
+ cpuHandles [i ] = d3d12CommandBuffer -> computeReadWriteStorageTextureDescriptorHandles [i ];
5424
5464
}
5425
5465
5426
- D3D12_INTERNAL_WriteGPUDescriptors (
5466
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5427
5467
d3d12CommandBuffer ,
5428
5468
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
5429
5469
cpuHandles ,
5430
5470
d3d12CommandBuffer -> computeReadWriteStorageTextureSubresourceCount ,
5431
- & gpuDescriptorHandle );
5471
+ & gpuDescriptorHandle ))
5472
+ {
5473
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing compute read-write storage texture!" );
5474
+ }
5432
5475
5433
5476
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable (
5434
5477
d3d12CommandBuffer -> graphicsCommandList ,
@@ -5438,15 +5481,18 @@ static void D3D12_BindComputePipeline(
5438
5481
5439
5482
if (pipeline -> numReadWriteStorageBuffers > 0 ) {
5440
5483
for (Uint32 i = 0 ; i < pipeline -> numReadWriteStorageBuffers ; i += 1 ) {
5441
- cpuHandles [i ] = d3d12CommandBuffer -> computeReadWriteStorageBuffers [i ]-> uavDescriptor . cpuHandle ;
5484
+ cpuHandles [i ] = d3d12CommandBuffer -> computeReadWriteStorageBufferDescriptorHandles [i ];
5442
5485
}
5443
5486
5444
- D3D12_INTERNAL_WriteGPUDescriptors (
5487
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5445
5488
d3d12CommandBuffer ,
5446
5489
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
5447
5490
cpuHandles ,
5448
5491
d3d12CommandBuffer -> computeReadWriteStorageBufferCount ,
5449
- & gpuDescriptorHandle );
5492
+ & gpuDescriptorHandle ))
5493
+ {
5494
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing compute read-write storage buffer!" );
5495
+ }
5450
5496
5451
5497
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable (
5452
5498
d3d12CommandBuffer -> graphicsCommandList ,
@@ -5597,12 +5643,15 @@ static void D3D12_INTERNAL_BindComputeResources(
5597
5643
cpuHandles [i ] = commandBuffer -> computeSamplerDescriptorHandles [i ];
5598
5644
}
5599
5645
5600
- D3D12_INTERNAL_WriteGPUDescriptors (
5646
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5601
5647
commandBuffer ,
5602
5648
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER ,
5603
5649
cpuHandles ,
5604
5650
computePipeline -> numSamplers ,
5605
- & gpuDescriptorHandle );
5651
+ & gpuDescriptorHandle ))
5652
+ {
5653
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing compute sampler!" );
5654
+ }
5606
5655
5607
5656
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable (
5608
5657
commandBuffer -> graphicsCommandList ,
@@ -5613,12 +5662,15 @@ static void D3D12_INTERNAL_BindComputeResources(
5613
5662
cpuHandles [i ] = commandBuffer -> computeSamplerTextureDescriptorHandles [i ];
5614
5663
}
5615
5664
5616
- D3D12_INTERNAL_WriteGPUDescriptors (
5665
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5617
5666
commandBuffer ,
5618
5667
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
5619
5668
cpuHandles ,
5620
5669
computePipeline -> numSamplers ,
5621
- & gpuDescriptorHandle );
5670
+ & gpuDescriptorHandle ))
5671
+ {
5672
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing compute texture!" );
5673
+ }
5622
5674
5623
5675
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable (
5624
5676
commandBuffer -> graphicsCommandList ,
@@ -5634,12 +5686,15 @@ static void D3D12_INTERNAL_BindComputeResources(
5634
5686
cpuHandles [i ] = commandBuffer -> computeReadOnlyStorageTextureDescriptorHandles [i ];
5635
5687
}
5636
5688
5637
- D3D12_INTERNAL_WriteGPUDescriptors (
5689
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5638
5690
commandBuffer ,
5639
5691
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
5640
5692
cpuHandles ,
5641
5693
computePipeline -> numReadOnlyStorageTextures ,
5642
- & gpuDescriptorHandle );
5694
+ & gpuDescriptorHandle ))
5695
+ {
5696
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing compute storage texture!" );
5697
+ }
5643
5698
5644
5699
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable (
5645
5700
commandBuffer -> graphicsCommandList ,
@@ -5655,12 +5710,15 @@ static void D3D12_INTERNAL_BindComputeResources(
5655
5710
cpuHandles [i ] = commandBuffer -> computeReadOnlyStorageBufferDescriptorHandles [i ];
5656
5711
}
5657
5712
5658
- D3D12_INTERNAL_WriteGPUDescriptors (
5713
+ if (! D3D12_INTERNAL_WriteGPUDescriptors (
5659
5714
commandBuffer ,
5660
5715
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ,
5661
5716
cpuHandles ,
5662
5717
computePipeline -> numReadOnlyStorageBuffers ,
5663
- & gpuDescriptorHandle );
5718
+ & gpuDescriptorHandle ))
5719
+ {
5720
+ SDL_LogError (SDL_LOG_CATEGORY_GPU , "%s" , "Missing expected compute storage buffer!" );
5721
+ }
5664
5722
5665
5723
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable (
5666
5724
commandBuffer -> graphicsCommandList ,
@@ -5774,6 +5832,9 @@ static void D3D12_EndComputePass(
5774
5832
SDL_zeroa (d3d12CommandBuffer -> computeSamplerTextureDescriptorHandles );
5775
5833
SDL_zeroa (d3d12CommandBuffer -> computeSamplerDescriptorHandles );
5776
5834
5835
+ SDL_zeroa (d3d12CommandBuffer -> computeReadWriteStorageTextureDescriptorHandles );
5836
+ SDL_zeroa (d3d12CommandBuffer -> computeReadWriteStorageBufferDescriptorHandles );
5837
+
5777
5838
d3d12CommandBuffer -> currentComputePipeline = NULL ;
5778
5839
}
5779
5840
0 commit comments