32std::tuple<UniquePaintParamsID, const UniformDataBlock*, const TextureDataBlock*>
ExtractPaintData(
37 const SkM44& local2Dev,
54 std::move(dstTexture),
56 p.toKey(keyContext,
builder, gatherer);
72 return { paintID, uniforms, textures };
83 step->writeUniformsAndTextures(
params, gatherer);
92 return { uniforms, textures };
96 std::optional<SkBlendMode> blendMode,
118std::string get_uniform_header(
int bufferID,
const char*
name) {
126std::string get_uniforms(
Layout layout,
130 bool* wrotePaintColor) {
132 UniformOffsetCalculator offsetter(layout, *
offset);
134 std::string uniformName;
135 for (
const Uniform& u : uniforms) {
136 uniformName = u.name();
138 if (u.isPaintColor() && wrotePaintColor) {
139 if (*wrotePaintColor) {
144 *wrotePaintColor =
true;
146 if (manglingSuffix >= 0) {
147 uniformName.append(
"_");
153 " layout(offset=%d) %s %s",
154 offsetter.advanceOffset(u.type(), u.count()),
156 uniformName.c_str());
165 *
offset = offsetter.size();
169std::string get_node_uniforms(
Layout layout,
170 const ShaderNode* node,
173 bool* wrotePaintColor) {
177 if (!uniforms.
empty()) {
179 node->keyIndex(), node->entry()->fName);
180 result += get_uniforms(layout, uniforms,
offset, node->keyIndex(), wrotePaintColor);
183 *numUniforms += uniforms.
size();
184 for (
const ShaderNode* child : node->children()) {
185 result += get_node_uniforms(layout, child,
offset, numUniforms, wrotePaintColor);
192 bool* wrotePaintColor) {
195 std::string uniformName;
196 for (
const Uniform& u : uniforms) {
197 uniformName = u.name();
199 if (u.isPaintColor() && wrotePaintColor) {
200 if (*wrotePaintColor) {
205 *wrotePaintColor =
true;
207 if (manglingSuffix >= 0) {
208 uniformName.append(
"_");
223std::string get_node_ssbo_fields(
const ShaderNode* node,
int* numUniforms,
bool* wrotePaintColor) {
227 if (!uniforms.
empty()) {
229 node->keyIndex(), node->entry()->fName);
231 result += get_ssbo_fields(uniforms, node->keyIndex(), wrotePaintColor);
234 *numUniforms += uniforms.
size();
235 for (
const ShaderNode* child : node->children()) {
236 result += get_node_ssbo_fields(child, numUniforms, wrotePaintColor);
241std::string get_node_texture_samplers(
const ResourceBindingRequirements& bindingReqs,
242 const ShaderNode* node,
247 if (!samplers.
empty()) {
249 node->keyIndex(), node->entry()->fName);
251 for (
const TextureAndSampler& t : samplers) {
254 t.name(), node->keyIndex());
258 for (
const ShaderNode* child : node->children()) {
259 result += get_node_texture_samplers(bindingReqs, child, binding);
270 int* uniformsTotalBytes,
271 bool* wrotePaintColor) {
274 std::string
result = get_uniform_header(bufferID,
"FS");
276 result += get_node_uniforms(layout, n, &
offset, numUniforms, wrotePaintColor);
285 if (uniformsTotalBytes) {
286 *uniformsTotalBytes =
offset;
295 int* renderStepUniformsTotalBytes) {
298 std::string
result = get_uniform_header(bufferID,
"Step");
299 result += get_uniforms(layout, uniforms, &
offset, -1,
nullptr);
302 if (renderStepUniformsTotalBytes) {
303 *renderStepUniformsTotalBytes =
offset;
313 bool* wrotePaintColor) {
316 result +=
"struct FSUniformData {\n";
318 result += get_node_ssbo_fields(n, numUniforms, wrotePaintColor);
328 "layout (binding=%d) readonly buffer FSUniforms {\n"
329 " FSUniformData fsUniformData[];\n"
340 result +=
"struct StepUniformData {\n" +
341 get_ssbo_fields(uniforms, -1,
nullptr) +
345 "layout (binding=%d) readonly buffer StepUniforms {\n"
346 " StepUniformData stepUniformData[];\n"
353 const char* ssboIndex,
357 for (
const Uniform& u : uniforms) {
363 &
result,
" = %sUniformData[%s].%s;\n", bufferNamePrefix, ssboIndex, u.name());
370 const char* ssboIndex,
371 const char* uniformName) {
380 result += get_node_texture_samplers(bindingReqs, n, binding);
394 int samplerIndex = (*binding)++;
395 int textureIndex = (*binding)++;
401 int samplerIndex = (*binding)++;
416 for (
auto a : attrs) {
423 if (!vertexAttrs.
empty()) {
424 result.append(
"// vertex attrs\n");
425 add_attrs(vertexAttrs);
427 if (!instanceAttrs.
empty()) {
428 result.append(
"// instance attrs\n");
429 add_attrs(instanceAttrs);
437 const char* direction,
438 bool emitSsboIndicesVarying,
439 bool emitLocalCoordsVarying) {
443 if (emitSsboIndicesVarying) {
445 " layout(location=%d) %s flat ushort2 %s;\n",
451 if (emitLocalCoordsVarying) {
457 for (
auto v :
step->varyings()) {
468 bool useStorageBuffers,
469 bool defineLocalCoordsVarying) {
472 const bool hasStepUniforms =
step->numUniforms() > 0;
473 const bool useStepStorageBuffer = useStorageBuffers && hasStepUniforms;
474 const bool useShadingStorageBuffer = useStorageBuffers &&
step->performsShading();
486 "layout (binding=0) uniform intrinsicUniforms {\n"
487 " layout(offset=0) float4 rtAdjust;\n"
491 if (
step->numVertexAttributes() > 0 ||
step->numInstanceAttributes() > 0) {
492 sksl += emit_attributes(
step->vertexAttributes(),
step->instanceAttributes());
498 if (hasStepUniforms) {
499 if (useStepStorageBuffer) {
505 &
result.fRenderStepUniformsTotalBytes);
510 sksl +=
EmitVaryings(
step,
"out", useShadingStorageBuffer, defineLocalCoordsVarying);
513 sksl +=
"void main() {";
515 sksl +=
"float2 stepLocalCoords = float2(0);";
517 if (useStepStorageBuffer) {
525 sksl +=
step->vertexSkSL();
526 sksl +=
"sk_Position = float4(devPosition.xy * rtAdjust.xy + devPosition.ww * rtAdjust.zw,"
529 if (useShadingStorageBuffer) {
537 if (defineLocalCoordsVarying) {
539 sksl +=
"localCoordsVar = stepLocalCoords;";
543 result.fSkSL = std::move(sksl);
545 if (defineLocalCoordsVarying) {
546 result.fLabel +=
" (w/ local coords)";
557 bool useStorageBuffers,
565 const char* shadingSsboIndex =
566 useStorageBuffers &&
step->performsShading() ?
"shadingSsboIndex" :
nullptr;
567 ShaderInfo shaderInfo(paintID, dict, rteDict, shadingSsboIndex);
569 result.fSkSL = shaderInfo.toSkSL(caps,
572 &
result.fNumTexturesAndSamplers,
573 &
result.fNumPaintUniforms,
574 &
result.fRenderStepUniformsTotalBytes,
575 &
result.fPaintUniformsTotalBytes,
576 &
result.fHasGradientBuffer,
581 result.fBlendInfo = shaderInfo.blendInfo();
582 result.fRequiresLocalCoords = shaderInfo.needsLocalCoords();
583 result.fData = {shaderInfo.data()};
599 label += renderStep->
name();
608 step->localDispatchSize().fWidth,
609 step->localDispatchSize().fHeight,
610 step->localDispatchSize().fDepth);
614 bool separateSampler = bindingReqs.fSeparateTextureAndSamplerBinding;
627 case Type::kUniformBuffer:
631 case Type::kStorageBuffer:
632 case Type::kIndirectBuffer:
636 case Type::kReadOnlyStorageBuffer:
640 case Type::kWriteOnlyStorageTexture:
642 distinctRanges ? texIdx++ : index++);
645 case Type::kReadOnlyTexture:
647 distinctRanges ? texIdx++ : index++);
650 case Type::kSampledTexture:
651 if (distinctRanges) {
653 }
else if (separateSampler) {
655 &sksl,
"layout(webgpu, sampler=%d, texture=%d) ", index, index + 1);
660 sksl +=
"sampler2D ";
667 sksl +=
step->computeSkSL();
static int step(int x, SkScalar min, SkScalar max)
@ kLastCoeffMode
last porter duff blend mode
@ kSrcOver
r = s + (1-sa)*d
static bool isLCD(const SkScalerContextRec &rec)
const char * SkSLTypeString(SkSLType t)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
constexpr bool empty() const
constexpr size_t size() const
const char * c_str() const
SkString asString() const
const ResourceBindingRequirements & resourceBindingRequirements() const
DstReadRequirement getDstReadRequirement() const
const SkSL::ShaderCaps * shaderCaps() const
bool isEdgeAAQuad() const
const T * insert(const T &dataBlock)
void resetWithNewLayout(Layout layout)
UniformDataBlock finishUniformDataBlock()
const TextureDataBlock & textureDataBlock()
const ShaderCodeDictionary * shaderCodeDictionary() const
TextureDataCache * textureDataCache()
UniformDataCache * uniformDataCache()
static const char * ssboIndicesAttribute()
const char * name() const
static const char * ssboIndicesVarying()
UniquePaintParamsID findOrCreate(PaintParamsKeyBuilder *) SK_EXCLUDES(fSpinLock)
SkString idToString(UniquePaintParamsID id) const
const EmbeddedViewParams * params
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
std::string void appendf(std::string *str, const char *fmt,...) SK_PRINTF_LIKE(2
DEF_SWITCHES_START aot vmservice shared library name
VertSkSLInfo BuildVertexSkSL(const ResourceBindingRequirements &bindingReqs, const RenderStep *step, bool useStorageBuffers, bool defineLocalCoordsVarying)
std::string EmitPaintParamsUniforms(int bufferID, const Layout layout, SkSpan< const ShaderNode * > nodes, int *numUniforms, int *uniformsTotalBytes, bool *wrotePaintColor)
std::string BuildComputeSkSL(const Caps *caps, const ComputeStep *step)
std::string EmitStorageBufferAccess(const char *bufferNamePrefix, const char *ssboIndex, const char *uniformName)
DstReadRequirement GetDstReadRequirement(const Caps *caps, std::optional< SkBlendMode > blendMode, Coverage coverage)
std::string EmitTexturesAndSamplers(const ResourceBindingRequirements &bindingReqs, SkSpan< const ShaderNode * > nodes, int *binding)
FragSkSLInfo BuildFragmentSkSL(const Caps *caps, const ShaderCodeDictionary *dict, const RuntimeEffectDictionary *rteDict, const RenderStep *step, UniquePaintParamsID paintID, bool useStorageBuffers, skgpu::Swizzle writeSwizzle)
std::string GetPipelineLabel(const ShaderCodeDictionary *dict, const RenderPassDesc &renderPassDesc, const RenderStep *renderStep, UniquePaintParamsID paintID)
std::string EmitRenderStepStorageBuffer(int bufferID, SkSpan< const Uniform > uniforms)
std::string EmitRenderStepUniforms(int bufferID, const Layout layout, SkSpan< const Uniform > uniforms, int *renderStepUniformsTotalBytes)
std::string EmitVaryings(const RenderStep *step, const char *direction, bool emitSsboIndicesVarying, bool emitLocalCoordsVarying)
std::string EmitPaintParamsStorageBuffer(int bufferID, SkSpan< const ShaderNode * > nodes, int *numUniforms, bool *wrotePaintColor)
std::tuple< const UniformDataBlock *, const TextureDataBlock * > ExtractRenderStepData(UniformDataCache *uniformDataCache, TextureDataCache *textureDataCache, PipelineDataGatherer *gatherer, const Layout layout, const RenderStep *step, const DrawParams ¶ms)
std::string EmitSamplerLayout(const ResourceBindingRequirements &bindingReqs, int *binding)
std::tuple< UniquePaintParamsID, const UniformDataBlock *, const TextureDataBlock * > ExtractPaintData(Recorder *recorder, PipelineDataGatherer *gatherer, PaintParamsKeyBuilder *builder, const Layout layout, const SkM44 &local2Dev, const PaintParams &p, const Geometry &geometry, sk_sp< TextureProxy > dstTexture, SkIPoint dstOffset, const SkColorInfo &targetColorInfo)
std::string EmitUniformsFromStorageBuffer(const char *bufferNamePrefix, const char *ssboIndex, SkSpan< const Uniform > uniforms)
BlendFormula GetBlendFormula(bool isOpaque, bool hasCoverage, SkBlendMode xfermode)
BlendFormula GetLCDBlendFormula(SkBlendMode xfermode)
static SkString to_string(int n)
bool fDualSourceBlendingSupport
SkString toPipelineLabel() const
Layout fUniformBufferLayout
bool fDistinctIndexRanges
bool fSeparateTextureAndSamplerBinding