Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: src/gpu/vk/GrVkProgramDesc.cpp

Issue 2184413002: Merge ProgramDesc's for GL and Vulkan (Closed) Base URL: https://skia.googlesource.com/skia.git@minorPerf
Patch Set: typo Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/vk/GrVkProgramDesc.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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 #include "GrVkProgramDesc.h"
8
9 //#include "GrVkProcessor.h"
10 #include "GrProcessor.h"
11 #include "GrPipeline.h"
12 #include "GrRenderTargetPriv.h"
13 #include "GrVkGpu.h"
14 #include "GrVkUtil.h"
15 #include "SkChecksum.h"
16 #include "glsl/GrGLSLFragmentProcessor.h"
17 #include "glsl/GrGLSLFragmentShaderBuilder.h"
18 #include "glsl/GrGLSLCaps.h"
19
20 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc,
21 const GrGLSLCaps& caps) {
22 int numTextures = proc.numTextures();
23 SkASSERT(0 == proc.numBuffers());
24 // Need two bytes per key (swizzle, sampler type, and precision).
25 int word32Count = (proc.numTextures() + 1) / 2;
26 if (0 == word32Count) {
27 return;
28 }
29 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count));
30 for (int i = 0; i < numTextures; ++i) {
31 const GrTextureAccess& access = proc.textureAccess(i);
32 GrTexture* texture = access.getTexture();
33 k16[i] = SkToU16(caps.configTextureSwizzle(texture->config()).asKey() |
34 (caps.samplerPrecision(texture->config(), access.getVis ibility()) << 8));
35 }
36 // zero the last 16 bits if the number of textures is odd.
37 if (numTextures & 0x1) {
38 k16[numTextures] = 0;
39 }
40 }
41
42 /**
43 * A function which emits a meta key into the key builder. This is required beca use shader code may
44 * be dependent on properties of the effect that the effect itself doesn't use
45 * in its key (e.g. the pixel format of textures used). So we create a meta-key f or
46 * every effect using this function. It is also responsible for inserting the eff ect's class ID
47 * which must be different for every GrProcessor subclass. It can fail if an effe ct uses too many
48 * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and G Ps share this
49 * function because it is hairy, though FPs do not have attribs, and GPs do not h ave transforms
50 */
51 static bool gen_meta_key(const GrProcessor& proc,
52 const GrGLSLCaps& glslCaps,
53 uint32_t transformKey,
54 GrProcessorKeyBuilder* b) {
55 size_t processorKeySize = b->size();
56 uint32_t classID = proc.classID();
57
58 // Currently we allow 16 bits for the class id and the overall processor key size.
59 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)SK_MaxU16);
60 if ((processorKeySize | classID) & kMetaKeyInvalidMask) {
61 return false;
62 }
63
64 add_texture_key(b, proc, glslCaps);
65
66 uint32_t* key = b->add32n(2);
67 key[0] = (classID << 16) | SkToU32(processorKeySize);
68 key[1] = transformKey;
69 return true;
70 }
71
72 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
73 const GrFragmentProcessor& fp,
74 const GrGLSLCaps& glslCaps,
75 GrProcessorKeyBuilder* b) {
76 for (int i = 0; i < fp.numChildProcessors(); ++i) {
77 if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), glslCap s, b)) {
78 return false;
79 }
80 }
81
82 fp.getGLSLProcessorKey(glslCaps, b);
83
84 return gen_meta_key(fp, glslCaps, primProc.getTransformKey(fp.coordTransform s(),
85 fp.numTransformsExclChildren()), b);
86 }
87
88 bool GrVkProgramDescBuilder::Build(GrProgramDesc* desc,
89 const GrPrimitiveProcessor& primProc,
90 const GrPipeline& pipeline,
91 const GrGLSLCaps& glslCaps) {
92 // The descriptor is used as a cache key. Thus when a field of the
93 // descriptor will not affect program generation (because of the attribute
94 // bindings in use or other descriptor field settings) it should be set
95 // to a canonical value to avoid duplicate programs with different keys.
96
97 GrVkProgramDesc* vkDesc = (GrVkProgramDesc*)desc;
98
99 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t));
100 // Make room for everything up to the effect keys.
101 vkDesc->key().reset();
102 vkDesc->key().push_back_n(kProcessorKeysOffset);
103
104 GrProcessorKeyBuilder b(&vkDesc->key());
105
106 primProc.getGLSLProcessorKey(glslCaps, &b);
107 if (!gen_meta_key(primProc, glslCaps, 0, &b)) {
108 vkDesc->key().reset();
109 return false;
110 }
111 GrProcessor::RequiredFeatures requiredFeatures = primProc.requiredFeatures() ;
112
113 for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
114 const GrFragmentProcessor& fp = pipeline.getFragmentProcessor(i);
115 if (!gen_frag_proc_and_meta_keys(primProc, fp, glslCaps, &b)) {
116 vkDesc->key().reset();
117 return false;
118 }
119 requiredFeatures |= fp.requiredFeatures();
120 }
121
122 const GrXferProcessor& xp = pipeline.getXferProcessor();
123 xp.getGLSLProcessorKey(glslCaps, &b);
124 if (!gen_meta_key(xp, glslCaps, 0, &b)) {
125 vkDesc->key().reset();
126 return false;
127 }
128 requiredFeatures |= xp.requiredFeatures();
129
130 // --------DO NOT MOVE HEADER ABOVE THIS LINE------------------------------- -------------------
131 // Because header is a pointer into the dynamic array, we can't push any new data into the key
132 // below here.
133 KeyHeader* header = vkDesc->atOffset<KeyHeader, kHeaderOffset>();
134
135 // make sure any padding in the header is zeroed.
136 memset(header, 0, kHeaderSize);
137
138 GrRenderTarget* rt = pipeline.getRenderTarget();
139
140 if (requiredFeatures & (GrProcessor::kFragmentPosition_RequiredFeature |
141 GrProcessor::kSampleLocations_RequiredFeature)) {
142 header->fSurfaceOriginKey = GrGLSLFragmentShaderBuilder::KeyForSurfaceOr igin(rt->origin());
143 } else {
144 header->fSurfaceOriginKey = 0;
145 }
146
147 if (requiredFeatures & GrProcessor::kSampleLocations_RequiredFeature) {
148 SkASSERT(pipeline.isHWAntialiasState());
149 header->fSamplePatternKey =
150 rt->renderTargetPriv().getMultisampleSpecs(pipeline.getStencil()).fU niqueID;
151 } else {
152 header->fSamplePatternKey = 0;
153 }
154
155 header->fOutputSwizzle = glslCaps.configOutputSwizzle(rt->config()).asKey();
156
157 if (pipeline.ignoresCoverage()) {
158 header->fIgnoresCoverage = 1;
159 } else {
160 header->fIgnoresCoverage = 0;
161 }
162
163 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters();
164 header->fColorEffectCnt = pipeline.numColorFragmentProcessors();
165 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors();
166 vkDesc->finalize();
167 return true;
168 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkProgramDesc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698