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
8 JPH_SUPPRESS_WARNING_PUSH
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
35 JPH_SUPPRESS_WARNING_POP
36#else
37 #pragma pack_matrix(column_major)
38
39 typedef float JPH_float;
40 typedef float3 JPH_float3;
41 typedef float4 JPH_float4;
42 typedef uint JPH_uint;
43 typedef uint3 JPH_uint3;
44 typedef uint4 JPH_uint4;
45 typedef int JPH_int;
46 typedef int3 JPH_int3;
47 typedef int4 JPH_int4;
48 typedef float4 JPH_Quat; // xyz = imaginary part, w = real part
49 typedef float4 JPH_Plane; // xyz = normal, w = constant
50 typedef float4x4 JPH_Mat44; // matrix, column major
51
52 #define JPH_SHADER_CONSTANT(type, name, value) static const type name = value;
53
54 #define JPH_SHADER_CONSTANTS_BEGIN(type, name) cbuffer name {
55 #define JPH_SHADER_CONSTANTS_MEMBER(type, name) type c##name;
56 #define JPH_SHADER_CONSTANTS_END(type) };
57
58 #define JPH_SHADER_FUNCTION_BEGIN(return_type, name, group_size_x, group_size_y, group_size_z) \
59 [numthreads(group_size_x, group_size_y, group_size_z)] \
60 return_type name(
61 #define JPH_SHADER_PARAM_THREAD_ID(name) uint3 name : SV_DispatchThreadID
62 #define JPH_SHADER_FUNCTION_END )
63
64 #define JPH_SHADER_BUFFER(type) StructuredBuffer<type>
65 #define JPH_SHADER_RW_BUFFER(type) RWStructuredBuffer<type>
66
67 #define JPH_SHADER_BIND_BEGIN(name)
68 #define JPH_SHADER_BIND_END(name)
69 #define JPH_SHADER_BIND_BUFFER(type, name) JPH_SHADER_BUFFER(type) name;
70 #define JPH_SHADER_BIND_RW_BUFFER(type, name) JPH_SHADER_RW_BUFFER(type) name;
71
72 #define JPH_AtomicAdd InterlockedAdd
73#endif
74
75#define JPH_SHADER_STRUCT_BEGIN(name) struct name {
76#define JPH_SHADER_STRUCT_MEMBER(type, name) type m##name;
77#define JPH_SHADER_STRUCT_END(name) };
78
79#define JPH_IN(type) in type
80#define JPH_OUT(type) out type
81#define JPH_IN_OUT(type) in out type
82
83#endif // JPH_OVERRIDE_SHADER_MACROS
#define JPH_SUPPRESS_WARNINGS
Definition Core.h:336
unsigned int uint
Definition Core.h:500
uint JPH_uint
Definition ShaderCore.h:42
int JPH_int
Definition ShaderCore.h:45
int3 JPH_int3
Definition ShaderCore.h:46
int4 JPH_int4
Definition ShaderCore.h:47
uint4 JPH_uint4
Definition ShaderCore.h:44
float4x4 JPH_Mat44
Definition ShaderCore.h:50
float JPH_float
Definition ShaderCore.h:39
float3 JPH_float3
Definition ShaderCore.h:40
float4 JPH_Plane
Definition ShaderCore.h:49
float4 JPH_float4
Definition ShaderCore.h:41
float4 JPH_Quat
Definition ShaderCore.h:48
uint3 JPH_uint3
Definition ShaderCore.h:43