Skip to content

Commit 7f62dfb

Browse files
bartwethatcosmonaut
authored andcommitted
casting, range check, and more compilation warning resolutions
1 parent 6902dac commit 7f62dfb

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

src/gpu/d3d12/SDL_gpu_d3d12.c

+33-13
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,7 @@ static SDL_bool D3D12_QueryFence(
11401140
SDL_GpuRenderer *driverData,
11411141
SDL_GpuFence *fence)
11421142
{
1143+
(void)driverData;
11431144
D3D12Fence *d3d12Fence = (D3D12Fence *)fence;
11441145
return ID3D12Fence_GetCompletedValue(d3d12Fence->handle) == D3D12_FENCE_SIGNAL_VALUE;
11451146
}
@@ -2015,13 +2016,13 @@ static D3D12ComputeRootSignature *D3D12_INTERNAL_CreateComputeRootSignature(
20152016
SDL_zeroa(descriptorRanges);
20162017
SDL_zero(rootParameter);
20172018

2018-
d3d12ComputeRootSignature->readOnlyStorageTextureRootIndex = -1;
2019-
d3d12ComputeRootSignature->readOnlyStorageBufferRootIndex = -1;
2020-
d3d12ComputeRootSignature->readWriteStorageTextureRootIndex = -1;
2021-
d3d12ComputeRootSignature->readWriteStorageBufferRootIndex = -1;
2019+
d3d12ComputeRootSignature->readOnlyStorageTextureRootIndex = (Uint32)-1;
2020+
d3d12ComputeRootSignature->readOnlyStorageBufferRootIndex = (Uint32)-1;
2021+
d3d12ComputeRootSignature->readWriteStorageTextureRootIndex = (Uint32)-1;
2022+
d3d12ComputeRootSignature->readWriteStorageBufferRootIndex = (Uint32)-1;
20222023

20232024
for (Uint32 i = 0; i < MAX_UNIFORM_BUFFERS_PER_STAGE; i += 1) {
2024-
d3d12ComputeRootSignature->uniformBufferRootIndex[i] = -1;
2025+
d3d12ComputeRootSignature->uniformBufferRootIndex[i] = (Uint32)-1;
20252026
}
20262027

20272028
if (createInfo->readOnlyStorageTextureCount) {
@@ -2625,13 +2626,21 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
26252626

26262627
heapFlags = D3D12_HEAP_FLAG_NONE;
26272628

2629+
if (((textureCreateInfo->depth <= 1) && (!textureCreateInfo->isCube) && (textureCreateInfo->layerCount > UINT16_MAX))
2630+
|| ((textureCreateInfo->depth > 1) && (textureCreateInfo->depth > UINT16_MAX))
2631+
|| (textureCreateInfo->levelCount > UINT16_MAX)) {
2632+
SDL_LogError(SDL_LOG_CATEGORY_GPU, "Failed to create texture! Argument out of range.");
2633+
D3D12_INTERNAL_DestroyTexture(renderer, texture);
2634+
return NULL;
2635+
}
2636+
26282637
if (textureCreateInfo->depth <= 1) {
26292638
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
26302639
desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
26312640
desc.Width = textureCreateInfo->width;
26322641
desc.Height = textureCreateInfo->height;
2633-
desc.DepthOrArraySize = textureCreateInfo->isCube ? 6 : textureCreateInfo->layerCount;
2634-
desc.MipLevels = textureCreateInfo->levelCount;
2642+
desc.DepthOrArraySize = textureCreateInfo->isCube ? 6 : (UINT16)textureCreateInfo->layerCount;
2643+
desc.MipLevels = (UINT16)textureCreateInfo->levelCount;
26352644
desc.Format = SDLToD3D12_TextureFormat[textureCreateInfo->format];
26362645
desc.SampleDesc.Count = 1;
26372646
desc.SampleDesc.Quality = 0;
@@ -2642,8 +2651,8 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
26422651
desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
26432652
desc.Width = textureCreateInfo->width;
26442653
desc.Height = textureCreateInfo->height;
2645-
desc.DepthOrArraySize = textureCreateInfo->depth;
2646-
desc.MipLevels = textureCreateInfo->levelCount;
2654+
desc.DepthOrArraySize = (UINT16)textureCreateInfo->depth;
2655+
desc.MipLevels = (UINT16)textureCreateInfo->levelCount;
26472656
desc.Format = SDLToD3D12_TextureFormat[textureCreateInfo->format];
26482657
desc.SampleDesc.Count = 1;
26492658
desc.SampleDesc.Quality = 0;
@@ -2761,7 +2770,7 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
27612770
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE3D;
27622771
rtvDesc.Texture3D.MipSlice = levelIndex;
27632772
rtvDesc.Texture3D.FirstWSlice = 0;
2764-
rtvDesc.Texture3D.WSize = -1; /* all depths */
2773+
rtvDesc.Texture3D.WSize = (UINT)-1; /* all depths */
27652774
} else {
27662775
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
27672776
rtvDesc.Texture2D.MipSlice = levelIndex;
@@ -3319,7 +3328,7 @@ static void D3D12_ReleaseShader(
33193328
SDL_GpuRenderer *driverData,
33203329
SDL_GpuShader *shader)
33213330
{
3322-
/* D3D12Renderer *renderer = (D3D12Renderer *)driverData; */
3331+
(void)driverData;
33233332
D3D12Shader *d3d12shader = (D3D12Shader *)shader;
33243333

33253334
if (d3d12shader->bytecode) {
@@ -3718,7 +3727,7 @@ static void D3D12_BeginRenderPass(
37183727
subresource->dsvHandle.cpuHandle,
37193728
clearFlags,
37203729
depthStencilAttachmentInfo->depthStencilClearValue.depth,
3721-
depthStencilAttachmentInfo->depthStencilClearValue.stencil,
3730+
(Uint8)depthStencilAttachmentInfo->depthStencilClearValue.stencil,
37223731
0,
37233732
NULL);
37243733
}
@@ -4409,6 +4418,7 @@ static void D3D12_DrawPrimitivesIndirect(
44094418
Uint32 drawCount,
44104419
Uint32 stride)
44114420
{
4421+
(void)stride;
44124422
D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer;
44134423
D3D12Buffer *d3d12Buffer = ((D3D12BufferContainer *)buffer)->activeBuffer;
44144424

@@ -4431,6 +4441,7 @@ static void D3D12_DrawIndexedPrimitivesIndirect(
44314441
Uint32 drawCount,
44324442
Uint32 stride)
44334443
{
4444+
(void)stride;
44344445
D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer;
44354446
D3D12Buffer *d3d12Buffer = ((D3D12BufferContainer *)buffer)->activeBuffer;
44364447

@@ -5515,6 +5526,7 @@ static SDL_bool D3D12_SupportsSwapchainComposition(
55155526
SDL_Window *window,
55165527
SDL_GpuSwapchainComposition swapchainComposition)
55175528
{
5529+
(void)window;
55185530
D3D12Renderer *renderer = (D3D12Renderer *)driverData;
55195531
DXGI_FORMAT format;
55205532
D3D12_FEATURE_DATA_FORMAT_SUPPORT formatSupport;
@@ -6038,6 +6050,7 @@ static SDL_GpuTextureFormat D3D12_GetSwapchainTextureFormat(
60386050
SDL_GpuRenderer *driverData,
60396051
SDL_Window *window)
60406052
{
6053+
(void)driverData;
60416054
D3D12WindowData *windowData = D3D12_INTERNAL_FetchWindowData(window);
60426055

60436056
if (windowData == NULL) {
@@ -6334,7 +6347,7 @@ static SDL_GpuTexture *D3D12_AcquireSwapchainTexture(
63346347
IDXGISwapChain_GetDesc(windowData->swapchain, &swapchainDesc);
63356348
SDL_GetWindowSize(window, &w, &h);
63366349

6337-
if (w != swapchainDesc.BufferDesc.Width || h != swapchainDesc.BufferDesc.Height) {
6350+
if ((INT64)w != (INT64)swapchainDesc.BufferDesc.Width || (INT64)h != (INT64)swapchainDesc.BufferDesc.Height) {
63386351
res = D3D12_INTERNAL_ResizeSwapchain(
63396352
renderer,
63406353
windowData,
@@ -6686,9 +6699,14 @@ static void D3D12_Submit(
66866699

66876700
/* Acquire a fence and set it to the in-flight fence */
66886701
d3d12CommandBuffer->inFlightFence = D3D12_INTERNAL_AcquireFence(renderer);
6702+
6703+
/* Fence creation can fail, we can't handle this nicely */
66896704
if (!d3d12CommandBuffer->inFlightFence) {
66906705
SDL_LogError(SDL_LOG_CATEGORY_GPU, "Failed to acquire fence.");
6706+
SDL_assert(d3d12CommandBuffer->inFlightFence);
6707+
return;
66916708
}
6709+
66926710
/* Command buffer has a reference to the in-flight fence */
66936711
(void)SDL_AtomicIncRef(&d3d12CommandBuffer->inFlightFence->referenceCount);
66946712

@@ -7087,6 +7105,8 @@ static SDL_bool D3D12_PrepareDriver(SDL_VideoDevice *_this)
70877105
IDXGIFactory6 *factory6;
70887106
IDXGIAdapter1 *adapter;
70897107

7108+
(void)_this;
7109+
70907110
/* Can we load D3D12? */
70917111

70927112
d3d12_dll = SDL_LoadObject(D3D12_DLL);

0 commit comments

Comments
 (0)