29
29
30
30
#include <d3d11.h>
31
31
#include <d3d11_1.h>
32
- #include <d3dcompiler.h>
33
32
#include <dxgi.h>
34
33
#include <dxgi1_6.h>
35
34
#include <dxgidebug.h>
36
35
37
36
#include "../SDL_sysgpu.h"
38
37
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
-
85
38
/* MinGW doesn't implement this yet */
86
39
#ifdef _WIN32
87
40
#define HAVE_IDXGIINFOQUEUE
@@ -90,7 +43,6 @@ struct VKD3DBlob
90
43
/* Function Pointer Signatures */
91
44
typedef HRESULT (WINAPI * PFN_CREATE_DXGI_FACTORY1 )(const GUID * riid , void * * ppFactory );
92
45
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 );
94
46
95
47
/* IIDs (from https://www.magnumdb.com/) */
96
48
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,
116
68
#define D3D11_DLL "d3d11.dll"
117
69
#define DXGI_DLL "dxgi.dll"
118
70
#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"
125
71
#elif defined(__APPLE__ )
126
72
#define D3D11_DLL "libdxvk_d3d11.0.dylib"
127
73
#define DXGI_DLL "libdxvk_dxgi.0.dylib"
128
74
#define DXGIDEBUG_DLL "libdxvk_dxgidebug.0.dylib"
129
- #define D3DCOMPILER_DLL "libvkd3d-utils.1.dylib"
130
75
#else
131
76
#define D3D11_DLL "libdxvk_d3d11.so.0"
132
77
#define DXGI_DLL "libdxvk_dxgi.so.0"
133
78
#define DXGIDEBUG_DLL "libdxvk_dxgidebug.so.0"
134
- #define D3DCOMPILER_DLL "libvkd3d-utils.so.1"
135
79
#endif
136
80
137
81
#define D3D11_CREATE_DEVICE_FUNC "D3D11CreateDevice"
138
82
#define CREATE_DXGI_FACTORY1_FUNC "CreateDXGIFactory1"
139
- #define D3DCOMPILE_FUNC "D3DCompile"
140
83
#define DXGI_GET_DEBUG_INTERFACE_FUNC "DXGIGetDebugInterface"
141
84
#define WINDOW_PROPERTY_DATA "SDL_GpuD3D11WindowPropertyData"
142
85
@@ -727,9 +670,6 @@ struct D3D11Renderer
727
670
void * dxgi_dll ;
728
671
void * dxgidebug_dll ;
729
672
730
- void * d3dcompiler_dll ;
731
- PFN_D3DCOMPILE D3DCompile_func ;
732
-
733
673
Uint8 debugMode ;
734
674
BOOL supportsTearing ;
735
675
Uint8 supportsFlipDiscard ;
@@ -1009,7 +949,6 @@ static void D3D11_DestroyDevice(
1009
949
/* Release the DLLs */
1010
950
SDL_UnloadObject (renderer -> d3d11_dll );
1011
951
SDL_UnloadObject (renderer -> dxgi_dll );
1012
- SDL_UnloadObject (renderer -> d3dcompiler_dll );
1013
952
if (renderer -> dxgidebug_dll ) {
1014
953
SDL_UnloadObject (renderer -> dxgidebug_dll );
1015
954
}
@@ -1463,38 +1402,10 @@ static ID3D11DeviceChild *D3D11_INTERNAL_CreateID3D11Shader(
1463
1402
void * * pBytecode ,
1464
1403
size_t * pBytecodeSize )
1465
1404
{
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 ;
1471
1405
ID3D11DeviceChild * handle = NULL ;
1472
1406
HRESULT res ;
1473
1407
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 ) {
1498
1409
SDL_LogError (SDL_LOG_CATEGORY_GPU , "Incompatible shader format for D3D11" );
1499
1410
return NULL ;
1500
1411
}
@@ -1503,8 +1414,8 @@ static ID3D11DeviceChild *D3D11_INTERNAL_CreateID3D11Shader(
1503
1414
if (stage == SDL_GPU_SHADERSTAGE_VERTEX ) {
1504
1415
res = ID3D11Device_CreateVertexShader (
1505
1416
renderer -> device ,
1506
- bytecode ,
1507
- bytecodeSize ,
1417
+ code ,
1418
+ codeSize ,
1508
1419
NULL ,
1509
1420
(ID3D11VertexShader * * )& handle );
1510
1421
if (FAILED (res )) {
@@ -1514,8 +1425,8 @@ static ID3D11DeviceChild *D3D11_INTERNAL_CreateID3D11Shader(
1514
1425
} else if (stage == SDL_GPU_SHADERSTAGE_FRAGMENT ) {
1515
1426
res = ID3D11Device_CreatePixelShader (
1516
1427
renderer -> device ,
1517
- bytecode ,
1518
- bytecodeSize ,
1428
+ code ,
1429
+ codeSize ,
1519
1430
NULL ,
1520
1431
(ID3D11PixelShader * * )& handle );
1521
1432
if (FAILED (res )) {
@@ -1525,8 +1436,8 @@ static ID3D11DeviceChild *D3D11_INTERNAL_CreateID3D11Shader(
1525
1436
} else if (stage == SDL_GPU_SHADERSTAGE_COMPUTE ) {
1526
1437
res = ID3D11Device_CreateComputeShader (
1527
1438
renderer -> device ,
1528
- bytecode ,
1529
- bytecodeSize ,
1439
+ code ,
1440
+ codeSize ,
1530
1441
NULL ,
1531
1442
(ID3D11ComputeShader * * )& handle );
1532
1443
if (FAILED (res )) {
@@ -1536,14 +1447,9 @@ static ID3D11DeviceChild *D3D11_INTERNAL_CreateID3D11Shader(
1536
1447
}
1537
1448
1538
1449
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 ;
1547
1453
}
1548
1454
1549
1455
return handle ;
@@ -1886,8 +1792,8 @@ SDL_GpuShader *D3D11_CreateShader(
1886
1792
{
1887
1793
D3D11Renderer * renderer = (D3D11Renderer * )driverData ;
1888
1794
ID3D11DeviceChild * handle ;
1889
- void * bytecode ;
1890
- size_t bytecodeSize ;
1795
+ void * bytecode = NULL ;
1796
+ size_t bytecodeSize = 0 ;
1891
1797
D3D11Shader * shader ;
1892
1798
1893
1799
handle = D3D11_INTERNAL_CreateID3D11Shader (
@@ -5742,11 +5648,10 @@ static SDL_bool D3D11_IsTextureFormatSupported(
5742
5648
5743
5649
static SDL_bool D3D11_PrepareDriver (SDL_VideoDevice * _this )
5744
5650
{
5745
- void * d3d11_dll , * dxgi_dll , * d3dcompiler_dll ;
5651
+ void * d3d11_dll , * dxgi_dll ;
5746
5652
PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc ;
5747
5653
D3D_FEATURE_LEVEL levels [] = { D3D_FEATURE_LEVEL_11_1 };
5748
5654
PFN_CREATE_DXGI_FACTORY1 CreateDXGIFactoryFunc ;
5749
- PFN_D3DCOMPILE D3DCompileFunc ;
5750
5655
HRESULT res ;
5751
5656
5752
5657
/* Can we load D3D11? */
@@ -5804,23 +5709,6 @@ static SDL_bool D3D11_PrepareDriver(SDL_VideoDevice *_this)
5804
5709
return SDL_FALSE ;
5805
5710
}
5806
5711
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
-
5824
5712
return SDL_TRUE ;
5825
5713
}
5826
5714
@@ -6035,19 +5923,6 @@ static SDL_GpuDevice *D3D11_CreateDevice(SDL_bool debugMode, SDL_bool preferLowP
6035
5923
/* Allocate and zero out the renderer */
6036
5924
renderer = (D3D11Renderer * )SDL_calloc (1 , sizeof (D3D11Renderer ));
6037
5925
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
-
6051
5926
/* Load the DXGI library */
6052
5927
renderer -> dxgi_dll = SDL_LoadObject (DXGI_DLL );
6053
5928
if (renderer -> dxgi_dll == NULL ) {
0 commit comments