GPU: Zero-init handling (#10786)

This commit is contained in:
Evan Hemsley 2024-09-10 18:17:08 -07:00 committed by GitHub
parent b8dbc7086d
commit 0b6f993dea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 310 additions and 88 deletions

View file

@ -79,20 +79,50 @@
return; \
}
#define CHECK_TEXTUREFORMAT_ENUM_INVALID(format, retval) \
if (format >= SDL_GPU_TEXTUREFORMAT_MAX) { \
#define CHECK_TEXTUREFORMAT_ENUM_INVALID(enumval, retval) \
if (enumval <= SDL_GPU_TEXTUREFORMAT_INVALID || enumval >= SDL_GPU_TEXTUREFORMAT_MAX_ENUM_VALUE) { \
SDL_assert_release(!"Invalid texture format enum!"); \
return retval; \
}
#define CHECK_VERTEXELEMENTFORMAT_ENUM_INVALID(enumval, retval) \
if (enumval <= SDL_GPU_VERTEXELEMENTFORMAT_INVALID || enumval >= SDL_GPU_VERTEXELEMENTFORMAT_MAX_ENUM_VALUE) { \
SDL_assert_release(!"Invalid vertex format enum!"); \
return retval; \
}
#define CHECK_COMPAREOP_ENUM_INVALID(enumval, retval) \
if (enumval <= SDL_GPU_COMPAREOP_INVALID || enumval >= SDL_GPU_COMPAREOP_MAX_ENUM_VALUE) { \
SDL_assert_release(!"Invalid compare op enum!"); \
return retval; \
}
#define CHECK_STENCILOP_ENUM_INVALID(enumval, retval) \
if (enumval <= SDL_GPU_STENCILOP_INVALID || enumval >= SDL_GPU_STENCILOP_MAX_ENUM_VALUE) { \
SDL_assert_release(!"Invalid stencil op enum!"); \
return retval; \
}
#define CHECK_BLENDOP_ENUM_INVALID(enumval, retval) \
if (enumval <= SDL_GPU_BLENDOP_INVALID || enumval >= SDL_GPU_BLENDOP_MAX_ENUM_VALUE) { \
SDL_assert_release(!"Invalid blend op enum!"); \
return retval; \
}
#define CHECK_BLENDFACTOR_ENUM_INVALID(enumval, retval) \
if (enumval <= SDL_GPU_BLENDFACTOR_INVALID || enumval >= SDL_GPU_BLENDFACTOR_MAX_ENUM_VALUE) { \
SDL_assert_release(!"Invalid blend factor enum!"); \
return retval; \
}
#define CHECK_SWAPCHAINCOMPOSITION_ENUM_INVALID(enumval, retval) \
if (enumval >= SDL_GPU_SWAPCHAINCOMPOSITION_MAX) { \
if (enumval < 0 || enumval >= SDL_GPU_SWAPCHAINCOMPOSITION_MAX_ENUM_VALUE) { \
SDL_assert_release(!"Invalid swapchain composition enum!"); \
return retval; \
}
#define CHECK_PRESENTMODE_ENUM_INVALID(enumval, retval) \
if (enumval >= SDL_GPU_PRESENTMODE_MAX) { \
if (enumval < 0 || enumval >= SDL_GPU_PRESENTMODE_MAX_ENUM_VALUE) { \
SDL_assert_release(!"Invalid present mode enum!"); \
return retval; \
}
@ -190,7 +220,7 @@ SDL_GPUGraphicsPipeline *SDL_GPU_FetchBlitPipeline(
}
blit_pipeline_create_info.multisample_state.sample_count = SDL_GPU_SAMPLECOUNT_1;
blit_pipeline_create_info.multisample_state.sample_mask = 0xFFFFFFFF;
blit_pipeline_create_info.multisample_state.enable_mask = SDL_FALSE;
blit_pipeline_create_info.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
@ -590,11 +620,14 @@ SDL_GPUComputePipeline *SDL_CreateGPUComputePipeline(
}
if (device->debug_mode) {
if (createinfo->format == SDL_GPU_SHADERFORMAT_INVALID) {
SDL_assert_release(!"Shader format cannot be INVALID!");
return NULL;
}
if (!(createinfo->format & device->shader_formats)) {
SDL_assert_release(!"Incompatible shader format for GPU backend");
return NULL;
}
if (createinfo->num_writeonly_storage_textures > MAX_COMPUTE_WRITE_TEXTURES) {
SDL_assert_release(!"Compute pipeline write-only texture count cannot be higher than 8!");
return NULL;
@ -627,12 +660,25 @@ SDL_GPUGraphicsPipeline *SDL_CreateGPUGraphicsPipeline(
}
if (device->debug_mode) {
if (graphicsPipelineCreateInfo->target_info.num_color_targets > 0 && graphicsPipelineCreateInfo->target_info.color_target_descriptions == NULL) {
SDL_assert_release(!"Color target descriptions array pointer cannot be NULL if num_color_targets is greater than zero!");
return NULL;
}
for (Uint32 i = 0; i < graphicsPipelineCreateInfo->target_info.num_color_targets; i += 1) {
CHECK_TEXTUREFORMAT_ENUM_INVALID(graphicsPipelineCreateInfo->target_info.color_target_descriptions[i].format, NULL);
if (IsDepthFormat(graphicsPipelineCreateInfo->target_info.color_target_descriptions[i].format)) {
SDL_assert_release(!"Color target formats cannot be a depth format!");
return NULL;
}
if (graphicsPipelineCreateInfo->target_info.color_target_descriptions[i].blend_state.enable_blend) {
const SDL_GPUColorTargetBlendState *blend_state = &graphicsPipelineCreateInfo->target_info.color_target_descriptions[i].blend_state;
CHECK_BLENDFACTOR_ENUM_INVALID(blend_state->src_color_blendfactor, NULL)
CHECK_BLENDFACTOR_ENUM_INVALID(blend_state->dst_color_blendfactor, NULL)
CHECK_BLENDOP_ENUM_INVALID(blend_state->color_blend_op, NULL)
CHECK_BLENDFACTOR_ENUM_INVALID(blend_state->src_alpha_blendfactor, NULL)
CHECK_BLENDFACTOR_ENUM_INVALID(blend_state->dst_alpha_blendfactor, NULL)
CHECK_BLENDOP_ENUM_INVALID(blend_state->alpha_blend_op, NULL)
}
}
if (graphicsPipelineCreateInfo->target_info.has_depth_stencil_target) {
CHECK_TEXTUREFORMAT_ENUM_INVALID(graphicsPipelineCreateInfo->target_info.depth_stencil_format, NULL);
@ -641,6 +687,27 @@ SDL_GPUGraphicsPipeline *SDL_CreateGPUGraphicsPipeline(
return NULL;
}
}
if (graphicsPipelineCreateInfo->vertex_input_state.num_vertex_bindings > 0 && graphicsPipelineCreateInfo->vertex_input_state.vertex_bindings == NULL) {
SDL_assert_release(!"Vertex bindings array pointer cannot be NULL!");
return NULL;
}
if (graphicsPipelineCreateInfo->vertex_input_state.num_vertex_attributes > 0 && graphicsPipelineCreateInfo->vertex_input_state.vertex_attributes == NULL) {
SDL_assert_release(!"Vertex attributes array pointer cannot be NULL!");
return NULL;
}
for (Uint32 i = 0; i < graphicsPipelineCreateInfo->vertex_input_state.num_vertex_attributes; i += 1) {
CHECK_VERTEXELEMENTFORMAT_ENUM_INVALID(graphicsPipelineCreateInfo->vertex_input_state.vertex_attributes[i].format, NULL);
}
if (graphicsPipelineCreateInfo->depth_stencil_state.enable_depth_test) {
CHECK_COMPAREOP_ENUM_INVALID(graphicsPipelineCreateInfo->depth_stencil_state.compare_op, NULL)
}
if (graphicsPipelineCreateInfo->depth_stencil_state.enable_stencil_test) {
const SDL_GPUStencilOpState *stencil_state = &graphicsPipelineCreateInfo->depth_stencil_state.back_stencil_state;
CHECK_COMPAREOP_ENUM_INVALID(stencil_state->compare_op, NULL)
CHECK_STENCILOP_ENUM_INVALID(stencil_state->fail_op, NULL)
CHECK_STENCILOP_ENUM_INVALID(stencil_state->pass_op, NULL)
CHECK_STENCILOP_ENUM_INVALID(stencil_state->depth_fail_op, NULL)
}
}
return device->CreateGraphicsPipeline(
@ -674,6 +741,10 @@ SDL_GPUShader *SDL_CreateGPUShader(
}
if (device->debug_mode) {
if (createinfo->format == SDL_GPU_SHADERFORMAT_INVALID) {
SDL_assert_release(!"Shader format cannot be INVALID!");
return NULL;
}
if (!(createinfo->format & device->shader_formats)) {
SDL_assert_release(!"Incompatible shader format for GPU backend");
return NULL;
@ -1909,6 +1980,14 @@ void SDL_UploadToGPUTexture(
if (COPYPASS_DEVICE->debug_mode) {
CHECK_COPYPASS
if (source->transfer_buffer == NULL) {
SDL_assert_release(!"Source transfer buffer cannot be NULL!");
return;
}
if (destination->texture == NULL) {
SDL_assert_release(!"Destination texture cannot be NULL!");
return;
}
}
COPYPASS_DEVICE->UploadToTexture(
@ -1937,6 +2016,18 @@ void SDL_UploadToGPUBuffer(
return;
}
if (COPYPASS_DEVICE->debug_mode) {
CHECK_COPYPASS
if (source->transfer_buffer == NULL) {
SDL_assert_release(!"Source transfer buffer cannot be NULL!");
return;
}
if (destination->buffer == NULL) {
SDL_assert_release(!"Destination buffer cannot be NULL!");
return;
}
}
COPYPASS_DEVICE->UploadToBuffer(
COPYPASS_COMMAND_BUFFER,
source,
@ -1966,6 +2057,18 @@ void SDL_CopyGPUTextureToTexture(
return;
}
if (COPYPASS_DEVICE->debug_mode) {
CHECK_COPYPASS
if (source->texture == NULL) {
SDL_assert_release(!"Source texture cannot be NULL!");
return;
}
if (destination->texture == NULL) {
SDL_assert_release(!"Destination texture cannot be NULL!");
return;
}
}
COPYPASS_DEVICE->CopyTextureToTexture(
COPYPASS_COMMAND_BUFFER,
source,
@ -1996,6 +2099,18 @@ void SDL_CopyGPUBufferToBuffer(
return;
}
if (COPYPASS_DEVICE->debug_mode) {
CHECK_COPYPASS
if (source->buffer == NULL) {
SDL_assert_release(!"Source buffer cannot be NULL!");
return;
}
if (destination->buffer == NULL) {
SDL_assert_release(!"Destination buffer cannot be NULL!");
return;
}
}
COPYPASS_DEVICE->CopyBufferToBuffer(
COPYPASS_COMMAND_BUFFER,
source,
@ -2022,6 +2137,18 @@ void SDL_DownloadFromGPUTexture(
return;
}
if (COPYPASS_DEVICE->debug_mode) {
CHECK_COPYPASS
if (source->texture == NULL) {
SDL_assert_release(!"Source texture cannot be NULL!");
return;
}
if (destination->transfer_buffer == NULL) {
SDL_assert_release(!"Destination transfer buffer cannot be NULL!");
return;
}
}
COPYPASS_DEVICE->DownloadFromTexture(
COPYPASS_COMMAND_BUFFER,
source,
@ -2046,6 +2173,18 @@ void SDL_DownloadFromGPUBuffer(
return;
}
if (COPYPASS_DEVICE->debug_mode) {
CHECK_COPYPASS
if (source->buffer == NULL) {
SDL_assert_release(!"Source buffer cannot be NULL!");
return;
}
if (destination->transfer_buffer == NULL) {
SDL_assert_release(!"Destination transfer buffer cannot be NULL!");
return;
}
}
COPYPASS_DEVICE->DownloadFromBuffer(
COPYPASS_COMMAND_BUFFER,
source,