SDL_shaders_d3d12_xboxone.cpp 4.2 KB

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