mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-04 17:06:25 +00:00
Generalize and validate optional GPU feature properties
Fixes https://github.com/libsdl-org/SDL/issues/13139 Fixes https://github.com/libsdl-org/SDL/issues/13138
This commit is contained in:
@@ -719,6 +719,9 @@ SDL_GPUDevice *SDL_CreateGPUDeviceWithProperties(SDL_PropertiesID props)
|
||||
if (result != NULL) {
|
||||
result->backend = selectedBackend->name;
|
||||
result->debug_mode = debug_mode;
|
||||
result->validate_feature_depth_clamp_disabled = !SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_DEPTH_CLAMPING_BOOLEAN, true);
|
||||
result->validate_feature_indirect_draw_first_instance_disabled = !SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_INDIRECT_DRAW_FIRST_INSTANCE_BOOLEAN, true);
|
||||
result->validate_feature_anisotropy_disabled = !SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_ANISOTROPY_BOOLEAN, true);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -1104,6 +1107,12 @@ SDL_GPUGraphicsPipeline *SDL_CreateGPUGraphicsPipeline(
|
||||
CHECK_STENCILOP_ENUM_INVALID(stencil_state->pass_op, NULL)
|
||||
CHECK_STENCILOP_ENUM_INVALID(stencil_state->depth_fail_op, NULL)
|
||||
}
|
||||
|
||||
if (device->validate_feature_depth_clamp_disabled &&
|
||||
!graphicsPipelineCreateInfo->rasterizer_state.enable_depth_clip) {
|
||||
SDL_assert_release(!"Rasterizer state enable_depth_clip must be set to true (FEATURE_DEPTH_CLAMPING disabled)");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return device->CreateGraphicsPipeline(
|
||||
@@ -1122,6 +1131,14 @@ SDL_GPUSampler *SDL_CreateGPUSampler(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (device->debug_mode) {
|
||||
if (device->validate_feature_anisotropy_disabled &&
|
||||
createinfo->enable_anisotropy) {
|
||||
SDL_assert_release(!"enable_anisotropy must be set to false (FEATURE_ANISOTROPY disabled)");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return device->CreateSampler(
|
||||
device->driverData,
|
||||
createinfo);
|
||||
@@ -2164,6 +2181,11 @@ void SDL_DrawGPUIndexedPrimitives(
|
||||
CHECK_RENDERPASS
|
||||
CHECK_GRAPHICS_PIPELINE_BOUND
|
||||
SDL_GPU_CheckGraphicsBindings(render_pass);
|
||||
if (RENDERPASS_DEVICE->validate_feature_indirect_draw_first_instance_disabled &&
|
||||
first_instance != 0) {
|
||||
SDL_assert_release(!"first_instance must be 0 (FEATURE_INDIRECT_DRAW_FIRST_INSTANCE disabled)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
RENDERPASS_DEVICE->DrawIndexedPrimitives(
|
||||
@@ -2191,6 +2213,11 @@ void SDL_DrawGPUPrimitives(
|
||||
CHECK_RENDERPASS
|
||||
CHECK_GRAPHICS_PIPELINE_BOUND
|
||||
SDL_GPU_CheckGraphicsBindings(render_pass);
|
||||
if (RENDERPASS_DEVICE->validate_feature_indirect_draw_first_instance_disabled &&
|
||||
first_instance != 0) {
|
||||
SDL_assert_release(!"first_instance must be 0 (FEATURE_INDIRECT_DRAW_FIRST_INSTANCE disabled)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
RENDERPASS_DEVICE->DrawPrimitives(
|
||||
|
@@ -1096,6 +1096,9 @@ struct SDL_GPUDevice
|
||||
|
||||
// Store this for SDL_gpu.c's debug layer
|
||||
bool debug_mode;
|
||||
bool validate_feature_depth_clamp_disabled;
|
||||
bool validate_feature_indirect_draw_first_instance_disabled;
|
||||
bool validate_feature_anisotropy_disabled;
|
||||
};
|
||||
|
||||
#define ASSIGN_DRIVER_FUNC(func, name) \
|
||||
|
@@ -11739,10 +11739,10 @@ static bool VULKAN_PrepareDriver(SDL_VideoDevice *_this, SDL_PropertiesID props)
|
||||
renderer = (VulkanRenderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer) {
|
||||
// Opt out device features (higher compatibility in exchange for reduced functionality)
|
||||
renderer->desiredDeviceFeatures.samplerAnisotropy = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_VULKAN_SAMPLERANISOTROPY_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.depthClamp = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_VULKAN_DEPTHCLAMP_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.shaderClipDistance = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_VULKAN_SHADERCLIPDISTANCE_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.drawIndirectFirstInstance = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_VULKAN_DRAWINDIRECTFIRST_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.samplerAnisotropy = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_ANISOTROPY_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.depthClamp = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_DEPTH_CLAMPING_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.shaderClipDistance = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_CLIP_DISTANCE_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.drawIndirectFirstInstance = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_INDIRECT_DRAW_FIRST_INSTANCE_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
|
||||
// These features have near universal support so they are always enabled
|
||||
renderer->desiredDeviceFeatures.independentBlend = VK_TRUE;
|
||||
@@ -11788,10 +11788,10 @@ static SDL_GPUDevice *VULKAN_CreateDevice(bool debugMode, bool preferLowPower, S
|
||||
renderer->allowedFramesInFlight = 2;
|
||||
|
||||
// Opt out device features (higher compatibility in exchange for reduced functionality)
|
||||
renderer->desiredDeviceFeatures.samplerAnisotropy = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_VULKAN_SAMPLERANISOTROPY_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.depthClamp = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_VULKAN_DEPTHCLAMP_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.shaderClipDistance = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_VULKAN_SHADERCLIPDISTANCE_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.drawIndirectFirstInstance = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_VULKAN_DRAWINDIRECTFIRST_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.samplerAnisotropy = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_ANISOTROPY_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.depthClamp = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_DEPTH_CLAMPING_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.shaderClipDistance = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_CLIP_DISTANCE_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
renderer->desiredDeviceFeatures.drawIndirectFirstInstance = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_FEATURE_INDIRECT_DRAW_FIRST_INSTANCE_BOOLEAN, true) ? VK_TRUE : VK_FALSE;
|
||||
|
||||
// These features have near universal support so they are always enabled
|
||||
renderer->desiredDeviceFeatures.independentBlend = VK_TRUE;
|
||||
|
Reference in New Issue
Block a user