SDL_shaders_d3d12_xboxseries.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 && !SDL_RENDER_DISABLED && defined(__XBOXSERIES__)
  20. #include <SDL3/SDL_stdinc.h>
  21. #include "../../core/windows/SDL_windows.h"
  22. #include <d3d12_xs.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 buildshaders.bat */
  26. #include "../VisualC-GDK/shaders/D3D12_PixelShader_Colors_Series.h"
  27. #include "../VisualC-GDK/shaders/D3D12_PixelShader_Textures_Series.h"
  28. #include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT601_Series.h"
  29. #include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_BT709_Series.h"
  30. #include "../VisualC-GDK/shaders/D3D12_PixelShader_NV12_JPEG_Series.h"
  31. #include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT601_Series.h"
  32. #include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_BT709_Series.h"
  33. #include "../VisualC-GDK/shaders/D3D12_PixelShader_NV21_JPEG_Series.h"
  34. #include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT601_Series.h"
  35. #include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_BT709_Series.h"
  36. #include "../VisualC-GDK/shaders/D3D12_PixelShader_YUV_JPEG_Series.h"
  37. #include "../VisualC-GDK/shaders/D3D12_VertexShader_Color_Series.h"
  38. #include "../VisualC-GDK/shaders/D3D12_VertexShader_Texture_Series.h"
  39. #include "../VisualC-GDK/shaders/D3D12_VertexShader_NV_Series.h"
  40. #include "../VisualC-GDK/shaders/D3D12_VertexShader_YUV_Series.h"
  41. #include "../VisualC-GDK/shaders/D3D12_RootSig_Color_Series.h"
  42. #include "../VisualC-GDK/shaders/D3D12_RootSig_Texture_Series.h"
  43. #include "../VisualC-GDK/shaders/D3D12_RootSig_YUV_Series.h"
  44. #include "../VisualC-GDK/shaders/D3D12_RootSig_NV_Series.h"
  45. static struct
  46. {
  47. const void *ps_shader_data;
  48. SIZE_T ps_shader_size;
  49. const void *vs_shader_data;
  50. SIZE_T vs_shader_size;
  51. D3D12_RootSignature root_sig;
  52. } D3D12_shaders[NUM_SHADERS] = {
  53. { D3D12_PixelShader_Colors, sizeof(D3D12_PixelShader_Colors),
  54. D3D12_VertexShader_Color, sizeof(D3D12_VertexShader_Color),
  55. ROOTSIG_COLOR },
  56. { D3D12_PixelShader_Textures, sizeof(D3D12_PixelShader_Textures),
  57. D3D12_VertexShader_Texture, sizeof(D3D12_VertexShader_Texture),
  58. ROOTSIG_TEXTURE },
  59. #if SDL_HAVE_YUV
  60. { D3D12_PixelShader_YUV_JPEG, sizeof(D3D12_PixelShader_YUV_JPEG),
  61. D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV),
  62. ROOTSIG_YUV },
  63. { D3D12_PixelShader_YUV_BT601, sizeof(D3D12_PixelShader_YUV_BT601),
  64. D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV),
  65. ROOTSIG_YUV },
  66. { D3D12_PixelShader_YUV_BT709, sizeof(D3D12_PixelShader_YUV_BT709),
  67. D3D12_VertexShader_YUV, sizeof(D3D12_VertexShader_YUV),
  68. ROOTSIG_YUV },
  69. { D3D12_PixelShader_NV12_JPEG, sizeof(D3D12_PixelShader_NV12_JPEG),
  70. D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
  71. ROOTSIG_NV },
  72. { D3D12_PixelShader_NV12_BT601, sizeof(D3D12_PixelShader_NV12_BT601),
  73. D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
  74. ROOTSIG_NV },
  75. { D3D12_PixelShader_NV12_BT709, sizeof(D3D12_PixelShader_NV12_BT709),
  76. D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
  77. ROOTSIG_NV },
  78. { D3D12_PixelShader_NV21_JPEG, sizeof(D3D12_PixelShader_NV21_JPEG),
  79. D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
  80. ROOTSIG_NV },
  81. { D3D12_PixelShader_NV21_BT601, sizeof(D3D12_PixelShader_NV21_BT601),
  82. D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
  83. ROOTSIG_NV },
  84. { D3D12_PixelShader_NV21_BT709, sizeof(D3D12_PixelShader_NV21_BT709),
  85. D3D12_VertexShader_NV, sizeof(D3D12_VertexShader_NV),
  86. ROOTSIG_NV },
  87. #endif
  88. };
  89. static struct
  90. {
  91. const void *rs_shader_data;
  92. SIZE_T rs_shader_size;
  93. } D3D12_rootsigs[NUM_ROOTSIGS] = {
  94. { D3D12_RootSig_Color, sizeof(D3D12_RootSig_Color) },
  95. { D3D12_RootSig_Texture, sizeof(D3D12_RootSig_Texture) },
  96. #if SDL_HAVE_YUV
  97. { D3D12_RootSig_YUV, sizeof(D3D12_RootSig_YUV) },
  98. { D3D12_RootSig_NV, sizeof(D3D12_RootSig_NV) },
  99. #endif
  100. };
  101. extern "C" void
  102. 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. extern "C" void
  108. 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. extern "C" D3D12_RootSignature
  114. D3D12_GetRootSignatureType(D3D12_Shader shader)
  115. {
  116. return D3D12_shaders[shader].root_sig;
  117. }
  118. extern "C" void
  119. 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. #endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXSERIES__) */
  125. /* vi: set ts=4 sw=4 expandtab: */