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

Side by Side Diff: src/gpu/gl/GrGLProgramDesc.cpp

Issue 1297503007: Generating gl processor key is now recursive (Closed) Base URL: https://skia.googlesource.com/skia@cs3_numExclChildren
Patch Set: rebased Created 5 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/GrPrimitiveProcessor.cpp ('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
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "GrGLProgramDesc.h" 7 #include "GrGLProgramDesc.h"
8 8
9 #include "GrGLFragmentProcessor.h" 9 #include "GrGLFragmentProcessor.h"
10 #include "GrProcessor.h" 10 #include "GrProcessor.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 55
56 /** 56 /**
57 * A function which emits a meta key into the key builder. This is required bec ause shader code may 57 * A function which emits a meta key into the key builder. This is required bec ause shader code may
58 * be dependent on properties of the effect that the effect itself doesn't use 58 * be dependent on properties of the effect that the effect itself doesn't use
59 * in its key (e.g. the pixel format of textures used). So we create a meta-key for 59 * in its key (e.g. the pixel format of textures used). So we create a meta-key for
60 * every effect using this function. It is also responsible for inserting the ef fect's class ID 60 * every effect using this function. It is also responsible for inserting the ef fect's class ID
61 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many 61 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many
62 * textures, transforms, etc, for the space allotted in the meta-key. NOTE, bot h FPs and GPs share 62 * textures, transforms, etc, for the space allotted in the meta-key. NOTE, bot h FPs and GPs share
63 * this function because it is hairy, though FPs do not have attribs, and GPs do not have transforms 63 * this function because it is hairy, though FPs do not have attribs, and GPs do not have transforms
64 *
65 * TODO: A better name for this function would be "compute" instead of "get".
64 */ 66 */
65 static bool get_meta_key(const GrProcessor& proc, 67 static bool get_meta_key(const GrProcessor& proc,
66 const GrGLCaps& caps, 68 const GrGLCaps& caps,
67 uint32_t transformKey, 69 uint32_t transformKey,
68 GrProcessorKeyBuilder* b) { 70 GrProcessorKeyBuilder* b) {
69 size_t processorKeySize = b->size(); 71 size_t processorKeySize = b->size();
70 uint32_t textureKey = gen_texture_key(proc, caps); 72 uint32_t textureKey = gen_texture_key(proc, caps);
71 uint32_t classID = proc.classID(); 73 uint32_t classID = proc.classID();
72 74
73 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they 75 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they
74 // don't fit. 76 // don't fit.
75 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); 77 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16);
76 if ((textureKey | transformKey | classID) & kMetaKeyInvalidMask) { 78 if ((textureKey | transformKey | classID) & kMetaKeyInvalidMask) {
77 return false; 79 return false;
78 } 80 }
79 if (processorKeySize > SK_MaxU16) { 81 if (processorKeySize > SK_MaxU16) {
80 return false; 82 return false;
81 } 83 }
82 84
83 uint32_t* key = b->add32n(2); 85 uint32_t* key = b->add32n(2);
84 key[0] = (textureKey << 16 | transformKey); 86 key[0] = (textureKey << 16 | transformKey);
85 key[1] = (classID << 16 | SkToU16(processorKeySize)); 87 key[1] = (classID << 16 | SkToU16(processorKeySize));
86 return true; 88 return true;
87 } 89 }
88 90
91 /*
92 * TODO: A better name for this function would be "compute" instead of "get".
93 */
94 static bool get_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
95 const GrFragmentProcessor& fp,
96 const GrGLCaps& caps,
97 GrProcessorKeyBuilder* b) {
98 for (int i = 0; i < fp.numChildProcessors(); ++i) {
99 if (!get_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), caps, b )) {
100 return false;
101 }
102 }
103
104 fp.getGLProcessorKey(*caps.glslCaps(), b);
105
106 //**** use glslCaps here?
107 return get_meta_key(fp, caps, primProc.getTransformKey(fp.coordTransforms(),
108 fp.numTransformsExclC hildren()), b);
109 }
110
89 bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc, 111 bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc,
90 const GrPrimitiveProcessor& primProc, 112 const GrPrimitiveProcessor& primProc,
91 const GrPipeline& pipeline, 113 const GrPipeline& pipeline,
92 const GrGLGpu* gpu, 114 const GrGLGpu* gpu,
93 const GrBatchTracker& batchTracker) { 115 const GrBatchTracker& batchTracker) {
94 // The descriptor is used as a cache key. Thus when a field of the 116 // The descriptor is used as a cache key. Thus when a field of the
95 // descriptor will not affect program generation (because of the attribute 117 // descriptor will not affect program generation (because of the attribute
96 // bindings in use or other descriptor field settings) it should be set 118 // bindings in use or other descriptor field settings) it should be set
97 // to a canonical value to avoid duplicate programs with different keys. 119 // to a canonical value to avoid duplicate programs with different keys.
98 120
99 GrGLProgramDesc* glDesc = (GrGLProgramDesc*) desc; 121 GrGLProgramDesc* glDesc = (GrGLProgramDesc*) desc;
100 122
101 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); 123 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t));
102 // Make room for everything up to the effect keys. 124 // Make room for everything up to the effect keys.
103 glDesc->key().reset(); 125 glDesc->key().reset();
104 glDesc->key().push_back_n(kProcessorKeysOffset); 126 glDesc->key().push_back_n(kProcessorKeysOffset);
105 127
106 GrProcessorKeyBuilder b(&glDesc->key()); 128 GrProcessorKeyBuilder b(&glDesc->key());
107 129
108 primProc.getGLProcessorKey(batchTracker, *gpu->glCaps().glslCaps(), &b); 130 primProc.getGLProcessorKey(batchTracker, *gpu->glCaps().glslCaps(), &b);
109 //**** use glslCaps here? 131 //**** use glslCaps here?
110 if (!get_meta_key(primProc, gpu->glCaps(), 0, &b)) { 132 if (!get_meta_key(primProc, gpu->glCaps(), 0, &b)) {
111 glDesc->key().reset(); 133 glDesc->key().reset();
112 return false; 134 return false;
113 } 135 }
114 136
115 for (int s = 0; s < pipeline.numFragmentStages(); ++s) { 137 for (int s = 0; s < pipeline.numFragmentStages(); ++s) {
116 const GrPendingFragmentStage& fps = pipeline.getFragmentStage(s); 138 const GrPendingFragmentStage& fps = pipeline.getFragmentStage(s);
117 const GrFragmentProcessor& fp = *fps.processor(); 139 const GrFragmentProcessor& fp = *fps.processor();
118 140 if (!get_frag_proc_and_meta_keys(primProc, fp, gpu->glCaps(), &b)) {
119 fp.getGLProcessorKey(*gpu->glCaps().glslCaps(), &b);
120
121 //**** use glslCaps here?
122 if (!get_meta_key(fp, gpu->glCaps(), primProc.getTransformKey(fp.coordTr ansforms()), &b)) {
123 glDesc->key().reset(); 141 glDesc->key().reset();
124 return false; 142 return false;
125 } 143 }
126 } 144 }
127 145
128 const GrXferProcessor& xp = *pipeline.getXferProcessor(); 146 const GrXferProcessor& xp = *pipeline.getXferProcessor();
129 xp.getGLProcessorKey(*gpu->glCaps().glslCaps(), &b); 147 xp.getGLProcessorKey(*gpu->glCaps().glslCaps(), &b);
130 //**** use glslCaps here? 148 //**** use glslCaps here?
131 if (!get_meta_key(xp, gpu->glCaps(), 0, &b)) { 149 if (!get_meta_key(xp, gpu->glCaps(), 0, &b)) {
132 glDesc->key().reset(); 150 glDesc->key().reset();
(...skipping 14 matching lines...) Expand all
147 gpu->glCaps()) ; 165 gpu->glCaps()) ;
148 } else { 166 } else {
149 header->fFragPosKey = 0; 167 header->fFragPosKey = 0;
150 } 168 }
151 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); 169 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters();
152 header->fColorEffectCnt = pipeline.numColorFragmentStages(); 170 header->fColorEffectCnt = pipeline.numColorFragmentStages();
153 header->fCoverageEffectCnt = pipeline.numCoverageFragmentStages(); 171 header->fCoverageEffectCnt = pipeline.numCoverageFragmentStages();
154 glDesc->finalize(); 172 glDesc->finalize();
155 return true; 173 return true;
156 } 174 }
OLDNEW
« no previous file with comments | « src/gpu/GrPrimitiveProcessor.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698