Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ComputeSystemCPU.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2026 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
9#ifdef JPH_USE_CPU_COMPUTE
10
13
15
18class JPH_EXPORT ComputeSystemCPU : public ComputeSystem
19{
20public:
21 JPH_DECLARE_RTTI_VIRTUAL(JPH_EXPORT, ComputeSystemCPU)
22
23 // See: ComputeSystem
24 virtual ComputeShaderResult CreateComputeShader(const char *inName, uint32 inGroupSizeX, uint32 inGroupSizeY, uint32 inGroupSizeZ) override;
25 virtual ComputeBufferResult CreateComputeBuffer(ComputeBuffer::EType inType, uint64 inSize, uint inStride, const void *inData = nullptr) override;
26 virtual ComputeQueueResult CreateComputeQueue() override;
27
28 using CreateShader = ComputeShaderCPU::CreateShader;
29
30 void RegisterShader(const char *inName, CreateShader inCreateShader)
31 {
32 mShaderRegistry[inName] = inCreateShader;
33 }
34
35private:
36 using ShaderRegistry = UnorderedMap<string_view, CreateShader>;
37 ShaderRegistry mShaderRegistry;
38};
39
40// Internal helpers
41#define JPH_SHADER_WRAPPER_FUNCTION_NAME(name) RegisterShader##name
42#define JPH_SHADER_WRAPPER_FUNCTION(sys, name) void JPH_EXPORT JPH_SHADER_WRAPPER_FUNCTION_NAME(name)(ComputeSystemCPU *sys)
43
45#define JPH_DECLARE_REGISTER_SHADER(name) namespace JPH { class ComputeSystemCPU; JPH_SHADER_WRAPPER_FUNCTION(, name); }
46
48#define JPH_REGISTER_SHADER(sys, name) JPH::JPH_SHADER_WRAPPER_FUNCTION_NAME(name)(sys)
49
51
52#endif // JPH_USE_CPU_COMPUTE
#define JPH_EXPORT
Definition Core.h:275
std::uint64_t uint64
Definition Core.h:504
unsigned int uint
Definition Core.h:500
#define JPH_NAMESPACE_END
Definition Core.h:425
std::uint32_t uint32
Definition Core.h:503
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
#define JPH_DECLARE_RTTI_VIRTUAL(linkage, class_name)
Definition RTTI.h:245
EType
Type of buffer.
Definition ComputeBuffer.h:24
Interface to run a workload on the GPU.
Definition ComputeSystem.h:16
virtual ComputeQueueResult CreateComputeQueue()=0
Create a queue for executing compute shaders.
virtual ComputeBufferResult CreateComputeBuffer(ComputeBuffer::EType inType, uint64 inSize, uint inStride, const void *inData=nullptr)=0
Create a buffer for use with a compute shader.
virtual ComputeShaderResult CreateComputeShader(const char *inName, uint32 inGroupSizeX, uint32 inGroupSizeY=1, uint32 inGroupSizeZ=1)=0
Compile a compute shader.
Helper class that either contains a valid result or an error.
Definition Result.h:12
Definition UnorderedMap.h:31