ComputeSystemCPU.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2026 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Compute/ComputeSystem.h>
  6. #ifdef JPH_USE_CPU_COMPUTE
  7. #include <Jolt/Core/UnorderedMap.h>
  8. #include <Jolt/Compute/CPU/ComputeShaderCPU.h>
  9. JPH_NAMESPACE_BEGIN
  10. /// Interface to run a workload on the CPU
  11. /// This is intended mainly for debugging purposes and is not optimized for performance
  12. class JPH_EXPORT ComputeSystemCPU : public ComputeSystem
  13. {
  14. public:
  15. JPH_DECLARE_RTTI_VIRTUAL(JPH_EXPORT, ComputeSystemCPU)
  16. // See: ComputeSystem
  17. virtual ComputeShaderResult CreateComputeShader(const char *inName, uint32 inGroupSizeX, uint32 inGroupSizeY, uint32 inGroupSizeZ) override;
  18. virtual ComputeBufferResult CreateComputeBuffer(ComputeBuffer::EType inType, uint64 inSize, uint inStride, const void *inData = nullptr) override;
  19. virtual ComputeQueueResult CreateComputeQueue() override;
  20. using CreateShader = ComputeShaderCPU::CreateShader;
  21. void RegisterShader(const char *inName, CreateShader inCreateShader)
  22. {
  23. mShaderRegistry[inName] = inCreateShader;
  24. }
  25. private:
  26. using ShaderRegistry = UnorderedMap<string_view, CreateShader>;
  27. ShaderRegistry mShaderRegistry;
  28. };
  29. // Internal helpers
  30. #define JPH_SHADER_WRAPPER_FUNCTION_NAME(name) RegisterShader##name
  31. #define JPH_SHADER_WRAPPER_FUNCTION(sys, name) void JPH_EXPORT JPH_SHADER_WRAPPER_FUNCTION_NAME(name)(ComputeSystemCPU *sys)
  32. /// Macro to declare a shader register function
  33. #define JPH_DECLARE_REGISTER_SHADER(name) namespace JPH { class ComputeSystemCPU; JPH_SHADER_WRAPPER_FUNCTION(, name); }
  34. /// Macro to register a shader
  35. #define JPH_REGISTER_SHADER(sys, name) JPH::JPH_SHADER_WRAPPER_FUNCTION_NAME(name)(sys)
  36. JPH_NAMESPACE_END
  37. #endif // JPH_USE_CPU_COMPUTE