• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/gpu/graphite/ResourceTypes.h"
12 
13 namespace skgpu::graphite {
14 
15 // The maximum number of shared resource binding slots permitted for ComputeSteps of a DispatchGroup
16 constexpr int kMaxComputeDataFlowSlots = 16;
17 
18 /**
19  * Defines the space that a compute shader operates on. A problem space is logically divided into
20  * abstract "work groups" (or "thread groups" in Metal/D3D12).
21  *
22  * The "work group count" or "global size" of the work group is a 3-dimensional number that defines
23  * the size of the problem space. The user must provide the global size to define the number of
24  * work groups that execute as part of a dispatch.
25  *
26  * The local size of a work group defines the number of parallel execution units that run in that
27  * group. The local group size is defined in terms of the "raw number of threads" that run within
28  * the group.
29  *
30  * A local group is further divided into fixed-sized SIMD units called "subgroups" (in Vulkan
31  * terminology - these are referred to as "SIMD groups"/"threads" in Metal, "wavefronts" in OpenCL,
32  * "warps" in CUDA).
33  *
34  * The local size is defined in 3 dimensions and must be determined based on hardware limitations,
35  * which can be queried via Caps::maxComputeWorkgroupSize() (for each individual dimension) and
36  * Caps::maxComputeInvocationsPerWorkgroup().
37  *
38  * The WorkgroupSize type is used to represent both global size and local size.
39  */
40 struct WorkgroupSize {
41     WorkgroupSize() = default;
WorkgroupSizeWorkgroupSize42     WorkgroupSize(uint32_t width, uint32_t height, uint32_t depth)
43             : fWidth(width)
44             , fHeight(height)
45             , fDepth(depth) {}
46 
47     uint32_t fWidth = 1;
48     uint32_t fHeight = 1;
49     uint32_t fDepth = 1;
50 };
51 
52 struct ComputePassDesc {
53     WorkgroupSize fGlobalDispatchSize;
54 
55     // TODO(b/240615224): On OpenGL D3D, and Vulkan 1.0, the local work group size is expressed with
56     // literals in the shading language and is tied to the pipeline state. On those platforms, we
57     // could either:
58     //
59     //     1. Defer pipeline creation until `fLocalDispatchSize` is known for a particular compute
60     //     pass and build the shader text using this value, or
61     //     2. Hard-code reasonable defaults within GPU capabilities and disregard
62     //     `fLocalDispatchSize`.
63     //
64     // The local size is a function of both the number of supported hardware threads AND how the
65     // problem is divided between the global and local sizes. Which approach is more optimal depends
66     // on the problem.
67     WorkgroupSize fLocalDispatchSize;
68 };
69 
70 // TODO(armansito): These types aren't specific to compute and could share definitions with render
71 // pipeline stack.
72 using BindingIndex = uint32_t;
73 
74 struct ResourceBinding {
75     BindingIndex fIndex;
76     BindBufferInfo fBuffer;
77 };
78 
79 }  // namespace skgpu::graphite
80 
81 #endif  // skgpu_graphite_ComputeTypes_DEFINED
82