Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Enumerations | Functions | Variables
GrProgramDesc.cpp File Reference
#include "src/gpu/ganesh/GrProgramDesc.h"
#include "include/private/base/SkTo.h"
#include "src/core/SkChecksum.h"
#include "src/gpu/KeyBuilder.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrFragmentProcessor.h"
#include "src/gpu/ganesh/GrGeometryProcessor.h"
#include "src/gpu/ganesh/GrPipeline.h"
#include "src/gpu/ganesh/GrProcessor.h"
#include "src/gpu/ganesh/GrProgramInfo.h"
#include "src/gpu/ganesh/GrRenderTarget.h"
#include "src/gpu/ganesh/GrShaderCaps.h"
#include "src/gpu/ganesh/GrTexture.h"
#include "src/gpu/ganesh/effects/GrTextureEffect.h"
#include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h"

Go to the source code of this file.

Enumerations

enum  { kSamplerOrImageTypeKeyBits = 4 }
 

Functions

static uint16_t texture_type_key (GrTextureType type)
 
static uint32_t sampler_key (GrTextureType textureType, const skgpu::Swizzle &swizzle, const GrCaps &caps)
 
static void add_geomproc_sampler_keys (skgpu::KeyBuilder *b, const GrGeometryProcessor &geomProc, const GrCaps &caps)
 
static void gen_geomproc_key (const GrGeometryProcessor &geomProc, const GrCaps &caps, skgpu::KeyBuilder *b)
 
static void gen_xp_key (const GrXferProcessor &xp, const GrCaps &caps, const GrPipeline &pipeline, skgpu::KeyBuilder *b)
 
static void gen_fp_key (const GrFragmentProcessor &fp, const GrCaps &caps, skgpu::KeyBuilder *b)
 
static void gen_key (skgpu::KeyBuilder *b, const GrProgramInfo &programInfo, const GrCaps &caps)
 

Variables

static constexpr uint32_t kClassIDBits = 8
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSamplerOrImageTypeKeyBits 

Definition at line 25 of file GrProgramDesc.cpp.

25 {
27};
@ kSamplerOrImageTypeKeyBits

Function Documentation

◆ add_geomproc_sampler_keys()

static void add_geomproc_sampler_keys ( skgpu::KeyBuilder b,
const GrGeometryProcessor geomProc,
const GrCaps caps 
)
static

Definition at line 59 of file GrProgramDesc.cpp.

61 {
62 int numTextureSamplers = geomProc.numTextureSamplers();
63 b->add32(numTextureSamplers, "ppNumSamplers");
64 for (int i = 0; i < numTextureSamplers; ++i) {
65 const GrGeometryProcessor::TextureSampler& sampler = geomProc.textureSampler(i);
66 const GrBackendFormat& backendFormat = sampler.backendFormat();
67
68 uint32_t samplerKey = sampler_key(backendFormat.textureType(), sampler.swizzle(), caps);
69 b->add32(samplerKey);
70
71 caps.addExtraSamplerKey(b, sampler.samplerState(), backendFormat);
72 }
73}
static uint32_t sampler_key(GrTextureType textureType, const skgpu::Swizzle &swizzle, const GrCaps &caps)
GrTextureType textureType() const
virtual void addExtraSamplerKey(skgpu::KeyBuilder *, GrSamplerState, const GrBackendFormat &) const
Definition GrCaps.h:507
const GrBackendFormat & backendFormat() const
const skgpu::Swizzle & swizzle() const
const TextureSampler & textureSampler(int index) const
static bool b

◆ gen_fp_key()

static void gen_fp_key ( const GrFragmentProcessor fp,
const GrCaps caps,
skgpu::KeyBuilder b 
)
static

Definition at line 122 of file GrProgramDesc.cpp.

