| 1 | /* | 
|---|
| 2 | Simple DirectMedia Layer | 
|---|
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | 
|---|
| 4 |  | 
|---|
| 5 | This software is provided 'as-is', without any express or implied | 
|---|
| 6 | warranty.  In no event will the authors be held liable for any damages | 
|---|
| 7 | arising from the use of this software. | 
|---|
| 8 |  | 
|---|
| 9 | Permission is granted to anyone to use this software for any purpose, | 
|---|
| 10 | including commercial applications, and to alter it and redistribute it | 
|---|
| 11 | freely, subject to the following restrictions: | 
|---|
| 12 |  | 
|---|
| 13 | 1. The origin of this software must not be misrepresented; you must not | 
|---|
| 14 | claim that you wrote the original software. If you use this software | 
|---|
| 15 | in a product, an acknowledgment in the product documentation would be | 
|---|
| 16 | appreciated but is not required. | 
|---|
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | 
|---|
| 18 | misrepresented as being the original software. | 
|---|
| 19 | 3. This notice may not be removed or altered from any source distribution. | 
|---|
| 20 | */ | 
|---|
| 21 | #include "SDL_internal.h" | 
|---|
| 22 |  | 
|---|
| 23 | #if defined(SDL_VIDEO_RENDER_D3D12) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) | 
|---|
| 24 |  | 
|---|
| 25 | #include "../../core/windows/SDL_windows.h" | 
|---|
| 26 | #include "../../video/directx/SDL_d3d12.h" | 
|---|
| 27 |  | 
|---|
| 28 | #include "SDL_shaders_d3d12.h" | 
|---|
| 29 |  | 
|---|
| 30 | #define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str | 
|---|
| 31 |  | 
|---|
| 32 | // The shaders here were compiled with compile_shaders.bat | 
|---|
| 33 |  | 
|---|
| 34 | #define g_main D3D12_PixelShader_Colors | 
|---|
| 35 | #include "D3D12_PixelShader_Colors.h" | 
|---|
| 36 | #undef g_main | 
|---|
| 37 |  | 
|---|
| 38 | #define g_main D3D12_PixelShader_Textures | 
|---|
| 39 | #include "D3D12_PixelShader_Textures.h" | 
|---|
| 40 | #undef g_main | 
|---|
| 41 |  | 
|---|
| 42 | #define g_main D3D12_PixelShader_Advanced | 
|---|
| 43 | #include "D3D12_PixelShader_Advanced.h" | 
|---|
| 44 | #undef g_main | 
|---|
| 45 |  | 
|---|
| 46 |  | 
|---|
| 47 | #define g_mainColor D3D12_VertexShader_Colors | 
|---|
| 48 | #include "D3D12_VertexShader_Color.h" | 
|---|
| 49 | #undef g_mainColor | 
|---|
| 50 |  | 
|---|
| 51 | #define g_mainTexture D3D12_VertexShader_Textures | 
|---|
| 52 | #include "D3D12_VertexShader_Texture.h" | 
|---|
| 53 | #undef g_mainTexture | 
|---|
| 54 |  | 
|---|
| 55 | #define g_mainAdvanced D3D12_VertexShader_Advanced | 
|---|
| 56 | #include "D3D12_VertexShader_Advanced.h" | 
|---|
| 57 | #undef g_mainAdvanced | 
|---|
| 58 |  | 
|---|
| 59 |  | 
|---|
| 60 | #define g_ColorRS D3D12_RootSig_Color | 
|---|
| 61 | #include "D3D12_RootSig_Color.h" | 
|---|
| 62 | #undef g_ColorRS | 
|---|
| 63 |  | 
|---|
| 64 | #define g_TextureRS D3D12_RootSig_Texture | 
|---|
| 65 | #include "D3D12_RootSig_Texture.h" | 
|---|
| 66 | #undef g_TextureRS | 
|---|
| 67 |  | 
|---|
| 68 | #define g_AdvancedRS D3D12_RootSig_Advanced | 
|---|
| 69 | #include "D3D12_RootSig_Advanced.h" | 
|---|
| 70 | #undef g_AdvancedRS | 
|---|
| 71 |  | 
|---|
| 72 |  | 
|---|
| 73 | static struct | 
|---|
| 74 | { | 
|---|
| 75 | const void *ps_shader_data; | 
|---|
| 76 | SIZE_T ps_shader_size; | 
|---|
| 77 | const void *vs_shader_data; | 
|---|
| 78 | SIZE_T vs_shader_size; | 
|---|
| 79 | D3D12_RootSignature root_sig; | 
|---|
| 80 | } D3D12_shaders[NUM_SHADERS] = { | 
|---|
| 81 | { D3D12_PixelShader_Colors, sizeof(D3D12_PixelShader_Colors), | 
|---|
| 82 | D3D12_VertexShader_Colors, sizeof(D3D12_VertexShader_Colors), | 
|---|
| 83 | ROOTSIG_COLOR }, | 
|---|
| 84 | { D3D12_PixelShader_Textures, sizeof(D3D12_PixelShader_Textures), | 
|---|
| 85 | D3D12_VertexShader_Textures, sizeof(D3D12_VertexShader_Textures), | 
|---|
| 86 | ROOTSIG_TEXTURE }, | 
|---|
| 87 | { D3D12_PixelShader_Advanced, sizeof(D3D12_PixelShader_Advanced), | 
|---|
| 88 | D3D12_VertexShader_Advanced, sizeof(D3D12_VertexShader_Advanced), | 
|---|
| 89 | ROOTSIG_ADVANCED }, | 
|---|
| 90 | }; | 
|---|
| 91 |  | 
|---|
| 92 | static struct | 
|---|
| 93 | { | 
|---|
| 94 | const void *rs_shader_data; | 
|---|
| 95 | SIZE_T rs_shader_size; | 
|---|
| 96 | } D3D12_rootsigs[NUM_ROOTSIGS] = { | 
|---|
| 97 | { D3D12_RootSig_Color, sizeof(D3D12_RootSig_Color) }, | 
|---|
| 98 | { D3D12_RootSig_Texture, sizeof(D3D12_RootSig_Texture) }, | 
|---|
| 99 | { D3D12_RootSig_Advanced, sizeof(D3D12_RootSig_Advanced) }, | 
|---|
| 100 | }; | 
|---|
| 101 |  | 
|---|
| 102 | void D3D12_GetVertexShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) | 
|---|
| 103 | { | 
|---|
| 104 | outBytecode->pShaderBytecode = D3D12_shaders[shader].vs_shader_data; | 
|---|
| 105 | outBytecode->BytecodeLength = D3D12_shaders[shader].vs_shader_size; | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | void D3D12_GetPixelShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) | 
|---|
| 109 | { | 
|---|
| 110 | outBytecode->pShaderBytecode = D3D12_shaders[shader].ps_shader_data; | 
|---|
| 111 | outBytecode->BytecodeLength = D3D12_shaders[shader].ps_shader_size; | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | D3D12_RootSignature D3D12_GetRootSignatureType(D3D12_Shader shader) | 
|---|
| 115 | { | 
|---|
| 116 | return D3D12_shaders[shader].root_sig; | 
|---|
| 117 | } | 
|---|
| 118 |  | 
|---|
| 119 | void D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECODE *outBytecode) | 
|---|
| 120 | { | 
|---|
| 121 | outBytecode->pShaderBytecode = D3D12_rootsigs[rootSig].rs_shader_data; | 
|---|
| 122 | outBytecode->BytecodeLength = D3D12_rootsigs[rootSig].rs_shader_size; | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | #endif // SDL_VIDEO_RENDER_D3D12 && !SDL_PLATFORM_XBOXONE && !SDL_PLATFORM_XBOXSERIES | 
|---|
| 126 |  | 
|---|