WrapShaderBegin.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2026 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <Jolt/Core/HashCombine.h>
  5. #include <Jolt/Compute/CPU/ComputeSystemCPU.h>
  6. #include <Jolt/Compute/CPU/ShaderWrapper.h>
  7. #include <Jolt/Compute/CPU/HLSLToCPP.h>
  8. /// @cond INTERNAL
  9. JPH_NAMESPACE_BEGIN
  10. JPH_MSVC_SUPPRESS_WARNING(5031) // #pragma warning(pop): likely mismatch, popping warning state pushed in different file
  11. #define JPH_SHADER_OVERRIDE_MACROS
  12. #define JPH_SHADER_GENERATE_WRAPPER
  13. #define JPH_SHADER_CONSTANT(type, name, value) inline static constexpr type name = value;
  14. #define JPH_SHADER_CONSTANTS_BEGIN(type, name) struct type { alignas(16) int dummy; } name; // Ensure that the first constant is 16 byte aligned
  15. #define JPH_SHADER_CONSTANTS_MEMBER(type, name) type c##name;
  16. #define JPH_SHADER_CONSTANTS_END(type)
  17. #define JPH_SHADER_BUFFER(type) const type *
  18. #define JPH_SHADER_RW_BUFFER(type) type *
  19. #define JPH_SHADER_BIND_BEGIN(name)
  20. #define JPH_SHADER_BIND_END(name)
  21. #define JPH_SHADER_BIND_BUFFER(type, name) const type *name = nullptr;
  22. #define JPH_SHADER_BIND_RW_BUFFER(type, name) type *name = nullptr;
  23. #define JPH_SHADER_FUNCTION_BEGIN(return_type, name, group_size_x, group_size_y, group_size_z) \
  24. virtual void Main(
  25. #define JPH_SHADER_PARAM_THREAD_ID(name) const HLSLToCPP::uint3 &name
  26. #define JPH_SHADER_FUNCTION_END ) override
  27. #define JPH_SHADER_STRUCT_BEGIN(name) struct name {
  28. #define JPH_SHADER_STRUCT_MEMBER(type, name) type m##name;
  29. #define JPH_SHADER_STRUCT_END(name) };
  30. #define JPH_TO_STRING(name) JPH_TO_STRING2(name)
  31. #define JPH_TO_STRING2(name) #name
  32. #define JPH_SHADER_CLASS_NAME(name) JPH_SHADER_CLASS_NAME2(name)
  33. #define JPH_SHADER_CLASS_NAME2(name) name##ShaderWrapper
  34. #define JPH_IN(type) const type &
  35. #define JPH_OUT(type) type &
  36. #define JPH_IN_OUT(type) type &
  37. // Namespace to prevent 'using' from leaking out
  38. namespace ShaderWrappers {
  39. using namespace HLSLToCPP;
  40. class JPH_SHADER_CLASS_NAME(JPH_SHADER_NAME) : public ShaderWrapper
  41. {
  42. public:
  43. // Define types
  44. using JPH_float = float;
  45. using JPH_float3 = HLSLToCPP::float3;
  46. using JPH_float4 = HLSLToCPP::float4;
  47. using JPH_uint = uint;
  48. using JPH_uint3 = HLSLToCPP::uint3;
  49. using JPH_uint4 = HLSLToCPP::uint4;
  50. using JPH_int = int;
  51. using JPH_int3 = HLSLToCPP::int3;
  52. using JPH_int4 = HLSLToCPP::int4;
  53. using JPH_Quat = HLSLToCPP::Quat;
  54. using JPH_Plane = HLSLToCPP::Plane;
  55. using JPH_Mat44 = HLSLToCPP::Mat44;
  56. // Now the shader code should be included followed by WrapShaderBindings.h
  57. /// @endcond