Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 462c690

Browse files
authoredAug 8, 2024··
Remove HLSL shader format (#145)
1 parent b5dea93 commit 462c690

File tree

3 files changed

+17
-245
lines changed

3 files changed

+17
-245
lines changed
 

‎include/SDL3/SDL_gpu.h

-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ typedef enum SDL_GpuShaderFormat
195195
SDL_GPU_SHADERFORMAT_INVALID,
196196
SDL_GPU_SHADERFORMAT_SECRET, /* NDA'd platforms */
197197
SDL_GPU_SHADERFORMAT_SPIRV, /* Vulkan */
198-
SDL_GPU_SHADERFORMAT_HLSL, /* D3D11, D3D12 */
199198
SDL_GPU_SHADERFORMAT_DXBC, /* D3D11, D3D12 */
200199
SDL_GPU_SHADERFORMAT_DXIL, /* D3D12 */
201200
SDL_GPU_SHADERFORMAT_MSL, /* Metal */

‎src/gpu/d3d11/SDL_gpu_d3d11.c

+13-138
Original file line numberDiff line numberDiff line change
@@ -29,59 +29,12 @@
2929

3030
#include <d3d11.h>
3131
#include <d3d11_1.h>
32-
#include <d3dcompiler.h>
3332
#include <dxgi.h>
3433
#include <dxgi1_6.h>
3534
#include <dxgidebug.h>
3635

3736
#include "../SDL_sysgpu.h"
3837

39-
/* __stdcall declaration, largely taken from vkd3d_windows.h */
40-
#ifdef _WIN32
41-
#define D3DCOMPILER_API STDMETHODCALLTYPE
42-
#else
43-
#ifdef __stdcall
44-
#undef __stdcall
45-
#endif
46-
#ifdef __x86_64__
47-
#define __stdcall __attribute__((ms_abi))
48-
#else
49-
#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || defined(__APPLE__)
50-
#define __stdcall __attribute__((__stdcall__)) __attribute__((__force_align_arg_pointer__))
51-
#else
52-
#define __stdcall __attribute__((__stdcall__))
53-
#endif
54-
#endif
55-
#define D3DCOMPILER_API __stdcall
56-
#endif
57-
58-
/* vkd3d uses stdcall for its ID3D10Blob implementation */
59-
#ifndef _WIN32
60-
typedef struct VKD3DBlob VKD3DBlob;
61-
typedef struct VKD3DBlobVtbl
62-
{
63-
HRESULT(__stdcall *QueryInterface)
64-
(
65-
VKD3DBlob *This,
66-
REFIID riid,
67-
void **ppvObject);
68-
ULONG(__stdcall *AddRef)
69-
(VKD3DBlob *This);
70-
ULONG(__stdcall *Release)
71-
(VKD3DBlob *This);
72-
LPVOID(__stdcall *GetBufferPointer)
73-
(VKD3DBlob *This);
74-
SIZE_T(__stdcall *GetBufferSize)
75-
(VKD3DBlob *This);
76-
} VKD3DBlobVtbl;
77-
struct VKD3DBlob
78-
{
79-
const VKD3DBlobVtbl *lpVtbl;
80-
};
81-
#define ID3D10Blob VKD3DBlob
82-
#define ID3DBlob VKD3DBlob
83-
#endif
84-
8538
/* MinGW doesn't implement this yet */
8639
#ifdef _WIN32
8740
#define HAVE_IDXGIINFOQUEUE
@@ -90,7 +43,6 @@ struct VKD3DBlob
9043
/* Function Pointer Signatures */
9144
typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY1)(const GUID *riid, void **ppFactory);
9245
typedef HRESULT(WINAPI *PFN_DXGI_GET_DEBUG_INTERFACE)(const GUID *riid, void **ppDebug);
93-
typedef HRESULT(D3DCOMPILER_API *PFN_D3DCOMPILE)(LPCVOID pSrcData, SIZE_T SrcDataSize, LPCSTR pSourceName, const D3D_SHADER_MACRO *pDefines, ID3DInclude *pInclude, LPCSTR pEntrypoint, LPCSTR pTarget, UINT Flags1, UINT Flags2, ID3DBlob **ppCode, ID3DBlob **ppErrorMsgs);
9446

