Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ComputeSystem.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#pragma once
6
10#include <Jolt/Core/RTTI.h>
11
13
15class JPH_EXPORT ComputeSystem : public RefTarget<ComputeSystem>, public NonCopyable
16{
17public:
19
20
21 virtual ~ComputeSystem() = default;
22
24 virtual ComputeShaderResult CreateComputeShader(const char *inName, uint32 inGroupSizeX, uint32 inGroupSizeY = 1, uint32 inGroupSizeZ = 1) = 0;
25
27 virtual ComputeBufferResult CreateComputeBuffer(ComputeBuffer::EType inType, uint64 inSize, uint inStride, const void *inData = nullptr) = 0;
28
30 virtual ComputeQueueResult CreateComputeQueue() = 0;
31
33 using ShaderLoader = std::function<bool(const char *inName, Array<uint8> &outData, String &outError)>;
34 ShaderLoader mShaderLoader = [](const char *, Array<uint8> &, String &outError) { JPH_ASSERT(false, "Override this function"); outError = "Not implemented"; return false; };
35};
36
38
39#ifdef JPH_USE_VK
41extern JPH_EXPORT ComputeSystemResult CreateComputeSystemVK();
42#endif
43
44#ifdef JPH_USE_CPU_COMPUTE
47extern JPH_EXPORT ComputeSystemResult CreateComputeSystemCPU();
48#endif
49
50#ifdef JPH_USE_DX12
51
53extern JPH_EXPORT ComputeSystemResult CreateComputeSystemDX12();
54
56inline ComputeSystemResult CreateComputeSystem() { return CreateComputeSystemDX12(); }
57
58#elif defined(JPH_USE_MTL)
59
61extern JPH_EXPORT ComputeSystemResult CreateComputeSystemMTL();
62
64inline ComputeSystemResult CreateComputeSystem() { return CreateComputeSystemMTL(); }
65
66#elif defined(JPH_USE_VK)
67
69inline ComputeSystemResult CreateComputeSystem() { return CreateComputeSystemVK(); }
70
71#else
72
74inline ComputeSystemResult CreateComputeSystem() { ComputeSystemResult result; result.SetError("Not implemented"); return result; }
75
76#endif
77
ComputeSystemResult CreateComputeSystem()
Fallback implementation when no compute system is available.
Definition ComputeSystem.h:74
std::uint8_t uint8
Definition Core.h:501
#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_ASSERT(...)
Definition IssueReporting.h:33
#define JPH_DECLARE_RTTI_ABSTRACT_BASE(linkage, class_name)
Definition RTTI.h:295
std::basic_string< char, std::char_traits< char >, STLAllocator< char > > String
Definition STLAllocator.h:107
Definition Array.h:36
Buffer that can be read from / written to by a compute shader.
Definition ComputeBuffer.h:18
Interface to run a workload on the GPU.
Definition ComputeSystem.h:16
std::function< bool(const char *inName, Array< uint8 > &outData, String &outError)> ShaderLoader
Callback used when loading shaders.
Definition ComputeSystem.h:33
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
Definition Reference.h:35
Helper class that either contains a valid result or an error.
Definition Result.h:12
void SetError(const char *inError)
Set an error value.
Definition Result.h:152
Definition Array.h:699