| 1 |
/* |
| 2 |
* Copyright 2022 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef skgpu_graphite_ComputeTypes_DEFINED |
| 9 |
#define skgpu_graphite_ComputeTypes_DEFINED |
| 10 |
|
| 11 |
#include <cstddef> |
| 12 |
#include <cstdint> |
| 13 |
|
| 14 |
namespace skgpu::graphite { |
| 15 |
|
| 16 |
// The maximum number of shared resource binding slots permitted for ComputeSteps of a DispatchGroup |
| 17 |
constexpr int kMaxComputeDataFlowSlots = 28; |
| 18 |
|
| 19 |
// The minimum element stride of an indirect dispatch argument array in bytes |
| 20 |
struct IndirectDispatchArgs { |
| 21 |
uint32_t global_size_x; |
| 22 |
uint32_t global_size_y; |
| 23 |
uint32_t global_size_z; |
| 24 |
}; |
| 25 |
constexpr size_t kIndirectDispatchArgumentSize = sizeof(IndirectDispatchArgs); |
| 26 |
|
| 27 |
/** |
| 28 |
* Defines the space that a compute shader operates on. A problem space is logically divided into |
| 29 |
* abstract "work groups" (or "thread groups" in Metal/D3D12). |
| 30 |
* |
| 31 |
* The "work group count" or "global size" of the work group is a 3-dimensional number that defines |
| 32 |
* the size of the problem space. The user must provide the global size to define the number of |
| 33 |
* work groups that execute as part of a dispatch. |
| 34 |
* |
| 35 |
* The local size of a work group defines the number of parallel execution units that run in that |
| 36 |
* group. The local group size is defined in terms of the "raw number of threads" that run within |
| 37 |
* the group. |
| 38 |
* |
| 39 |
* A local group is further divided into fixed-sized SIMD units called "subgroups" (in Vulkan |
| 40 |
* terminology - these are referred to as "SIMD groups"/"threads" in Metal, "wavefronts" in OpenCL, |
| 41 |
* "warps" in CUDA). |
| 42 |
* |
| 43 |
* The local size is defined in 3 dimensions and must be determined based on hardware limitations, |
| 44 |
* which can be queried via Caps::maxComputeWorkgroupSize() (for each individual dimension) and |
| 45 |
* Caps::maxComputeInvocationsPerWorkgroup(). |
| 46 |
* |
| 47 |
* The WorkgroupSize type is used to represent both global size and local size. |
| 48 |
*/ |
| 49 |
struct WorkgroupSize { |
| 50 |
WorkgroupSize() = default; |
| 51 |
WorkgroupSize(uint32_t width, uint32_t height, uint32_t depth) |
| 52 |
: fWidth(width) |
| 53 |
, fHeight(height) |
| 54 |
, fDepth(depth) {} |
| 55 |
|
| 56 |
uint32_t scalarSize() const { return fWidth * fHeight * fDepth; } |
| 57 |
|
| 58 |
uint32_t fWidth = 1; |
| 59 |
uint32_t fHeight = 1; |
| 60 |
uint32_t fDepth = 1; |
| 61 |
}; |
| 62 |
|
| 63 |
} // namespace skgpu::graphite |
| 64 |
|
| 65 |
#endif // skgpu_graphite_ComputeTypes_DEFINED |