Flutter Engine
The Flutter Engine
Functions
GrVkUniformHandler.cpp File Reference
#include "src/gpu/ganesh/vk/GrVkUniformHandler.h"
#include "src/gpu/ganesh/GrTexture.h"
#include "src/gpu/ganesh/GrUtil.h"
#include "src/gpu/ganesh/glsl/GrGLSLProgramBuilder.h"
#include "src/gpu/ganesh/vk/GrVkGpu.h"
#include "src/gpu/ganesh/vk/GrVkPipelineStateBuilder.h"
#include "src/gpu/ganesh/vk/GrVkTexture.h"

Go to the source code of this file.

Functions

static uint32_t sksltype_to_alignment_mask (SkSLType type)
 
static uint32_t sksltype_to_vk_size (SkSLType type, int layout)
 
static uint32_t get_aligned_offset (uint32_t *currentOffset, SkSLType type, int arrayCount, int layout)
 

Function Documentation

◆ get_aligned_offset()

static uint32_t get_aligned_offset ( uint32_t *  currentOffset,
SkSLType  type,
int  arrayCount,
int  layout 
)
static

Definition at line 165 of file GrVkUniformHandler.cpp.

168 {
169 uint32_t alignmentMask = sksltype_to_alignment_mask(type);
170 // For std140 layout we must make arrays align to 16 bytes.
171 // TODO(skia:13380): make sure 2x3 and 3x2 matrices are handled properly once SkSLType adds
172 // support for non-square matrices
173 if (layout == GrVkUniformHandler::kStd140Layout &&
174 (arrayCount || type == SkSLType::kFloat2x2 || type == SkSLType::kHalf2x2)) {
175 alignmentMask = 0xF;
176 }
177 uint32_t offsetDiff = *currentOffset & alignmentMask;
178 if (offsetDiff != 0) {
179 offsetDiff = alignmentMask - offsetDiff + 1;
180 }
181 int32_t uniformOffset = *currentOffset + offsetDiff;
182 SkASSERT(sizeof(float) == 4);
183 if (arrayCount) {
184 // TODO: this shouldn't be necessary for std430
185 uint32_t elementSize = std::max<uint32_t>(16, sksltype_to_vk_size(type, layout));
186 SkASSERT(0 == (elementSize & 0xF));
187 *currentOffset = uniformOffset + elementSize * arrayCount;
188 } else {
189 *currentOffset = uniformOffset + sksltype_to_vk_size(type, layout);
190 }
191 return uniformOffset;
192}
static uint32_t sksltype_to_vk_size(SkSLType type, int layout)
static uint32_t sksltype_to_alignment_mask(SkSLType type)
#define SkASSERT(cond)
Definition: SkAssert.h:116
GLenum type

◆ sksltype_to_alignment_mask()

static uint32_t sksltype_to_alignment_mask ( SkSLType  type)
static

Definition at line 25 of file GrVkUniformHandler.cpp.

25 {
26 switch(type) {
27 case SkSLType::kShort: // fall through
29 return 0x1;
30 case SkSLType::kShort2: // fall through
32 return 0x3;
33 case SkSLType::kShort3: // fall through
37 return 0x7;
38 case SkSLType::kInt:
39 case SkSLType::kUInt:
40 return 0x3;
41 case SkSLType::kInt2:
43 return 0x7;
44 case SkSLType::kInt3:
46 case SkSLType::kInt4:
48 return 0xF;
49 case SkSLType::kHalf: // fall through
51 return 0x3;
52 case SkSLType::kHalf2: // fall through
54 return 0x7;
55 case SkSLType::kHalf3: // fall through
57 return 0xF;
58 case SkSLType::kHalf4: // fall through
60 return 0xF;
61 case SkSLType::kHalf2x2: // fall through
63 return 0x7;
64 case SkSLType::kHalf3x3: // fall through
66 return 0xF;
67 case SkSLType::kHalf4x4: // fall through
69 return 0xF;
70
71 // This query is only valid for certain types.
72 case SkSLType::kVoid:
73 case SkSLType::kBool:
83 break;
84 }
85 SK_ABORT("Unexpected type");
86}
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
@ kTextureExternalSampler
@ kTexture2DSampler
@ kTexture2DRectSampler

◆ sksltype_to_vk_size()

static uint32_t sksltype_to_vk_size ( SkSLType  type,
int  layout 
)
inlinestatic

Returns the size in bytes taken up in vulkanbuffers for SkSLTypes.

Definition at line 89 of file GrVkUniformHandler.cpp.

89 {
90 switch(type) {
92 return sizeof(int16_t);
94 return 2 * sizeof(int16_t);
96 return 3 * sizeof(int16_t);
98 return 4 * sizeof(int16_t);
100 return sizeof(uint16_t);
102 return 2 * sizeof(uint16_t);
104 return 3 * sizeof(uint16_t);
106 return 4 * sizeof(uint16_t);
107 case SkSLType::kHalf: // fall through
108 case SkSLType::kFloat:
109 return sizeof(float);
110 case SkSLType::kHalf2: // fall through
112 return 2 * sizeof(float);
113 case SkSLType::kHalf3: // fall through
115 return 3 * sizeof(float);
116 case SkSLType::kHalf4: // fall through
118 return 4 * sizeof(float);
119 case SkSLType::kInt: // fall through
120 case SkSLType::kUInt:
121 return sizeof(int32_t);
122 case SkSLType::kInt2: // fall through
123 case SkSLType::kUInt2:
124 return 2 * sizeof(int32_t);
125 case SkSLType::kInt3: // fall through
126 case SkSLType::kUInt3:
127 return 3 * sizeof(int32_t);
128 case SkSLType::kInt4: // fall through
129 case SkSLType::kUInt4:
130 return 4 * sizeof(int32_t);
131 case SkSLType::kHalf2x2: // fall through
133 if (layout == GrVkUniformHandler::kStd430Layout) {
134 return 4 * sizeof(float);
135 } else {
136 return 8 * sizeof(float);
137 }
138 case SkSLType::kHalf3x3: // fall through
140 return 12 * sizeof(float);
141 case SkSLType::kHalf4x4: // fall through
143 return 16 * sizeof(float);
144
145 // This query is only valid for certain types.
146 case SkSLType::kVoid:
147 case SkSLType::kBool:
148 case SkSLType::kBool2:
149 case SkSLType::kBool3:
150 case SkSLType::kBool4:
156 case SkSLType::kInput:
157 break;
158 }
159 SK_ABORT("Unexpected type");
160}