Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ShaderCore.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2025 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#ifndef JPH_SHADER_OVERRIDE_MACROS
6
7#ifdef __cplusplus
10
11 using JPH_float = float;
12 using JPH_float3 = JPH::Float3;
13 using JPH_float4 = JPH::Float4;
14 using JPH_uint = JPH::uint32;
15 using JPH_uint3 = JPH::uint32[3];
16 using JPH_uint4 = JPH::uint32[4];
17 using JPH_int = int;
18 using JPH_int3 = int[3];
19 using JPH_int4 = int[4];
20 using JPH_Quat = JPH::Float4;
21 using JPH_Plane = JPH::Float4;
22 using JPH_Mat44 = JPH::Float4[4]; // matrix, column major
23
24 #define JPH_SHADER_CONSTANT(type, name, value) constexpr type name = value;
25
26 #define JPH_SHADER_CONSTANTS_BEGIN(type, name) struct type {
27 #define JPH_SHADER_CONSTANTS_MEMBER(type, name) type c##name;
28 #define JPH_SHADER_CONSTANTS_END(type) };
29
30 #define JPH_SHADER_BIND_BEGIN(name)
31 #define JPH_SHADER_BIND_END(name)
32 #define JPH_SHADER_BIND_BUFFER(type, name)
33 #define JPH_SHADER_BIND_RW_BUFFER(type, name)
34
36#else
37 #define JPH_SUPPRESS_WARNING_PUSH
38 #define JPH_SUPPRESS_WARNING_POP
39 #define JPH_SUPPRESS_WARNINGS
40
41 typedef float JPH_float;
42 typedef float3 JPH_float3;
43 typedef float4 JPH_float4;
44 typedef uint JPH_uint;
45 typedef uint3 JPH_uint3;
46 typedef uint4 JPH_uint4;
47 typedef int JPH_int;
48 typedef int3 JPH_int3;
49 typedef int4 JPH_int4;
50 typedef float4 JPH_Quat; // xyz = imaginary part, w = real part
51 typedef float4 JPH_Plane; // xyz = normal, w = constant
52 typedef float4 JPH_Mat44[4]; // matrix, column major
53
54 #define JPH_SHADER_CONSTANT(type, name, value) static const type name = value;
55
56 #define JPH_SHADER_CONSTANTS_BEGIN(type, name) cbuffer name {
57 #define JPH_SHADER_CONSTANTS_MEMBER(type, name) type c##name;
58 #define JPH_SHADER_CONSTANTS_END(type) };
59
60 #define JPH_SHADER_FUNCTION_BEGIN(return_type, name, group_size_x, group_size_y, group_size_z) \
61 [numthreads(group_size_x, group_size_y, group_size_z)] \
62 return_type name(
63 #define JPH_SHADER_PARAM_THREAD_ID(name) uint3 name : SV_DispatchThreadID
64 #define JPH_SHADER_FUNCTION_END )
65
66 #define JPH_SHADER_BUFFER(type) StructuredBuffer<type>
67 #define JPH_SHADER_RW_BUFFER(type) RWStructuredBuffer<type>
68
69 #define JPH_SHADER_BIND_BEGIN(name)
70 #define JPH_SHADER_BIND_END(name)
71 #define JPH_SHADER_BIND_BUFFER(type, name) JPH_SHADER_BUFFER(type) name;
72 #define JPH_SHADER_BIND_RW_BUFFER(type, name) JPH_SHADER_RW_BUFFER(type) name;
73
74 #define JPH_AtomicAdd InterlockedAdd
75#endif
76
77#define JPH_SHADER_STRUCT_BEGIN(name) struct name {
78#define JPH_SHADER_STRUCT_MEMBER(type, name) type m##name;
79#define JPH_SHADER_STRUCT_END(name) };
80
81#define JPH_IN(type) in type
82#define JPH_OUT(type) out type
83#define JPH_IN_OUT(type) in out type
84
85#endif // JPH_OVERRIDE_SHADER_MACROS
unsigned int uint
Definition Core.h:500
uint JPH_uint
Definition ShaderCore.h:44
#define JPH_SUPPRESS_WARNINGS
Definition ShaderCore.h:39
int JPH_int
Definition ShaderCore.h:47
int3 JPH_int3
Definition ShaderCore.h:48
int4 JPH_int4
Definition ShaderCore.h:49
uint4 JPH_uint4
Definition ShaderCore.h:46
float4 JPH_Mat44[4]
Definition ShaderCore.h:52
float JPH_float
Definition ShaderCore.h:41
float3 JPH_float3
Definition ShaderCore.h:42
float4 JPH_Plane
Definition ShaderCore.h:51
float4 JPH_float4
Definition ShaderCore.h:43
#define JPH_SUPPRESS_WARNING_POP
Definition ShaderCore.h:38
#define JPH_SUPPRESS_WARNING_PUSH
Definition ShaderCore.h:37
float4 JPH_Quat
Definition ShaderCore.h:50
uint3 JPH_uint3
Definition ShaderCore.h:45