KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rhi_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_bind_group.h>
23#include <rhi/rhi_command.h>
24#include <rhi/rhi_shader.h>
25#include <array>
26#include <cstddef>
27#include <cstdint>
28#include <functional>
29#include <vector>
30
32constexpr uint32_t RHI_SPEC_ID_WORKGROUP_X = 0;
33constexpr uint32_t RHI_SPEC_ID_WORKGROUP_Y = 1;
34constexpr uint32_t RHI_SPEC_ID_USER_FIRST = 2;
35
38{
39 uint32_t id;
40 uint32_t value;
41};
42
44{
46 std::vector<RHI_BIND_GROUP_LAYOUT_DESC> bindGroupLayouts;
47 std::vector<RHI_SPECIALIZATION_CONSTANT> constants;
48 uint32_t workgroupX = 8;
49 uint32_t workgroupY = 8;
50 uint32_t pushConstantBytes = 0;
51};
52
55
61
63{
64 std::array<uint32_t, 3> maxWorkgroupSize{};
66 std::array<uint32_t, 3> maxDispatchGroups{};
70};
71
77
84
91{
92public:
103
105 struct COMMAND
106 {
111 uint32_t index = 0;
112 uint32_t groupsX = 0;
113 uint32_t groupsY = 0;
114 size_t offset = 0;
115 size_t bytes = 0;
116 void* destination = nullptr;
117 std::vector<uint8_t> data{};
118 };
119
121 void Upload( RHI_BufferHandle aBuffer, const void* aData, size_t aBytes, size_t aOffset = 0 );
122 void Bind( RHI_ComputePipelineHandle aPipeline );
123 void BindGroup( uint32_t aIndex, RHI_BindGroupHandle aGroup );
124 void PushConstants( const void* aData, size_t aBytes );
125 void Dispatch( uint32_t aGroupsX, uint32_t aGroupsY = 1 );
126 void Barrier();
127 void Readback( RHI_BufferHandle aBuffer, size_t aOffset, size_t aBytes, void* aDestination );
128
129 bool IsValid() const { return m_valid; }
130 const std::vector<COMMAND>& Commands() const { return m_commands; }
131
132private:
133 bool m_valid = true;
134 std::vector<COMMAND> m_commands;
135};
136
137
140{
143 std::function<bool( RHI_BufferHandle, size_t aOffset, size_t aBytes )> storageRange;
144};
145
150bool RhiValidateComputeJob( const RHI_COMPUTE_JOB& aJob, const RHI_COMPUTE_DEVICE_LIMITS& aLimits,
151 const RHI_COMPUTE_JOB_LOOKUP& aLookup );
Plain owning command data, recordable on any thread without device access.
Definition rhi_compute.h:91
void Dispatch(uint32_t aGroupsX, uint32_t aGroupsY=1)
const std::vector< COMMAND > & Commands() const
void BindGroup(uint32_t aIndex, RHI_BindGroupHandle aGroup)
bool IsValid() const
void Readback(RHI_BufferHandle aBuffer, size_t aOffset, size_t aBytes, void *aDestination)
std::vector< COMMAND > m_commands
void Upload(RHI_BufferHandle aBuffer, const void *aData, size_t aBytes, size_t aOffset=0)
Copy upload bytes immediately.
void Bind(RHI_ComputePipelineHandle aPipeline)
void PushConstants(const void *aData, size_t aBytes)
#define OK
constexpr uint32_t RHI_SPEC_ID_USER_FIRST
Definition rhi_compute.h:34
RHI_COMPUTE_RESULT
Definition rhi_compute.h:79
bool RhiValidateComputeJob(const RHI_COMPUTE_JOB &aJob, const RHI_COMPUTE_DEVICE_LIMITS &aLimits, const RHI_COMPUTE_JOB_LOOKUP &aLookup)
Check a whole job against live resources before any of it executes, so a bad job has no partial effec...
bool RhiValidateComputePipelineDesc(const RHI_COMPUTE_PIPELINE_DESC &aDesc)
Validate the portable contract without accessing a GPU or inspecting shader bytecode.
constexpr uint32_t RHI_SPEC_ID_WORKGROUP_Y
Definition rhi_compute.h:33
constexpr uint32_t RHI_SPEC_ID_WORKGROUP_X
Specialization IDs reserved for the workgroup dimensions; Z is always one.
Definition rhi_compute.h:32
bool RhiValidateComputeBindGroupLayout(const RHI_BIND_GROUP_LAYOUT_DESC &aLayout)
Validate a compute bind group layout.
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
uint64_t minStorageBufferOffsetAlignment
Definition rhi_compute.h:69
std::array< uint32_t, 3 > maxWorkgroupSize
Definition rhi_compute.h:64
std::array< uint32_t, 3 > maxDispatchGroups
Definition rhi_compute.h:66
Backend command representation; payload bytes are owned by the job.
RHI_BufferHandle buffer
RHI_ComputePipelineHandle pipeline
std::vector< uint8_t > data
RHI_BindGroupHandle group
Backend lookups for RhiValidateComputeJob.
std::function< const RHI_BIND_GROUP_LAYOUT_DESC *(RHI_BindGroupHandle)> groupLayout
std::function< bool(RHI_BufferHandle, size_t aOffset, size_t aBytes)> storageRange
std::function< const RHI_COMPUTE_PIPELINE_DESC *(RHI_ComputePipelineHandle)> pipeline
std::vector< RHI_SPECIALIZATION_CONSTANT > constants
Definition rhi_compute.h:47
std::vector< RHI_BIND_GROUP_LAYOUT_DESC > bindGroupLayouts
Definition rhi_compute.h:46
RHI_SHADER_BLOB shader
Definition rhi_compute.h:45
One shader stage as GenerateShaderHeader.cmake embeds it.
Definition rhi_shader.h:46
A 32-bit specialization value represented as raw bits.
Definition rhi_compute.h:38