Add SDL_CreateGPURenderer
This commit is contained in:
committed by
Sam Lantinga
parent
5a59b5f321
commit
f7b7188837
@@ -1187,6 +1187,37 @@ SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, const char *name)
|
||||
return renderer;
|
||||
}
|
||||
|
||||
SDL_Renderer *SDL_CreateGPURenderer(SDL_Window *window, SDL_GPUShaderFormat format_flags, SDL_GPUDevice **device)
|
||||
{
|
||||
if (!device) {
|
||||
SDL_InvalidParamError("device");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*device = NULL;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
SDL_PropertiesID props = SDL_CreateProperties();
|
||||
SDL_SetPointerProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, window);
|
||||
if (format_flags & SDL_GPU_SHADERFORMAT_SPIRV) {
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_RENDERER_CREATE_GPU_SHADERS_SPIRV_BOOLEAN, true);
|
||||
}
|
||||
if (format_flags & SDL_GPU_SHADERFORMAT_DXIL) {
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_RENDERER_CREATE_GPU_SHADERS_DXIL_BOOLEAN, true);
|
||||
}
|
||||
if (format_flags & SDL_GPU_SHADERFORMAT_MSL) {
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_RENDERER_CREATE_GPU_SHADERS_MSL_BOOLEAN, true);
|
||||
}
|
||||
SDL_SetStringProperty(props, SDL_PROP_RENDERER_CREATE_NAME_STRING, "gpu");
|
||||
|
||||
renderer = SDL_CreateRendererWithProperties(props);
|
||||
if (renderer) {
|
||||
*device = (SDL_GPUDevice *)SDL_GetPointerProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_GPU_DEVICE_POINTER, NULL);
|
||||
}
|
||||
SDL_DestroyProperties(props);
|
||||
return renderer;
|
||||
}
|
||||
|
||||
SDL_Renderer *SDL_CreateSoftwareRenderer(SDL_Surface *surface)
|
||||
{
|
||||
#ifdef SDL_VIDEO_RENDER_SW
|
||||
|
||||
@@ -1128,21 +1128,26 @@ static void GPU_DestroyRenderer(SDL_Renderer *renderer)
|
||||
}
|
||||
|
||||
for (Uint32 i = 0; i < SDL_arraysize(data->samplers); ++i) {
|
||||
SDL_ReleaseGPUSampler(data->device, data->samplers[i]);
|
||||
if (data->samplers[i]) {
|
||||
SDL_ReleaseGPUSampler(data->device, data->samplers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (data->backbuffer.texture) {
|
||||
SDL_ReleaseGPUTexture(data->device, data->backbuffer.texture);
|
||||
}
|
||||
|
||||
if (renderer->window) {
|
||||
if (renderer->window && data->device) {
|
||||
SDL_ReleaseWindowFromGPUDevice(data->device, renderer->window);
|
||||
}
|
||||
|
||||
ReleaseVertexBuffer(data);
|
||||
GPU_DestroyPipelineCache(&data->pipeline_cache);
|
||||
GPU_ReleaseShaders(&data->shaders, data->device);
|
||||
SDL_DestroyGPUDevice(data->device);
|
||||
|
||||
if (data->device) {
|
||||
GPU_ReleaseShaders(&data->shaders, data->device);
|
||||
SDL_DestroyGPUDevice(data->device);
|
||||
}
|
||||
|
||||
SDL_free(data);
|
||||
}
|
||||
|
||||
@@ -244,9 +244,24 @@ SDL_GPUShader *GPU_GetFragmentShader(GPU_Shaders *shaders, GPU_FragmentShaderID
|
||||
|
||||
void GPU_FillSupportedShaderFormats(SDL_PropertiesID props)
|
||||
{
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN, HAVE_SPIRV_SHADERS);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN, HAVE_DXIL60_SHADERS);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN, HAVE_METAL_SHADERS);
|
||||
bool custom_shaders = false;
|
||||
if (SDL_GetBooleanProperty(props, SDL_PROP_RENDERER_CREATE_GPU_SHADERS_SPIRV_BOOLEAN, false)) {
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN, HAVE_SPIRV_SHADERS);
|
||||
custom_shaders = true;
|
||||
}
|
||||
if (SDL_GetBooleanProperty(props, SDL_PROP_RENDERER_CREATE_GPU_SHADERS_DXIL_BOOLEAN, false)) {
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN, HAVE_DXIL60_SHADERS);
|
||||
custom_shaders = true;
|
||||
}
|
||||
if (SDL_GetBooleanProperty(props, SDL_PROP_RENDERER_CREATE_GPU_SHADERS_MSL_BOOLEAN, false)) {
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN, HAVE_METAL_SHADERS);
|
||||
custom_shaders = true;
|
||||
}
|
||||
if (!custom_shaders) {
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN, HAVE_SPIRV_SHADERS);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN, HAVE_DXIL60_SHADERS);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN, HAVE_METAL_SHADERS);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SDL_VIDEO_RENDER_GPU
|
||||
|
||||
Reference in New Issue
Block a user