/src/skia/src/gpu/GrDrawIndirectCommand.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2021 Google Inc. |
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 GrDrawIndirectCommand_DEFINED |
9 | | #define GrDrawIndirectCommand_DEFINED |
10 | | |
11 | | #include <stdint.h> |
12 | | #include <utility> |
13 | | |
14 | | struct GrDrawIndirectCommand { |
15 | | uint32_t fVertexCount; |
16 | | uint32_t fInstanceCount; |
17 | | int32_t fBaseVertex; |
18 | | uint32_t fBaseInstance; |
19 | | }; |
20 | | |
21 | | static_assert(sizeof(GrDrawIndirectCommand) == 16, "GrDrawIndirectCommand must be tightly packed"); |
22 | | |
23 | | struct GrDrawIndexedIndirectCommand { |
24 | | uint32_t fIndexCount; |
25 | | uint32_t fInstanceCount; |
26 | | uint32_t fBaseIndex; |
27 | | int32_t fBaseVertex; |
28 | | uint32_t fBaseInstance; |
29 | | }; |
30 | | |
31 | | static_assert(sizeof(GrDrawIndexedIndirectCommand) == 20, |
32 | | "GrDrawIndexedIndirectCommand must be tightly packed"); |
33 | | |
34 | | // Helper for writing commands to an indirect draw buffer. Usage: |
35 | | // |
36 | | // GrDrawIndirectWriter indirectWriter = target->makeDrawIndirectSpace(...); |
37 | | // indirectWriter.write(...); |
38 | | // indirectWriter.write(...); |
39 | | struct GrDrawIndirectWriter { |
40 | | public: |
41 | | GrDrawIndirectWriter() = default; |
42 | 0 | GrDrawIndirectWriter(void* data) : fData(static_cast<GrDrawIndirectCommand*>(data)) {} |
43 | | GrDrawIndirectWriter(const GrDrawIndirectWriter&) = delete; |
44 | 0 | GrDrawIndirectWriter(GrDrawIndirectWriter&& that) { *this = std::move(that); } |
45 | | |
46 | | GrDrawIndirectWriter& operator=(const GrDrawIndirectWriter&) = delete; |
47 | 0 | GrDrawIndirectWriter& operator=(GrDrawIndirectWriter&& that) { |
48 | 0 | fData = that.fData; |
49 | 0 | that.fData = nullptr; |
50 | 0 | return *this; |
51 | 0 | } |
52 | | |
53 | 0 | bool operator==(const GrDrawIndirectWriter& that) { return fData == that.fData; } |
54 | | |
55 | 0 | operator bool() const { return fData != nullptr; } |
56 | | |
57 | 0 | GrDrawIndirectWriter makeOffset(int drawCount) const { return {fData + drawCount}; } |
58 | | |
59 | | inline void write(uint32_t instanceCount, uint32_t baseInstance, uint32_t vertexCount, |
60 | 0 | int32_t baseVertex) { |
61 | 0 | *fData++ = {vertexCount, instanceCount, baseVertex, baseInstance}; |
62 | 0 | } |
63 | | |
64 | | private: |
65 | | GrDrawIndirectCommand* fData; |
66 | | }; |
67 | | |
68 | | // Helper for writing commands to an indexed indirect draw buffer. Usage: |
69 | | // |
70 | | // GrDrawIndexedIndirectWriter indirectWriter = target->makeDrawIndexedIndirectSpace(...); |
71 | | // indirectWriter.writeIndexed(...); |
72 | | // indirectWriter.writeIndexed(...); |
73 | | struct GrDrawIndexedIndirectWriter { |
74 | | public: |
75 | | GrDrawIndexedIndirectWriter() = default; |
76 | | GrDrawIndexedIndirectWriter(void* data) |
77 | 0 | : fData(static_cast<GrDrawIndexedIndirectCommand*>(data)) {} |
78 | | GrDrawIndexedIndirectWriter(const GrDrawIndexedIndirectWriter&) = delete; |
79 | 0 | GrDrawIndexedIndirectWriter(GrDrawIndexedIndirectWriter&& that) { *this = std::move(that); } |
80 | | |
81 | | GrDrawIndexedIndirectWriter& operator=(const GrDrawIndexedIndirectWriter&) = delete; |
82 | 0 | GrDrawIndexedIndirectWriter& operator=(GrDrawIndexedIndirectWriter&& that) { |
83 | 0 | fData = that.fData; |
84 | 0 | that.fData = nullptr; |
85 | 0 | return *this; |
86 | 0 | } |
87 | | |
88 | 0 | bool operator==(const GrDrawIndexedIndirectWriter& that) { return fData == that.fData; } |
89 | | |
90 | 0 | operator bool() const { return fData != nullptr; } |
91 | | |
92 | 0 | GrDrawIndexedIndirectWriter makeOffset(int drawCount) const { return {fData + drawCount}; } |
93 | | |
94 | | inline void writeIndexed(uint32_t indexCount, uint32_t baseIndex, uint32_t instanceCount, |
95 | 0 | uint32_t baseInstance, int32_t baseVertex) { |
96 | 0 | *fData++ = {indexCount, instanceCount, baseIndex, baseVertex, baseInstance}; |
97 | 0 | } |
98 | | |
99 | | private: |
100 | | GrDrawIndexedIndirectCommand* fData; |
101 | | }; |
102 | | |
103 | | #endif |