9547
/* IIDs (from https://www.magnumdb.com/) */
9648
static const IID D3D_IID_IDXGIFactory1 = { 0x770aae78, 0xf26f, 0x4dba, { 0xa8, 0x29, 0x25, 0x3c, 0x83, 0xd1, 0xb3, 0x87 } };
@@ -116,27 +68,18 @@ static const GUID D3D_IID_DXGI_DEBUG_ALL = { 0xe48ae283, 0xda80, 0x490b, { 0x87,
11668
#define D3D11_DLL "d3d11.dll"
11769
#define DXGI_DLL "dxgi.dll"
11870
#define DXGIDEBUG_DLL "dxgidebug.dll"
119-
120-
/* FIXME: Reuse the d3dcompiler loader in SDL_egl.c */
121-
#ifdef D3DCOMPILER_DLL
122-
#undef D3DCOMPILER_DLL
123-
#endif
124-
#define D3DCOMPILER_DLL "d3dcompiler_47.dll"
12571
#elif defined(__APPLE__)
12672
#define D3D11_DLL "libdxvk_d3d11.0.dylib"
12773
#define DXGI_DLL "libdxvk_dxgi.0.dylib"
12874
#define DXGIDEBUG_DLL "libdxvk_dxgidebug.0.dylib"
129-
#define D3DCOMPILER_DLL "libvkd3d-utils.1.dylib"
13075
#else
13176
#define D3D11_DLL "libdxvk_d3d11.so.0"
13277
#define DXGI_DLL "libdxvk_dxgi.so.0"
13378
#define DXGIDEBUG_DLL "libdxvk_dxgidebug.so.0"
134-
#define D3DCOMPILER_DLL "libvkd3d-utils.so.1"
13579
#endif
13680

13781
#define D3D11_CREATE_DEVICE_FUNC "D3D11CreateDevice"
13882
#define CREATE_DXGI_FACTORY1_FUNC "CreateDXGIFactory1"
139-
#define D3DCOMPILE_FUNC "D3DCompile"
14083
#define DXGI_GET_DEBUG_INTERFACE_FUNC "DXGIGetDebugInterface"
14184
#define WINDOW_PROPERTY_DATA "SDL_GpuD3D11WindowPropertyData"
14285

@@ -727,9 +670,6 @@ struct D3D11Renderer
727670
void *dxgi_dll;
728671
void *dxgidebug_dll;
729672

730-
void *d3dcompiler_dll;
731-
PFN_D3DCOMPILE D3DCompile_func;
732-
733673
Uint8 debugMode;
734674
BOOL supportsTearing;
735675
Uint8 supportsFlipDiscard;
@@ -1009,7 +949,6 @@ static void D3D11_DestroyDevice(
1009949
/* Release the DLLs */
1010950
SDL_UnloadObject(renderer->d3d11_dll);
1011951
SDL_UnloadObject(renderer->dxgi_dll);
1012-
SDL_UnloadObject(renderer->d3dcompiler_dll);
1013952
if (renderer->dxgidebug_dll) {
1014953
SDL_UnloadObject(renderer->dxgidebug_dll);
1015954
}
@@ -1463,38 +1402,10 @@ static ID3D11DeviceChild *D3D11_INTERNAL_CreateID3D11Shader(
14631402
void **pBytecode,
14641403
size_t *pBytecodeSize)
14651404
{
1466-
const char *profiles[3] = { "vs_5_0", "ps_5_0", "cs_5_0" };
1467-
ID3DBlob *blob = NULL;
1468-
ID3DBlob *errorBlob;
1469-
const Uint8 *bytecode;
1470-
size_t bytecodeSize;
14711405
ID3D11DeviceChild *handle = NULL;
14721406
HRESULT res;
14731407

1474-
if (format == SDL_GPU_SHADERFORMAT_HLSL) {
1475-
res = renderer->D3DCompile_func(
1476-
code,
1477-
codeSize,
1478-
NULL,
1479-
NULL,
1480-
NULL,
1481-
entryPointName,
1482-
profiles[stage],
1483-
0,
1484-
0,
1485-
&blob,
1486-
&errorBlob);
1487-
if (res < 0) {
1488-
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", (const char *)ID3D10Blob_GetBufferPointer(errorBlob));
1489-
ID3D10Blob_Release(errorBlob);
1490-
return NULL;
1491-
}
1492-
bytecode = ID3D10Blob_GetBufferPointer(blob);
1493-
bytecodeSize = ID3D10Blob_GetBufferSize(blob);
1494-
} else if (format == SDL_GPU_SHADERFORMAT_DXBC) {
1495-
bytecode = code;
1496-
bytecodeSize = codeSize;
1497-
} else {
1408+
if (format != SDL_GPU_SHADERFORMAT_DXBC) {
14981409
SDL_LogError(SDL_LOG_CATEGORY_GPU, "Incompatible shader format for D3D11");
14991410
return NULL;
15001411
}
@@ -1503,8 +1414,8 @@ static ID3D11DeviceChild *D3D11_INTERNAL_CreateID3D11Shader(
15031414
if (stage == SDL_GPU_SHADERSTAGE_VERTEX) {
15041415
res = ID3D11Device_CreateVertexShader(
15051416
renderer->device,
1506-
bytecode,
1507-
bytecodeSize,
1417+
code,
1418+
codeSize,
15081419
NULL,
15091420
(ID3D11VertexShader **)&handle);
15101421
if (FAILED(res)) {
@@ -1514,8 +1425,8 @@ static ID3D11DeviceChild *D3D11_INTERNAL_CreateID3D11Shader(
15141425
} else if (stage == SDL_GPU_SHADERSTAGE_FRAGMENT) {
15151426
res = ID3D11Device_CreatePixelShader(
15161427
renderer->device,
1517-
bytecode,
1518-
bytecodeSize,
1428+
code,
1429+
codeSize,
15191430
NULL,
15201431
(ID3D11PixelShader **)&handle);
15211432
if (FAILED(res)) {
@@ -1525,8 +1436,8 @@ static ID3D11DeviceChild *D3D11_INTERNAL_CreateID3D11Shader(
15251436
} else if (stage == SDL_GPU_SHADERSTAGE_COMPUTE) {
15261437
res = ID3D11Device_CreateComputeShader(
15271438
renderer->device,
1528-
bytecode,
1529-
bytecodeSize,
1439+
code,
1440+
codeSize,
15301441
NULL,
15311442
(ID3D11ComputeShader **)&handle);
15321443
if (FAILED(res)) {
@@ -1536,14 +1447,9 @@ static ID3D11DeviceChild *D3D11_INTERNAL_CreateID3D11Shader(
15361447
}
15371448

15381449
if (pBytecode != NULL) {
1539-
*pBytecode = SDL_malloc(bytecodeSize);
1540-
SDL_memcpy(*pBytecode, bytecode, bytecodeSize);
1541-
*pBytecodeSize = bytecodeSize;
1542-
}
1543-
1544-
/* Clean up */
1545-
if (blob) {
1546-
ID3D10Blob_Release(blob);
1450+
*pBytecode = SDL_malloc(codeSize);
1451+
SDL_memcpy(*pBytecode, code, codeSize);
1452+
*pBytecodeSize = codeSize;
15471453
}
15481454

15491455
return handle;
@@ -1886,8 +1792,8 @@ SDL_GpuShader *D3D11_CreateShader(
18861792
{
18871793
D3D11Renderer *renderer = (D3D11Renderer *)driverData;
18881794
ID3D11DeviceChild *handle;
1889-
void *bytecode;
1890-
size_t bytecodeSize;
1795+
void *bytecode = NULL;
1796+
size_t bytecodeSize = 0;
18911797
D3D11Shader *shader;
18921798

18931799
handle = D3D11_INTERNAL_CreateID3D11Shader(
@@ -5742,11 +5648,10 @@ static SDL_bool D3D11_IsTextureFormatSupported(
57425648

57435649
static SDL_bool D3D11_PrepareDriver(SDL_VideoDevice *_this)
57445650
{
5745-
void *d3d11_dll, *dxgi_dll, *d3dcompiler_dll;
5651+
void *d3d11_dll, *dxgi_dll;
57465652
PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc;
57475653
D3D_FEATURE_LEVEL levels[] = { D3D_FEATURE_LEVEL_11_1 };
57485654
PFN_CREATE_DXGI_FACTORY1 CreateDXGIFactoryFunc;
5749-
PFN_D3DCOMPILE D3DCompileFunc;
57505655
HRESULT res;
57515656

57525657
/* Can we load D3D11? */
@@ -5804,23 +5709,6 @@ static SDL_bool D3D11_PrepareDriver(SDL_VideoDevice *_this)
58045709
return SDL_FALSE;
58055710
}
58065711

5807-
/* Can we load D3DCompiler? */
5808-
5809-
d3dcompiler_dll = SDL_LoadObject(D3DCOMPILER_DLL);
5810-
if (d3dcompiler_dll == NULL) {
5811-
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "D3D11: Could not find " D3DCOMPILER_DLL);
5812-
return SDL_FALSE;
5813-
}
5814-
5815-
D3DCompileFunc = (PFN_D3DCOMPILE)SDL_LoadFunction(
5816-
d3dcompiler_dll,
5817-
D3DCOMPILE_FUNC);
5818-
SDL_UnloadObject(d3dcompiler_dll); /* We're not going to call this function, so we can just unload now. */
5819-
if (D3DCompileFunc == NULL) {
5820-
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "D3D11: Could not find function D3DCompile in " D3DCOMPILER_DLL);
5821-
return SDL_FALSE;
5822-
}
5823-
58245712
return SDL_TRUE;
58255713
}
58265714

@@ -6035,19 +5923,6 @@ static SDL_GpuDevice *D3D11_CreateDevice(SDL_bool debugMode, SDL_bool preferLowP
60355923
/* Allocate and zero out the renderer */
60365924
renderer = (D3D11Renderer *)SDL_calloc(1, sizeof(D3D11Renderer));
60375925

6038-
/* Load the D3DCompiler library */
6039-
renderer->d3dcompiler_dll = SDL_LoadObject(D3DCOMPILER_DLL);
6040-
if (renderer->d3dcompiler_dll == NULL) {
6041-
SDL_LogError(SDL_LOG_CATEGORY_GPU, "Could not find " D3DCOMPILER_DLL);
6042-
return NULL;
6043-
}
6044-
6045-
renderer->D3DCompile_func = (PFN_D3DCOMPILE)SDL_LoadFunction(renderer->d3dcompiler_dll, D3DCOMPILE_FUNC);
6046-
if (renderer->D3DCompile_func == NULL) {
6047-
SDL_LogError(SDL_LOG_CATEGORY_GPU, "Could not load function: " D3DCOMPILE_FUNC);
6048-
return NULL;
6049-
}
6050-
60515926
/* Load the DXGI library */
60525927
renderer->dxgi_dll = SDL_LoadObject(DXGI_DLL);
60535928
if (renderer->dxgi_dll == NULL) {

0 commit comments

Comments
 (0)