KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gpu_compute.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <rhi/rhi_compute.h>
23#include <atomic>
24#include <memory>
25#include <mutex>
26
27class RHI_DEVICE;
28
34{
35public:
37 static std::shared_ptr<GPU_COMPUTE> Get();
39
40 GPU_COMPUTE( const GPU_COMPUTE& ) = delete;
41 GPU_COMPUTE& operator=( const GPU_COMPUTE& ) = delete;
42
49 void DestroyBuffer( RHI_BufferHandle aBuffer );
53
56
57private:
58 explicit GPU_COMPUTE( std::unique_ptr<RHI_DEVICE> aDevice );
59
61 template <typename F>
62 void destroy( F aDestroy );
63
64 std::mutex m_mutex;
65 std::unique_ptr<RHI_DEVICE> m_device;
67 std::atomic<bool> m_lost{ false };
68};
void DestroyBindGroupLayout(RHI_BindGroupLayoutHandle aLayout)
GPU_COMPUTE(const GPU_COMPUTE &)=delete
GPU_COMPUTE & operator=(const GPU_COMPUTE &)=delete
RHI_ComputePipelineHandle CreatePipeline(const RHI_COMPUTE_PIPELINE_DESC &aDesc)
RHI_COMPUTE_RESULT Submit(const RHI_COMPUTE_JOB &aJob)
Run the whole job and copy its readbacks before returning.
static std::shared_ptr< GPU_COMPUTE > Get()
Return nullptr if compute is unavailable; replace a lost instance on the next call.
void DestroyPipeline(RHI_ComputePipelineHandle aPipeline)
const RHI_COMPUTE_DEVICE_LIMITS & DeviceLimits() const
Definition gpu_compute.h:43
std::atomic< bool > m_lost
Definition gpu_compute.h:67
std::mutex m_mutex
Definition gpu_compute.h:64
RHI_COMPUTE_DEVICE_LIMITS m_limits
Definition gpu_compute.h:66
RHI_BindGroupLayoutHandle CreateBindGroupLayout(const RHI_BIND_GROUP_LAYOUT_DESC &aDesc)
std::unique_ptr< RHI_DEVICE > m_device
Definition gpu_compute.h:65
void DestroyBuffer(RHI_BufferHandle aBuffer)
RHI_COMPUTE_PIPELINE_LIMITS PipelineLimits(RHI_ComputePipelineHandle aPipeline)
void DestroyBindGroup(RHI_BindGroupHandle aGroup)
RHI_BindGroupHandle CreateBindGroup(const RHI_BIND_GROUP_DESC &aDesc)
RHI_BufferHandle CreateStorageBuffer(size_t aBytes)
void destroy(F aDestroy)
Destroy under the lock, then retire the release at once since no job can still be using it.
Plain owning command data, recordable on any thread without device access.
Definition rhi_compute.h:91
Creates, uses and destroys GPU resources through one graphics API backend.
Definition rhi_device.h:66
#define F(x, y, z)
Definition md5_hash.cpp:15
RHI_COMPUTE_RESULT
Definition rhi_compute.h:79
RHI_HANDLE< RHI_TAG_BUFFER > RHI_BufferHandle
Definition rhi_handle.h:83
RHI_HANDLE< RHI_TAG_BIND_GROUP > RHI_BindGroupHandle
Definition rhi_handle.h:90
RHI_HANDLE< RHI_TAG_COMPUTE_PIPELINE > RHI_ComputePipelineHandle
Definition rhi_handle.h:87
RHI_HANDLE< RHI_TAG_BIND_GROUP_LAYOUT > RHI_BindGroupLayoutHandle
Definition rhi_handle.h:89