124 {
125 b->appendComment(fp.name());
126 b->addBits(kClassIDBits, fp.classID(), "fpClassID");
129
130 if (auto* te = fp.asTextureEffect()) {
131 const GrBackendFormat& backendFormat = te->view().proxy()->backendFormat();
132 uint32_t samplerKey = sampler_key(backendFormat.textureType(), te->view().swizzle(), caps);
133 b->add32(samplerKey, "fpSamplerKey");
134 caps.addExtraSamplerKey(b, te->samplerState(), backendFormat);
135 }
136
137 fp.addToKey(*caps.shaderCaps(), b);
138 b->add32(fp.numChildProcessors(), "fpNumChildren");
139
140 for (int i = 0; i < fp.numChildProcessors(); ++i) {
141 if (auto child = fp.childProcessor(i)) {
142 gen_fp_key(*child, caps, b);
143 } else {
144 // Fold in a sentinel value as the "class ID" for any null children
145 b->appendComment("Null");
146 b->addBits(kClassIDBits, GrProcessor::ClassID::kNull_ClassID, "fpClassID");
147 }
148 }
149}
static constexpr uint32_t kClassIDBits
static void gen_fp_key(const GrFragmentProcessor &fp, const GrCaps &caps, skgpu::KeyBuilder *b)
const GrShaderCaps * shaderCaps() const
Definition GrCaps.h:63
static constexpr int kCoordTransformKeyBits
static uint32_t ComputeCoordTransformsKey(const GrFragmentProcessor &fp)
const uint32_t fp

◆ gen_geomproc_key()

static void gen_geomproc_key ( const GrGeometryProcessor geomProc,
const GrCaps caps,
skgpu::KeyBuilder b 
)
static

Functions which emit processor key info into the key builder. For every effect, we include the effect's class ID (different for every GrProcessor subclass), any information generated by the effect itself (addToKey), and some meta-information. Shader code may be dependent on properties of the effect not placed in the key by the effect (e.g. pixel format of textures used).

Definition at line 85 of file GrProgramDesc.cpp.

87 {
88 b->appendComment(geomProc.name());
89 b->addBits(kClassIDBits, geomProc.classID(), "geomProcClassID");
90
91 geomProc.addToKey(*caps.shaderCaps(), b);
92 geomProc.getAttributeKey(b);
93
94 add_geomproc_sampler_keys(b, geomProc, caps);
95}
static void add_geomproc_sampler_keys(skgpu::KeyBuilder *b, const GrGeometryProcessor &geomProc, const GrCaps &caps)
virtual void addToKey(const GrShaderCaps &, skgpu::KeyBuilder *) const =0
void getAttributeKey(skgpu::KeyBuilder *b) const
ClassID classID() const
virtual const char * name() const =0

◆ gen_key()

static void gen_key ( skgpu::KeyBuilder b,
const GrProgramInfo programInfo,
const GrCaps caps 
)
static

Definition at line 151 of file GrProgramDesc.cpp.

153 {
154 gen_geomproc_key(programInfo.geomProc(), caps, b);
155
156 const GrPipeline& pipeline = programInfo.pipeline();
157 b->addBits(2, pipeline.numFragmentProcessors(), "numFPs");
158 b->addBits(1, pipeline.numColorFragmentProcessors(), "numColorFPs");
159 for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
160 gen_fp_key(pipeline.getFragmentProcessor(i), caps, b);
161 }
162
163 gen_xp_key(pipeline.getXferProcessor(), caps, pipeline, b);
164
165 b->addBits(16, pipeline.writeSwizzle().asKey(), "writeSwizzle");
166 b->addBool(pipeline.snapVerticesToPixelCenters(), "snapVertices");
167 // The base descriptor only stores whether or not the primitiveType is kPoints. Backend-
168 // specific versions (e.g., Vulkan) require more detail
169 b->addBool((programInfo.primitiveType() == GrPrimitiveType::kPoints), "isPoints");
170
171 // Put a clean break between the "common" data written by this function, and any backend data
172 // appended later. The initial key length will just be this portion (rounded to 4 bytes).
173 b->flush();
174}
static void gen_geomproc_key(const GrGeometryProcessor &geomProc, const GrCaps &caps, skgpu::KeyBuilder *b)
static void gen_xp_key(const GrXferProcessor &xp, const GrCaps &caps, const GrPipeline &pipeline, skgpu::KeyBuilder *b)
const skgpu::Swizzle & writeSwizzle() const
Definition GrPipeline.h:197
bool snapVerticesToPixelCenters() const
Definition GrPipeline.h:171
int numFragmentProcessors() const
Definition GrPipeline.h:99
int numColorFragmentProcessors() const
Definition GrPipeline.h:100
const GrFragmentProcessor & getFragmentProcessor(int idx) const
Definition GrPipeline.h:157
const GrXferProcessor & getXferProcessor() const
Definition GrPipeline.h:116
GrPrimitiveType primitiveType() const
const GrPipeline & pipeline() const
const GrGeometryProcessor & geomProc() const
constexpr uint16_t asKey() const
Definition Swizzle.h:43

