ComputeSystem.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2025 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Compute/ComputeShader.h>
  6. #include <Jolt/Compute/ComputeBuffer.h>
  7. #include <Jolt/Compute/ComputeQueue.h>
  8. JPH_NAMESPACE_BEGIN
  9. /// Interface to run a workload on the GPU
  10. class JPH_EXPORT ComputeSystem : public RefTarget<ComputeSystem>, public NonCopyable
  11. {
  12. public:
  13. JPH_OVERRIDE_NEW_DELETE
  14. /// Destructor
  15. virtual ~ComputeSystem() = default;
  16. /// Compile a compute shader
  17. virtual Ref<ComputeShader> CreateComputeShader(const char *inName, uint32 inGroupSizeX, uint32 inGroupSizeY = 1, uint32 inGroupSizeZ = 1) = 0;
  18. /// Create a buffer for use with a compute shader
  19. virtual Ref<ComputeBuffer> CreateComputeBuffer(ComputeBuffer::EType inType, uint64 inSize, uint inStride, const void *inData = nullptr) = 0;
  20. /// Create a queue for executing compute shaders
  21. virtual Ref<ComputeQueue> CreateComputeQueue() = 0;
  22. /// Callback used when loading shaders
  23. using ShaderLoader = std::function<bool(const char *inName, Array<uint8> &outData)>;
  24. ShaderLoader mShaderLoader = [](const char *, Array<uint8> &) { JPH_ASSERT(false, "Override this function"); return false; };
  25. };
  26. #ifdef JPH_USE_VK
  27. /// Factory function to create a compute system using Vulkan
  28. extern JPH_EXPORT ComputeSystem * CreateComputeSystemVK();
  29. #endif
  30. #ifdef JPH_USE_DX12
  31. /// Factory function to create a compute system using DirectX 12
  32. extern JPH_EXPORT ComputeSystem * CreateComputeSystemDX12();
  33. /// Factory function to create the default compute system for this platform
  34. inline ComputeSystem * CreateComputeSystem() { return CreateComputeSystemDX12(); }
  35. #elif defined(JPH_USE_MTL)
  36. /// Factory function to create a compute system using Metal
  37. extern JPH_EXPORT ComputeSystem * CreateComputeSystemMTL();
  38. /// Factory function to create the default compute system for this platform
  39. inline ComputeSystem * CreateComputeSystem() { return CreateComputeSystemMTL(); }
  40. #elif defined(JPH_USE_VK)
  41. /// Factory function to create the default compute system for this platform
  42. inline ComputeSystem * CreateComputeSystem() { return CreateComputeSystemVK(); }
  43. #else
  44. /// Fallback implementation when no compute system is available
  45. inline ComputeSystem * CreateComputeSystem() { return nullptr; }
  46. #endif
  47. JPH_NAMESPACE_END