gpu: Clean up unused code in Vulkan and D3D12 drivers

This commit is contained in:
Caleb Cornett
2025-03-12 21:55:34 -04:00
committed by Caleb Cornett
parent 71c4de190c
commit 0e29c6295c
2 changed files with 5 additions and 108 deletions
+4 -49
View File
@@ -121,18 +121,6 @@
#define SDL_GPU_SHADERSTAGE_COMPUTE (SDL_GPUShaderStage)2 #define SDL_GPU_SHADERSTAGE_COMPUTE (SDL_GPUShaderStage)2
#define EXPAND_ELEMENTS_IF_NEEDED(arr, initialValue, type) \
if (arr->count == arr->capacity) { \
if (arr->capacity == 0) { \
arr->capacity = initialValue; \
} else { \
arr->capacity *= 2; \
} \
arr->elements = (type *)SDL_realloc( \
arr->elements, \
arr->capacity * sizeof(type)); \
}
#ifdef _WIN32 #ifdef _WIN32
#define HRESULT_FMT "(0x%08lX)" #define HRESULT_FMT "(0x%08lX)"
#else #else
@@ -1179,7 +1167,6 @@ static void D3D12_INTERNAL_SetError(
// Release / Cleanup // Release / Cleanup
static void D3D12_INTERNAL_ReleaseStagingDescriptorHandle( static void D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
D3D12Renderer *renderer,
D3D12StagingDescriptor *cpuDescriptor) D3D12StagingDescriptor *cpuDescriptor)
{ {
D3D12StagingDescriptorPool *pool = cpuDescriptor->pool; D3D12StagingDescriptorPool *pool = cpuDescriptor->pool;
@@ -1193,7 +1180,6 @@ static void D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
} }
static void D3D12_INTERNAL_DestroyBuffer( static void D3D12_INTERNAL_DestroyBuffer(
D3D12Renderer *renderer,
D3D12Buffer *buffer) D3D12Buffer *buffer)
{ {
if (!buffer) { if (!buffer) {
@@ -1207,13 +1193,10 @@ static void D3D12_INTERNAL_DestroyBuffer(
NULL); NULL);
} }
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&buffer->srvDescriptor); &buffer->srvDescriptor);
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&buffer->uavDescriptor); &buffer->uavDescriptor);
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&buffer->cbvDescriptor); &buffer->cbvDescriptor);
if (buffer->handle) { if (buffer->handle) {
@@ -1264,7 +1247,6 @@ static void D3D12_INTERNAL_ReleaseBufferContainer(
} }
static void D3D12_INTERNAL_DestroyTexture( static void D3D12_INTERNAL_DestroyTexture(
D3D12Renderer *renderer,
D3D12Texture *texture) D3D12Texture *texture)
{ {
if (!texture) { if (!texture) {
@@ -1275,24 +1257,20 @@ static void D3D12_INTERNAL_DestroyTexture(
if (subresource->rtvHandles) { if (subresource->rtvHandles) {
for (Uint32 depthIndex = 0; depthIndex < subresource->depth; depthIndex += 1) { for (Uint32 depthIndex = 0; depthIndex < subresource->depth; depthIndex += 1) {
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&subresource->rtvHandles[depthIndex]); &subresource->rtvHandles[depthIndex]);
} }
SDL_free(subresource->rtvHandles); SDL_free(subresource->rtvHandles);
} }
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&subresource->uavHandle); &subresource->uavHandle);
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&subresource->dsvHandle); &subresource->dsvHandle);
} }
SDL_free(texture->subresources); SDL_free(texture->subresources);
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&texture->srvHandle); &texture->srvHandle);
if (texture->resource) { if (texture->resource) {
@@ -1344,11 +1322,9 @@ static void D3D12_INTERNAL_ReleaseTextureContainer(
} }
static void D3D12_INTERNAL_DestroySampler( static void D3D12_INTERNAL_DestroySampler(
D3D12Renderer *renderer,
D3D12Sampler *sampler) D3D12Sampler *sampler)
{ {
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&sampler->handle); &sampler->handle);
SDL_free(sampler); SDL_free(sampler);
@@ -1503,7 +1479,6 @@ static void D3D12_INTERNAL_DestroyRenderer(D3D12Renderer *renderer)
// Release uniform buffers // Release uniform buffers
for (Uint32 i = 0; i < renderer->uniformBufferPoolCount; i += 1) { for (Uint32 i = 0; i < renderer->uniformBufferPoolCount; i += 1) {
D3D12_INTERNAL_DestroyBuffer( D3D12_INTERNAL_DestroyBuffer(
renderer,
renderer->uniformBufferPool[i]->buffer); renderer->uniformBufferPool[i]->buffer);
SDL_free(renderer->uniformBufferPool[i]); SDL_free(renderer->uniformBufferPool[i]);
} }
@@ -2499,12 +2474,8 @@ static D3D12GraphicsRootSignature *D3D12_INTERNAL_CreateGraphicsRootSignature(
} }
static bool D3D12_INTERNAL_CreateShaderBytecode( static bool D3D12_INTERNAL_CreateShaderBytecode(
D3D12Renderer *renderer,
Uint32 stage,
SDL_GPUShaderFormat format,
const Uint8 *code, const Uint8 *code,
size_t codeSize, size_t codeSize,
const char *entrypointName,
void **pBytecode, void **pBytecode,
size_t *pBytecodeSize) size_t *pBytecodeSize)
{ {
@@ -2725,12 +2696,8 @@ static SDL_GPUComputePipeline *D3D12_CreateComputePipeline(
ID3D12PipelineState *pipelineState; ID3D12PipelineState *pipelineState;
if (!D3D12_INTERNAL_CreateShaderBytecode( if (!D3D12_INTERNAL_CreateShaderBytecode(
renderer,
SDL_GPU_SHADERSTAGE_COMPUTE,
createinfo->format,
createinfo->code, createinfo->code,
createinfo->code_size, createinfo->code_size,
createinfo->entrypoint,
&bytecode, &bytecode,
&bytecodeSize)) { &bytecodeSize)) {
return NULL; return NULL;
@@ -3137,18 +3104,13 @@ static SDL_GPUShader *D3D12_CreateShader(
SDL_GPURenderer *driverData, SDL_GPURenderer *driverData,
const SDL_GPUShaderCreateInfo *createinfo) const SDL_GPUShaderCreateInfo *createinfo)
{ {
D3D12Renderer *renderer = (D3D12Renderer *)driverData;
void *bytecode; void *bytecode;
size_t bytecodeSize; size_t bytecodeSize;
D3D12Shader *shader; D3D12Shader *shader;
if (!D3D12_INTERNAL_CreateShaderBytecode( if (!D3D12_INTERNAL_CreateShaderBytecode(
renderer,
createinfo->stage,
createinfo->format,
createinfo->code, createinfo->code,
createinfo->code_size, createinfo->code_size,
createinfo->entrypoint,
&bytecode, &bytecode,
&bytecodeSize)) { &bytecodeSize)) {
return NULL; return NULL;
@@ -3273,7 +3235,7 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
(void **)&handle); (void **)&handle);
if (FAILED(res)) { if (FAILED(res)) {
D3D12_INTERNAL_SetError(renderer, "Failed to create texture!", res); D3D12_INTERNAL_SetError(renderer, "Failed to create texture!", res);
D3D12_INTERNAL_DestroyTexture(renderer, texture); D3D12_INTERNAL_DestroyTexture(texture);
return NULL; return NULL;
} }
@@ -3339,7 +3301,7 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
texture->subresources = (D3D12TextureSubresource *)SDL_calloc( texture->subresources = (D3D12TextureSubresource *)SDL_calloc(
texture->subresourceCount, sizeof(D3D12TextureSubresource)); texture->subresourceCount, sizeof(D3D12TextureSubresource));
if (!texture->subresources) { if (!texture->subresources) {
D3D12_INTERNAL_DestroyTexture(renderer, texture); D3D12_INTERNAL_DestroyTexture(texture);
return NULL; return NULL;
} }
for (Uint32 layerIndex = 0; layerIndex < layerCount; layerIndex += 1) { for (Uint32 layerIndex = 0; layerIndex < layerCount; layerIndex += 1) {
@@ -3617,7 +3579,7 @@ static D3D12Buffer *D3D12_INTERNAL_CreateBuffer(
(void **)&handle); (void **)&handle);
if (FAILED(res)) { if (FAILED(res)) {
D3D12_INTERNAL_SetError(renderer, "Could not create buffer!", res); D3D12_INTERNAL_SetError(renderer, "Could not create buffer!", res);
D3D12_INTERNAL_DestroyBuffer(renderer, buffer); D3D12_INTERNAL_DestroyBuffer(buffer);
return NULL; return NULL;
} }
@@ -3707,7 +3669,7 @@ static D3D12Buffer *D3D12_INTERNAL_CreateBuffer(
(void **)&buffer->mapPointer); (void **)&buffer->mapPointer);
if (FAILED(res)) { if (FAILED(res)) {
D3D12_INTERNAL_SetError(renderer, "Failed to map upload buffer!", res); D3D12_INTERNAL_SetError(renderer, "Failed to map upload buffer!", res);
D3D12_INTERNAL_DestroyBuffer(renderer, buffer); D3D12_INTERNAL_DestroyBuffer(buffer);
return NULL; return NULL;
} }
} }
@@ -6633,10 +6595,8 @@ static bool D3D12_INTERNAL_ResizeSwapchain(
// Release views and clean up // Release views and clean up
for (Uint32 i = 0; i < windowData->swapchainTextureCount; i += 1) { for (Uint32 i = 0; i < windowData->swapchainTextureCount; i += 1) {
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&windowData->textureContainers[i].activeTexture->srvHandle); &windowData->textureContainers[i].activeTexture->srvHandle);
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles[0]); &windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles[0]);
SDL_free(windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles); SDL_free(windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles);
@@ -6684,10 +6644,8 @@ static void D3D12_INTERNAL_DestroySwapchain(
// Release views and clean up // Release views and clean up
for (Uint32 i = 0; i < windowData->swapchainTextureCount; i += 1) { for (Uint32 i = 0; i < windowData->swapchainTextureCount; i += 1) {
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&windowData->textureContainers[i].activeTexture->srvHandle); &windowData->textureContainers[i].activeTexture->srvHandle);
D3D12_INTERNAL_ReleaseStagingDescriptorHandle( D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
renderer,
&windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles[0]); &windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles[0]);
SDL_free(windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles); SDL_free(windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles);
@@ -7439,7 +7397,6 @@ static void D3D12_INTERNAL_PerformPendingDestroys(D3D12Renderer *renderer)
for (Sint32 i = renderer->buffersToDestroyCount - 1; i >= 0; i -= 1) { for (Sint32 i = renderer->buffersToDestroyCount - 1; i >= 0; i -= 1) {
if (SDL_GetAtomicInt(&renderer->buffersToDestroy[i]->referenceCount) == 0) { if (SDL_GetAtomicInt(&renderer->buffersToDestroy[i]->referenceCount) == 0) {
D3D12_INTERNAL_DestroyBuffer( D3D12_INTERNAL_DestroyBuffer(
renderer,
renderer->buffersToDestroy[i]); renderer->buffersToDestroy[i]);
renderer->buffersToDestroy[i] = renderer->buffersToDestroy[renderer->buffersToDestroyCount - 1]; renderer->buffersToDestroy[i] = renderer->buffersToDestroy[renderer->buffersToDestroyCount - 1];
@@ -7450,7 +7407,6 @@ static void D3D12_INTERNAL_PerformPendingDestroys(D3D12Renderer *renderer)
for (Sint32 i = renderer->texturesToDestroyCount - 1; i >= 0; i -= 1) { for (Sint32 i = renderer->texturesToDestroyCount - 1; i >= 0; i -= 1) {
if (SDL_GetAtomicInt(&renderer->texturesToDestroy[i]->referenceCount) == 0) { if (SDL_GetAtomicInt(&renderer->texturesToDestroy[i]->referenceCount) == 0) {
D3D12_INTERNAL_DestroyTexture( D3D12_INTERNAL_DestroyTexture(
renderer,
renderer->texturesToDestroy[i]); renderer->texturesToDestroy[i]);
renderer->texturesToDestroy[i] = renderer->texturesToDestroy[renderer->texturesToDestroyCount - 1]; renderer->texturesToDestroy[i] = renderer->texturesToDestroy[renderer->texturesToDestroyCount - 1];
@@ -7461,7 +7417,6 @@ static void D3D12_INTERNAL_PerformPendingDestroys(D3D12Renderer *renderer)
for (Sint32 i = renderer->samplersToDestroyCount - 1; i >= 0; i -= 1) { for (Sint32 i = renderer->samplersToDestroyCount - 1; i >= 0; i -= 1) {
if (SDL_GetAtomicInt(&renderer->samplersToDestroy[i]->referenceCount) == 0) { if (SDL_GetAtomicInt(&renderer->samplersToDestroy[i]->referenceCount) == 0) {
D3D12_INTERNAL_DestroySampler( D3D12_INTERNAL_DestroySampler(
renderer,
renderer->samplersToDestroy[i]); renderer->samplersToDestroy[i]);
renderer->samplersToDestroy[i] = renderer->samplersToDestroy[renderer->samplersToDestroyCount - 1]; renderer->samplersToDestroy[i] = renderer->samplersToDestroy[renderer->samplersToDestroyCount - 1];
+1 -59
View File
@@ -33,8 +33,6 @@
#include "../SDL_sysgpu.h" #include "../SDL_sysgpu.h"
#define VULKAN_INTERNAL_clamp(val, min, max) SDL_max(min, SDL_min(val, max))
// Global Vulkan Loader Entry Points // Global Vulkan Loader Entry Points
static PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; static PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
@@ -79,33 +77,6 @@ typedef struct VulkanExtensions
VK_COMPONENT_SWIZZLE_IDENTITY \ VK_COMPONENT_SWIZZLE_IDENTITY \
} }
#define NULL_DESC_LAYOUT (VkDescriptorSetLayout)0
#define NULL_PIPELINE_LAYOUT (VkPipelineLayout)0
#define NULL_RENDER_PASS (SDL_GPURenderPass *)0
#define EXPAND_ELEMENTS_IF_NEEDED(arr, initialValue, type) \
do { \
if (arr->count == arr->capacity) { \
if (arr->capacity == 0) { \
arr->capacity = initialValue; \
} else { \
arr->capacity *= 2; \
} \
arr->elements = (type *)SDL_realloc( \
arr->elements, \
arr->capacity * sizeof(type)); \
} \
} while (0)
#define MOVE_ARRAY_CONTENTS_AND_RESET(i, dstArr, dstCount, srcArr, srcCount) \
do { \
for ((i) = 0; (i) < (srcCount); (i) += 1) { \
(dstArr)[i] = (srcArr)[i]; \
} \
(dstCount) = (srcCount); \
(srcCount) = 0; \
while (0)
// Conversions // Conversions
static const Uint8 DEVICE_PRIORITY_HIGHPERFORMANCE[] = { static const Uint8 DEVICE_PRIORITY_HIGHPERFORMANCE[] = {
@@ -1321,7 +1292,6 @@ static inline Uint32 VULKAN_INTERNAL_NextHighestAlignment32(
} }
static void VULKAN_INTERNAL_MakeMemoryUnavailable( static void VULKAN_INTERNAL_MakeMemoryUnavailable(
VulkanRenderer *renderer,
VulkanMemoryAllocation *allocation) VulkanMemoryAllocation *allocation)
{ {
Uint32 i, j; Uint32 i, j;
@@ -1371,7 +1341,6 @@ static void VULKAN_INTERNAL_MarkAllocationsForDefrag(
renderer->allocationsToDefragCount += 1; renderer->allocationsToDefragCount += 1;
VULKAN_INTERNAL_MakeMemoryUnavailable( VULKAN_INTERNAL_MakeMemoryUnavailable(
renderer,
currentAllocator->allocations[allocationIndex]); currentAllocator->allocations[allocationIndex]);
} }
} }
@@ -1787,8 +1756,6 @@ static void VULKAN_INTERNAL_DeallocateMemory(
static Uint8 VULKAN_INTERNAL_AllocateMemory( static Uint8 VULKAN_INTERNAL_AllocateMemory(
VulkanRenderer *renderer, VulkanRenderer *renderer,
VkBuffer buffer,
VkImage image,
Uint32 memoryTypeIndex, Uint32 memoryTypeIndex,
VkDeviceSize allocationSize, VkDeviceSize allocationSize,
Uint8 isHostVisible, Uint8 isHostVisible,
@@ -2069,8 +2036,6 @@ static Uint8 VULKAN_INTERNAL_BindResourceMemory(
allocationResult = VULKAN_INTERNAL_AllocateMemory( allocationResult = VULKAN_INTERNAL_AllocateMemory(
renderer, renderer,
buffer,
image,
memoryTypeIndex, memoryTypeIndex,
allocationSize, allocationSize,
isHostVisible, isHostVisible,
@@ -2367,24 +2332,6 @@ static Uint8 VULKAN_INTERNAL_BindMemoryForBuffer(
// Resource tracking // Resource tracking
#define ADD_TO_ARRAY_UNIQUE(resource, type, array, count, capacity) \
Uint32 i; \
\
for (i = 0; i < commandBuffer->count; i += 1) { \
if (commandBuffer->array[i] == resource) { \
return; \
} \
} \
\
if (commandBuffer->count == commandBuffer->capacity) { \
commandBuffer->capacity += 1; \
commandBuffer->array = SDL_realloc( \
commandBuffer->array, \
commandBuffer->capacity * sizeof(type)); \
} \
commandBuffer->array[commandBuffer->count] = resource; \
commandBuffer->count += 1;
#define TRACK_RESOURCE(resource, type, array, count, capacity) \ #define TRACK_RESOURCE(resource, type, array, count, capacity) \
for (Sint32 i = commandBuffer->count - 1; i >= 0; i -= 1) { \ for (Sint32 i = commandBuffer->count - 1; i >= 0; i -= 1) { \
if (commandBuffer->array[i] == resource) { \ if (commandBuffer->array[i] == resource) { \
@@ -2463,7 +2410,6 @@ static void VULKAN_INTERNAL_TrackComputePipeline(
} }
static void VULKAN_INTERNAL_TrackFramebuffer( static void VULKAN_INTERNAL_TrackFramebuffer(
VulkanRenderer *renderer,
VulkanCommandBuffer *commandBuffer, VulkanCommandBuffer *commandBuffer,
VulkanFramebuffer *framebuffer) VulkanFramebuffer *framebuffer)
{ {
@@ -5982,7 +5928,6 @@ static VulkanTextureSubresource *VULKAN_INTERNAL_PrepareTextureSubresourceForWri
static VkRenderPass VULKAN_INTERNAL_CreateRenderPass( static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
VulkanRenderer *renderer, VulkanRenderer *renderer,
VulkanCommandBuffer *commandBuffer,
const SDL_GPUColorTargetInfo *colorTargetInfos, const SDL_GPUColorTargetInfo *colorTargetInfos,
Uint32 numColorTargets, Uint32 numColorTargets,
const SDL_GPUDepthStencilTargetInfo *depthStencilTargetInfo) const SDL_GPUDepthStencilTargetInfo *depthStencilTargetInfo)
@@ -7041,7 +6986,6 @@ static void VULKAN_ReleaseGraphicsPipeline(
static VkRenderPass VULKAN_INTERNAL_FetchRenderPass( static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
VulkanRenderer *renderer, VulkanRenderer *renderer,
VulkanCommandBuffer *commandBuffer,
const SDL_GPUColorTargetInfo *colorTargetInfos, const SDL_GPUColorTargetInfo *colorTargetInfos,
Uint32 numColorTargets, Uint32 numColorTargets,
const SDL_GPUDepthStencilTargetInfo *depthStencilTargetInfo) const SDL_GPUDepthStencilTargetInfo *depthStencilTargetInfo)
@@ -7096,7 +7040,6 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
renderPassHandle = VULKAN_INTERNAL_CreateRenderPass( renderPassHandle = VULKAN_INTERNAL_CreateRenderPass(
renderer, renderer,
commandBuffer,
colorTargetInfos, colorTargetInfos,
numColorTargets, numColorTargets,
depthStencilTargetInfo); depthStencilTargetInfo);
@@ -7779,7 +7722,6 @@ static void VULKAN_BeginRenderPass(
renderPass = VULKAN_INTERNAL_FetchRenderPass( renderPass = VULKAN_INTERNAL_FetchRenderPass(
renderer, renderer,
vulkanCommandBuffer,
colorTargetInfos, colorTargetInfos,
numColorTargets, numColorTargets,
depthStencilTargetInfo); depthStencilTargetInfo);
@@ -7801,7 +7743,7 @@ static void VULKAN_BeginRenderPass(
return; return;
} }
VULKAN_INTERNAL_TrackFramebuffer(renderer, vulkanCommandBuffer, framebuffer); VULKAN_INTERNAL_TrackFramebuffer(vulkanCommandBuffer, framebuffer);
// Set clear values // Set clear values