Skip to content

Commit

Permalink
GPU: Implement Legacy Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcosmonaut committed Nov 4, 2024
1 parent a54b4a1 commit e5c39d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/gpu/SDL_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,12 @@ static const SDL_GPUBootstrap * SDL_GPUSelectBackend(SDL_PropertiesID props)
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN, false)) {
format_flags |= SDL_GPU_SHADERFORMAT_SPIRV;
}
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN, false) && SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_LEGACYMODE_BOOLEAN, false)) {
format_flags |= SDL_GPU_SHADERFORMAT_DXBC;
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN, false)) {
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_LEGACYMODE_BOOLEAN, false)) {
format_flags |= SDL_GPU_SHADERFORMAT_DXBC;
} else {
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "%s", "DXBC is only supported in legacy mode but legacy mode is not enabled!");
}
}
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN, false)) {
format_flags |= SDL_GPU_SHADERFORMAT_DXIL;
Expand Down Expand Up @@ -458,9 +462,6 @@ static void SDL_GPU_FillProperties(
if (format_flags & SDL_GPU_SHADERFORMAT_SPIRV) {
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN, true);
}
if (format_flags & SDL_GPU_SHADERFORMAT_DXBC) {
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN, true);
}
if (format_flags & SDL_GPU_SHADERFORMAT_DXIL) {
SDL_SetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN, true);
}
Expand Down
26 changes: 23 additions & 3 deletions src/gpu/d3d11/SDL_gpu_d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -5954,7 +5954,7 @@ static bool D3D11_PrepareDriver(SDL_VideoDevice *this)
SDL_SharedObject *d3d11_dll;
SDL_SharedObject *dxgi_dll;
PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc;
D3D_FEATURE_LEVEL levels[] = { D3D_FEATURE_LEVEL_11_1 };
D3D_FEATURE_LEVEL levels[] = { D3D_FEATURE_LEVEL_11_0 };
PFN_CREATE_DXGI_FACTORY1 CreateDxgiFactoryFunc;
HRESULT res;

Expand Down Expand Up @@ -5992,7 +5992,7 @@ static bool D3D11_PrepareDriver(SDL_VideoDevice *this)
SDL_UnloadObject(d3d11_dll);

if (FAILED(res)) {
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "D3D11: Could not create D3D11Device with feature level 11_1");
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "D3D11: Could not create D3D11Device with feature level 11_0");
return false;
}

Expand Down Expand Up @@ -6288,7 +6288,7 @@ static SDL_GPUDevice *D3D11_CreateDevice(bool debugMode, bool preferLowPower, SD
D3D11Renderer *renderer;
PFN_CREATE_DXGI_FACTORY1 CreateDxgiFactoryFunc;
PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc;
D3D_FEATURE_LEVEL levels[] = { D3D_FEATURE_LEVEL_11_1 };
D3D_FEATURE_LEVEL levels[] = { D3D_FEATURE_LEVEL_11_0 };
IDXGIFactory4 *factory4;
IDXGIFactory5 *factory5;
IDXGIFactory6 *factory6;
Expand Down Expand Up @@ -6419,6 +6419,26 @@ static SDL_GPUDevice *D3D11_CreateDevice(bool debugMode, bool preferLowPower, SD

CHECK_D3D11_ERROR_AND_RETURN("Could not create D3D11 device", NULL);

// Check for constant buffer partial updates
D3D11_FEATURE_DATA_D3D11_OPTIONS options;
res = ID3D11Device_CheckFeatureSupport(
d3d11Device,
D3D11_FEATURE_D3D11_OPTIONS,
&options,
sizeof(D3D11_FEATURE_DATA_D3D11_OPTIONS));
if (FAILED(res)) {
D3D11_INTERNAL_SetError(renderer, "ID3D11Device_CheckFeatureSupport failed!", res);
ID3D11DeviceContext_Release(renderer->immediateContext);
ID3D11Device_Release(d3d11Device);
return NULL;
}

if (!options.ConstantBufferPartialUpdate || !options.ConstantBufferOffsetting) {
ID3D11DeviceContext_Release(renderer->immediateContext);
ID3D11Device_Release(d3d11Device);
SET_STRING_ERROR_AND_RETURN("Device does not support constant buffer partial update and offsetting!", NULL)
}

// The actual device we want is the ID3D11Device1 interface...
res = ID3D11Device_QueryInterface(
d3d11Device,
Expand Down

0 comments on commit e5c39d9

Please sign in to comment.