2
0

ComputeSystemVK.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/ComputeSystem.h>
  6. #ifdef JPH_USE_VK
  7. #include <Jolt/Compute/VK/ComputeQueueVK.h>
  8. JPH_NAMESPACE_BEGIN
  9. /// Interface to run a workload on the GPU using Vulkan.
  10. /// Minimal implementation that can integrate with your own Vulkan setup.
  11. class JPH_EXPORT ComputeSystemVK : public ComputeSystem
  12. {
  13. public:
  14. JPH_DECLARE_RTTI_ABSTRACT(JPH_EXPORT, ComputeSystemVK)
  15. // Initialize / shutdown the compute system
  16. bool Initialize(VkPhysicalDevice inPhysicalDevice, VkDevice inDevice, uint32 inComputeQueueIndex, ComputeSystemResult &outResult);
  17. void Shutdown();
  18. // See: ComputeSystem
  19. virtual ComputeShaderResult CreateComputeShader(const char *inName, uint32 inGroupSizeX, uint32 inGroupSizeY, uint32 inGroupSizeZ) override;
  20. virtual ComputeBufferResult CreateComputeBuffer(ComputeBuffer::EType inType, uint64 inSize, uint inStride, const void *inData = nullptr) override;
  21. virtual ComputeQueueResult CreateComputeQueue() override;
  22. /// Access to the Vulkan device
  23. VkDevice GetDevice() const { return mDevice; }
  24. /// Allow the application to override buffer creation and memory mapping in case it uses its own allocator
  25. virtual bool CreateBuffer(VkDeviceSize inSize, VkBufferUsageFlags inUsage, VkMemoryPropertyFlags inProperties, BufferVK &outBuffer) = 0;
  26. virtual void FreeBuffer(BufferVK &ioBuffer) = 0;
  27. virtual void * MapBuffer(BufferVK &ioBuffer) = 0;
  28. virtual void UnmapBuffer(BufferVK &ioBuffer) = 0;
  29. protected:
  30. /// Initialize / shutdown the memory subsystem
  31. virtual bool InitializeMemory() = 0;
  32. virtual void ShutdownMemory() = 0;
  33. VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE;
  34. VkDevice mDevice = VK_NULL_HANDLE;
  35. uint32 mComputeQueueIndex = 0;
  36. PFN_vkSetDebugUtilsObjectNameEXT mVkSetDebugUtilsObjectNameEXT = nullptr;
  37. private:
  38. // Buffer that can be bound when we have no buffer
  39. BufferVK mDummyBuffer;
  40. };
  41. JPH_NAMESPACE_END
  42. #endif // JPH_USE_VK