// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) // SPDX-FileCopyrightText: 2025 Jorrit Rouwe // SPDX-License-Identifier: MIT #pragma once #ifdef JPH_USE_DX12 #include #include #include JPH_NAMESPACE_BEGIN class ComputeBufferDX12; /// A command queue for DirectX for executing compute workloads on the GPU. class JPH_EXPORT ComputeQueueDX12 final : public ComputeQueue { public: JPH_OVERRIDE_NEW_DELETE /// Destructor virtual ~ComputeQueueDX12() override; /// Initialize the queue bool Initialize(ID3D12Device *inDevice, D3D12_COMMAND_LIST_TYPE inType, ComputeQueueResult &outResult); /// Start the command list (requires waiting until the previous one is finished) ID3D12GraphicsCommandList * Start(); // See: ComputeQueue virtual void SetShader(const ComputeShader *inShader) override; virtual void SetConstantBuffer(const char *inName, const ComputeBuffer *inBuffer) override; virtual void SetBuffer(const char *inName, const ComputeBuffer *inBuffer) override; virtual void SetRWBuffer(const char *inName, ComputeBuffer *inBuffer, EBarrier inBarrier = EBarrier::Yes) override; virtual void ScheduleReadback(ComputeBuffer *inDst, const ComputeBuffer *inSrc) override; virtual void Dispatch(uint inThreadGroupsX, uint inThreadGroupsY, uint inThreadGroupsZ) override; virtual void Execute() override; virtual void Wait() override; private: /// Copy the CPU buffer to the GPU buffer if needed void SyncCPUToGPU(const ComputeBufferDX12 *inBuffer); ComPtr mCommandQueue; ///< The command queue that will hold command lists ComPtr mCommandAllocator; ///< Allocator that holds the memory for the commands ComPtr mCommandList; ///< The command list that will hold the render commands / state changes HANDLE mFenceEvent = INVALID_HANDLE_VALUE; ///< Fence event, used to wait for rendering to complete ComPtr mFence; ///< Fence object, used to signal the fence event UINT64 mFenceValue = 0; ///< Current fence value, each time we need to wait we will signal the fence with this value, wait for it and then increase the value RefConst mShader = nullptr; ///< Current active shader bool mIsStarted = false; ///< If the command list has been started (reset) and is ready to record commands bool mIsExecuting = false; ///< If a command list is currently executing on the queue UnorderedSet> mUsedBuffers; ///< Buffers that are in use by the current execution, these will be retained until execution is finished so that we don't free buffers that are in use Array> mDelayedFreedBuffers; ///< Buffers freed during the execution }; JPH_NAMESPACE_END #endif // JPH_USE_DX12