mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-05 19:08:12 +00:00
gpu: Clean up unused code in Vulkan and D3D12 drivers
This commit is contained in:

committed by
Caleb Cornett

parent
71c4de190c
commit
0e29c6295c
@@ -121,18 +121,6 @@
|
||||
|
||||
#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
|
||||
#define HRESULT_FMT "(0x%08lX)"
|
||||
#else
|
||||
@@ -1179,7 +1167,6 @@ static void D3D12_INTERNAL_SetError(
|
||||
// Release / Cleanup
|
||||
|
||||
static void D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
D3D12Renderer *renderer,
|
||||
D3D12StagingDescriptor *cpuDescriptor)
|
||||
{
|
||||
D3D12StagingDescriptorPool *pool = cpuDescriptor->pool;
|
||||
@@ -1193,7 +1180,6 @@ static void D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
}
|
||||
|
||||
static void D3D12_INTERNAL_DestroyBuffer(
|
||||
D3D12Renderer *renderer,
|
||||
D3D12Buffer *buffer)
|
||||
{
|
||||
if (!buffer) {
|
||||
@@ -1207,13 +1193,10 @@ static void D3D12_INTERNAL_DestroyBuffer(
|
||||
NULL);
|
||||
}
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&buffer->srvDescriptor);
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&buffer->uavDescriptor);
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&buffer->cbvDescriptor);
|
||||
|
||||
if (buffer->handle) {
|
||||
@@ -1264,7 +1247,6 @@ static void D3D12_INTERNAL_ReleaseBufferContainer(
|
||||
}
|
||||
|
||||
static void D3D12_INTERNAL_DestroyTexture(
|
||||
D3D12Renderer *renderer,
|
||||
D3D12Texture *texture)
|
||||
{
|
||||
if (!texture) {
|
||||
@@ -1275,24 +1257,20 @@ static void D3D12_INTERNAL_DestroyTexture(
|
||||
if (subresource->rtvHandles) {
|
||||
for (Uint32 depthIndex = 0; depthIndex < subresource->depth; depthIndex += 1) {
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&subresource->rtvHandles[depthIndex]);
|
||||
}
|
||||
SDL_free(subresource->rtvHandles);
|
||||
}
|
||||
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&subresource->uavHandle);
|
||||
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&subresource->dsvHandle);
|
||||
}
|
||||
SDL_free(texture->subresources);
|
||||
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&texture->srvHandle);
|
||||
|
||||
if (texture->resource) {
|
||||
@@ -1344,11 +1322,9 @@ static void D3D12_INTERNAL_ReleaseTextureContainer(
|
||||
}
|
||||
|
||||
static void D3D12_INTERNAL_DestroySampler(
|
||||
D3D12Renderer *renderer,
|
||||
D3D12Sampler *sampler)
|
||||
{
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&sampler->handle);
|
||||
|
||||
SDL_free(sampler);
|
||||
@@ -1503,7 +1479,6 @@ static void D3D12_INTERNAL_DestroyRenderer(D3D12Renderer *renderer)
|
||||
// Release uniform buffers
|
||||
for (Uint32 i = 0; i < renderer->uniformBufferPoolCount; i += 1) {
|
||||
D3D12_INTERNAL_DestroyBuffer(
|
||||
renderer,
|
||||
renderer->uniformBufferPool[i]->buffer);
|
||||
SDL_free(renderer->uniformBufferPool[i]);
|
||||
}
|
||||
@@ -2499,12 +2474,8 @@ static D3D12GraphicsRootSignature *D3D12_INTERNAL_CreateGraphicsRootSignature(
|
||||
}
|
||||
|
||||
static bool D3D12_INTERNAL_CreateShaderBytecode(
|
||||
D3D12Renderer *renderer,
|
||||
Uint32 stage,
|
||||
SDL_GPUShaderFormat format,
|
||||
const Uint8 *code,
|
||||
size_t codeSize,
|
||||
const char *entrypointName,
|
||||
void **pBytecode,
|
||||
size_t *pBytecodeSize)
|
||||
{
|
||||
@@ -2725,12 +2696,8 @@ static SDL_GPUComputePipeline *D3D12_CreateComputePipeline(
|
||||
ID3D12PipelineState *pipelineState;
|
||||
|
||||
if (!D3D12_INTERNAL_CreateShaderBytecode(
|
||||
renderer,
|
||||
SDL_GPU_SHADERSTAGE_COMPUTE,
|
||||
createinfo->format,
|
||||
createinfo->code,
|
||||
createinfo->code_size,
|
||||
createinfo->entrypoint,
|
||||
&bytecode,
|
||||
&bytecodeSize)) {
|
||||
return NULL;
|
||||
@@ -3137,18 +3104,13 @@ static SDL_GPUShader *D3D12_CreateShader(
|
||||
SDL_GPURenderer *driverData,
|
||||
const SDL_GPUShaderCreateInfo *createinfo)
|
||||
{
|
||||
D3D12Renderer *renderer = (D3D12Renderer *)driverData;
|
||||
void *bytecode;
|
||||
size_t bytecodeSize;
|
||||
D3D12Shader *shader;
|
||||
|
||||
if (!D3D12_INTERNAL_CreateShaderBytecode(
|
||||
renderer,
|
||||
createinfo->stage,
|
||||
createinfo->format,
|
||||
createinfo->code,
|
||||
createinfo->code_size,
|
||||
createinfo->entrypoint,
|
||||
&bytecode,
|
||||
&bytecodeSize)) {
|
||||
return NULL;
|
||||
@@ -3273,7 +3235,7 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
|
||||
(void **)&handle);
|
||||
if (FAILED(res)) {
|
||||
D3D12_INTERNAL_SetError(renderer, "Failed to create texture!", res);
|
||||
D3D12_INTERNAL_DestroyTexture(renderer, texture);
|
||||
D3D12_INTERNAL_DestroyTexture(texture);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -3339,7 +3301,7 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
|
||||
texture->subresources = (D3D12TextureSubresource *)SDL_calloc(
|
||||
texture->subresourceCount, sizeof(D3D12TextureSubresource));
|
||||
if (!texture->subresources) {
|
||||
D3D12_INTERNAL_DestroyTexture(renderer, texture);
|
||||
D3D12_INTERNAL_DestroyTexture(texture);
|
||||
return NULL;
|
||||
}
|
||||
for (Uint32 layerIndex = 0; layerIndex < layerCount; layerIndex += 1) {
|
||||
@@ -3617,7 +3579,7 @@ static D3D12Buffer *D3D12_INTERNAL_CreateBuffer(
|
||||
(void **)&handle);
|
||||
if (FAILED(res)) {
|
||||
D3D12_INTERNAL_SetError(renderer, "Could not create buffer!", res);
|
||||
D3D12_INTERNAL_DestroyBuffer(renderer, buffer);
|
||||
D3D12_INTERNAL_DestroyBuffer(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -3707,7 +3669,7 @@ static D3D12Buffer *D3D12_INTERNAL_CreateBuffer(
|
||||
(void **)&buffer->mapPointer);
|
||||
if (FAILED(res)) {
|
||||
D3D12_INTERNAL_SetError(renderer, "Failed to map upload buffer!", res);
|
||||
D3D12_INTERNAL_DestroyBuffer(renderer, buffer);
|
||||
D3D12_INTERNAL_DestroyBuffer(buffer);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -6633,10 +6595,8 @@ static bool D3D12_INTERNAL_ResizeSwapchain(
|
||||
// Release views and clean up
|
||||
for (Uint32 i = 0; i < windowData->swapchainTextureCount; i += 1) {
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&windowData->textureContainers[i].activeTexture->srvHandle);
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles[0]);
|
||||
|
||||
SDL_free(windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles);
|
||||
@@ -6684,10 +6644,8 @@ static void D3D12_INTERNAL_DestroySwapchain(
|
||||
// Release views and clean up
|
||||
for (Uint32 i = 0; i < windowData->swapchainTextureCount; i += 1) {
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&windowData->textureContainers[i].activeTexture->srvHandle);
|
||||
D3D12_INTERNAL_ReleaseStagingDescriptorHandle(
|
||||
renderer,
|
||||
&windowData->textureContainers[i].activeTexture->subresources[0].rtvHandles[0]);
|
||||
|
||||
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) {
|
||||
if (SDL_GetAtomicInt(&renderer->buffersToDestroy[i]->referenceCount) == 0) {
|
||||
D3D12_INTERNAL_DestroyBuffer(
|
||||
renderer,
|
||||
renderer->buffersToDestroy[i]);
|
||||
|
||||
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) {
|
||||
if (SDL_GetAtomicInt(&renderer->texturesToDestroy[i]->referenceCount) == 0) {
|
||||
D3D12_INTERNAL_DestroyTexture(
|
||||
renderer,
|
||||
renderer->texturesToDestroy[i]);
|
||||
|
||||
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) {
|
||||
if (SDL_GetAtomicInt(&renderer->samplersToDestroy[i]->referenceCount) == 0) {
|
||||
D3D12_INTERNAL_DestroySampler(
|
||||
renderer,
|
||||
renderer->samplersToDestroy[i]);
|
||||
|
||||
renderer->samplersToDestroy[i] = renderer->samplersToDestroy[renderer->samplersToDestroyCount - 1];
|
||||
|
@@ -33,8 +33,6 @@
|
||||
|
||||
#include "../SDL_sysgpu.h"
|
||||
|
||||
#define VULKAN_INTERNAL_clamp(val, min, max) SDL_max(min, SDL_min(val, max))
|
||||
|
||||
// Global Vulkan Loader Entry Points
|
||||
|
||||
static PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
|
||||
@@ -79,33 +77,6 @@ typedef struct VulkanExtensions
|
||||
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
|
||||
|
||||
static const Uint8 DEVICE_PRIORITY_HIGHPERFORMANCE[] = {
|
||||
@@ -1321,7 +1292,6 @@ static inline Uint32 VULKAN_INTERNAL_NextHighestAlignment32(
|
||||
}
|
||||
|
||||
static void VULKAN_INTERNAL_MakeMemoryUnavailable(
|
||||
VulkanRenderer *renderer,
|
||||
VulkanMemoryAllocation *allocation)
|
||||
{
|
||||
Uint32 i, j;
|
||||
@@ -1371,7 +1341,6 @@ static void VULKAN_INTERNAL_MarkAllocationsForDefrag(
|
||||
renderer->allocationsToDefragCount += 1;
|
||||
|
||||
VULKAN_INTERNAL_MakeMemoryUnavailable(
|
||||
renderer,
|
||||
currentAllocator->allocations[allocationIndex]);
|
||||
}
|
||||
}
|
||||
@@ -1787,8 +1756,6 @@ static void VULKAN_INTERNAL_DeallocateMemory(
|
||||
|
||||
static Uint8 VULKAN_INTERNAL_AllocateMemory(
|
||||
VulkanRenderer *renderer,
|
||||
VkBuffer buffer,
|
||||
VkImage image,
|
||||
Uint32 memoryTypeIndex,
|
||||
VkDeviceSize allocationSize,
|
||||
Uint8 isHostVisible,
|
||||
@@ -2069,8 +2036,6 @@ static Uint8 VULKAN_INTERNAL_BindResourceMemory(
|
||||
|
||||
allocationResult = VULKAN_INTERNAL_AllocateMemory(
|
||||
renderer,
|
||||
buffer,
|
||||
image,
|
||||
memoryTypeIndex,
|
||||
allocationSize,
|
||||
isHostVisible,
|
||||
@@ -2367,24 +2332,6 @@ static Uint8 VULKAN_INTERNAL_BindMemoryForBuffer(
|
||||
|
||||
// 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) \
|
||||
for (Sint32 i = commandBuffer->count - 1; i >= 0; i -= 1) { \
|
||||
if (commandBuffer->array[i] == resource) { \
|
||||
@@ -2463,7 +2410,6 @@ static void VULKAN_INTERNAL_TrackComputePipeline(
|
||||
}
|
||||
|
||||
static void VULKAN_INTERNAL_TrackFramebuffer(
|
||||
VulkanRenderer *renderer,
|
||||
VulkanCommandBuffer *commandBuffer,
|
||||
VulkanFramebuffer *framebuffer)
|
||||
{
|
||||
@@ -5982,7 +5928,6 @@ static VulkanTextureSubresource *VULKAN_INTERNAL_PrepareTextureSubresourceForWri
|
||||
|
||||
static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
||||
VulkanRenderer *renderer,
|
||||
VulkanCommandBuffer *commandBuffer,
|
||||
const SDL_GPUColorTargetInfo *colorTargetInfos,
|
||||
Uint32 numColorTargets,
|
||||
const SDL_GPUDepthStencilTargetInfo *depthStencilTargetInfo)
|
||||
@@ -7041,7 +6986,6 @@ static void VULKAN_ReleaseGraphicsPipeline(
|
||||
|
||||
static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
|
||||
VulkanRenderer *renderer,
|
||||
VulkanCommandBuffer *commandBuffer,
|
||||
const SDL_GPUColorTargetInfo *colorTargetInfos,
|
||||
Uint32 numColorTargets,
|
||||
const SDL_GPUDepthStencilTargetInfo *depthStencilTargetInfo)
|
||||
@@ -7096,7 +7040,6 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
|
||||
|
||||
renderPassHandle = VULKAN_INTERNAL_CreateRenderPass(
|
||||
renderer,
|
||||
commandBuffer,
|
||||
colorTargetInfos,
|
||||
numColorTargets,
|
||||
depthStencilTargetInfo);
|
||||
@@ -7779,7 +7722,6 @@ static void VULKAN_BeginRenderPass(
|
||||
|
||||
renderPass = VULKAN_INTERNAL_FetchRenderPass(
|
||||
renderer,
|
||||
vulkanCommandBuffer,
|
||||
colorTargetInfos,
|
||||
numColorTargets,
|
||||
depthStencilTargetInfo);
|
||||
@@ -7801,7 +7743,7 @@ static void VULKAN_BeginRenderPass(
|
||||
return;
|
||||
}
|
||||
|
||||
VULKAN_INTERNAL_TrackFramebuffer(renderer, vulkanCommandBuffer, framebuffer);
|
||||
VULKAN_INTERNAL_TrackFramebuffer(vulkanCommandBuffer, framebuffer);
|
||||
|
||||
// Set clear values
|
||||
|
||||
|
Reference in New Issue
Block a user