◆ gen_xp_key()

static void gen_xp_key ( const GrXferProcessor xp,
const GrCaps caps,
const GrPipeline pipeline,
skgpu::KeyBuilder b 
)
static

Definition at line 97 of file GrProgramDesc.cpp.

100 {
101 b->appendComment(xp.name());
102 b->addBits(kClassIDBits, xp.classID(), "xpClassID");
103
104 const GrSurfaceOrigin* originIfDstTexture = nullptr;
105 GrSurfaceOrigin origin;
106 const GrSurfaceProxyView& dstView = pipeline.dstProxyView();
107 if (dstView.proxy()) {
108 origin = dstView.origin();
109 originIfDstTexture = &origin;
110
111 uint32_t samplerKey = sampler_key(dstView.proxy()->backendFormat().textureType(),
112 dstView.swizzle(), caps);
113 b->add32(samplerKey);
114 }
115
116 xp.addToKey(*caps.shaderCaps(),
117 b,
118 originIfDstTexture,
120}
GrSurfaceOrigin
Definition GrTypes.h:147
GrDstSampleFlags dstSampleFlags() const
Definition GrPipeline.h:142
const GrSurfaceProxyView & dstProxyView() const
Definition GrPipeline.h:138
skgpu::Swizzle swizzle() const
GrSurfaceOrigin origin() const
GrSurfaceProxy * proxy() const
const GrBackendFormat & backendFormat() const
void addToKey(const GrShaderCaps &, skgpu::KeyBuilder *, const GrSurfaceOrigin *originIfDstTexture, bool usesInputAttachmentForDstRead) const

◆ sampler_key()

static uint32_t sampler_key ( GrTextureType  textureType,
const skgpu::Swizzle swizzle,
const GrCaps caps 
)
static

Definition at line 50 of file GrProgramDesc.cpp.

51 {
52 int samplerTypeKey = texture_type_key(textureType);
53
54 static_assert(2 == sizeof(swizzle.asKey()));
55 uint16_t swizzleKey = swizzle.asKey();
56 return SkToU32(samplerTypeKey | swizzleKey << kSamplerOrImageTypeKeyBits);
57}
static uint16_t texture_type_key(GrTextureType type)
constexpr uint32_t SkToU32(S x)
Definition SkTo.h:26

◆ texture_type_key()

static uint16_t texture_type_key ( GrTextureType  type)
inlinestatic

Definition at line 29 of file GrProgramDesc.cpp.

29 {
30 int value = UINT16_MAX;
31 switch (type) {
33 value = 0;
34 break;
36 value = 1;
37 break;
39 value = 2;
40 break;
41 default:
42 SK_ABORT("Unexpected texture type");
43 value = 3;
44 break;
45 }
46 SkASSERT((value & ((1 << kSamplerOrImageTypeKeyBits) - 1)) == value);
47 return SkToU16(value);
48}
#define SK_ABORT(message,...)
Definition SkAssert.h:70
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr uint16_t SkToU16(S x)
Definition SkTo.h:24
uint8_t value

Variable Documentation

◆ kClassIDBits

constexpr uint32_t kClassIDBits = 8
staticconstexpr

Definition at line 76 of file GrProgramDesc.cpp.