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

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

Issue 1451683002: Initial version of external_oes texture support and unit test (Closed) Base URL: https://skia.googlesource.com/skia.git@target
Patch Set: again Created 5 years 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/gl/GrGLProgramDataManager.cpp ('k') | src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp » ('j') | 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 "GrProcessor.h" 9 #include "GrProcessor.h"
10 #include "GrGLGpu.h" 10 #include "GrGLGpu.h"
(...skipping 13 matching lines...) Expand all
24 return false; 24 return false;
25 } 25 }
26 const char* swizzleMap = caps.getSwizzleMap(config); 26 const char* swizzleMap = caps.getSwizzleMap(config);
27 27
28 return SkToBool(memcmp(swizzleMap, "rgba", 4)); 28 return SkToBool(memcmp(swizzleMap, "rgba", 4));
29 } 29 }
30 30
31 static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) { 31 static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) {
32 uint32_t key = 0; 32 uint32_t key = 0;
33 int numTextures = proc.numTextures(); 33 int numTextures = proc.numTextures();
34 int shift = 0;
34 for (int t = 0; t < numTextures; ++t) { 35 for (int t = 0; t < numTextures; ++t) {
35 const GrTextureAccess& access = proc.textureAccess(t); 36 const GrTextureAccess& access = proc.textureAccess(t);
36 if (swizzle_requires_alpha_remapping(*caps.glslCaps(), access.getTexture ()->config())) { 37 if (swizzle_requires_alpha_remapping(*caps.glslCaps(), access.getTexture ()->config())) {
37 key |= 1 << t; 38 key |= 1 << shift;
38 } 39 }
40 if (GR_GL_TEXTURE_EXTERNAL == static_cast<GrGLTexture*>(access.getTextur e())->target()) {
41 key |= 2 << shift;
42 }
43 shift += 2;
39 } 44 }
40 return key; 45 return key;
41 } 46 }
42 47
43 /** 48 /**
44 * A function which emits a meta key into the key builder. This is required bec ause shader code may 49 * A function which emits a meta key into the key builder. This is required bec ause shader code may
45 * be dependent on properties of the effect that the effect itself doesn't use 50 * be dependent on properties of the effect that the effect itself doesn't use
46 * in its key (e.g. the pixel format of textures used). So we create a meta-key for 51 * in its key (e.g. the pixel format of textures used). So we create a meta-key for
47 * every effect using this function. It is also responsible for inserting the ef fect's class ID 52 * every effect using this function. It is also responsible for inserting the ef fect's class ID
48 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many 53 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many
49 * textures, transforms, etc, for the space allotted in the meta-key. NOTE, bot h FPs and GPs share 54 * textures, transforms, etc, for the space allotted in the meta-key. NOTE, bot h FPs and GPs share
50 * this function because it is hairy, though FPs do not have attribs, and GPs do not have transforms 55 * this function because it is hairy, though FPs do not have attribs, and GPs do not have transforms
51 *
52 * TODO: A better name for this function would be "compute" instead of "get".
53 */ 56 */
54 static bool get_meta_key(const GrProcessor& proc, 57 static bool gen_meta_key(const GrProcessor& proc,
55 const GrGLCaps& caps, 58 const GrGLCaps& caps,
56 uint32_t transformKey, 59 uint32_t transformKey,
57 GrProcessorKeyBuilder* b) { 60 GrProcessorKeyBuilder* b) {
58 size_t processorKeySize = b->size(); 61 size_t processorKeySize = b->size();
59 uint32_t textureKey = gen_texture_key(proc, caps); 62 uint32_t textureKey = gen_texture_key(proc, caps);
60 uint32_t classID = proc.classID(); 63 uint32_t classID = proc.classID();
61 64
62 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they 65 // Currently we allow 16 bits for the class id and the overall processor key size.
63 // don't fit.
64 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); 66 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16);
65 if ((textureKey | transformKey | classID) & kMetaKeyInvalidMask) { 67 if ((processorKeySize | classID) & kMetaKeyInvalidMask) {
66 return false;
67 }
68 if (processorKeySize > SK_MaxU16) {
69 return false; 68 return false;
70 } 69 }
71 70
72 uint32_t* key = b->add32n(2); 71 uint32_t* key = b->add32n(3);
73 key[0] = (textureKey << 16 | transformKey); 72 key[0] = (classID << 16) | SkToU32(processorKeySize);
74 key[1] = (classID << 16 | SkToU16(processorKeySize)); 73 key[1] = textureKey;
74 key[2] = transformKey;
75 return true; 75 return true;
76 } 76 }
77 77
78 /* 78 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
79 * TODO: A better name for this function would be "compute" instead of "get".
80 */
81 static bool get_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
82 const GrFragmentProcessor& fp, 79 const GrFragmentProcessor& fp,
83 const GrGLCaps& caps, 80 const GrGLCaps& caps,
84 GrProcessorKeyBuilder* b) { 81 GrProcessorKeyBuilder* b) {
85 for (int i = 0; i < fp.numChildProcessors(); ++i) { 82 for (int i = 0; i < fp.numChildProcessors(); ++i) {
86 if (!get_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), caps, b )) { 83 if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), caps, b )) {
87 return false; 84 return false;
88 } 85 }
89 } 86 }
90 87
91 fp.getGLSLProcessorKey(*caps.glslCaps(), b); 88 fp.getGLSLProcessorKey(*caps.glslCaps(), b);
92 89
93 //**** use glslCaps here? 90 //**** use glslCaps here?
94 return get_meta_key(fp, caps, primProc.getTransformKey(fp.coordTransforms(), 91 return gen_meta_key(fp, caps, primProc.getTransformKey(fp.coordTransforms(),
95 fp.numTransformsExclC hildren()), b); 92 fp.numTransformsExclC hildren()), b);
96 } 93 }
97 94
98 bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc, 95 bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc,
99 const GrPrimitiveProcessor& primProc, 96 const GrPrimitiveProcessor& primProc,
100 const GrPipeline& pipeline, 97 const GrPipeline& pipeline,
101 const GrGLGpu* gpu) { 98 const GrGLGpu* gpu) {
102 // The descriptor is used as a cache key. Thus when a field of the 99 // The descriptor is used as a cache key. Thus when a field of the
103 // descriptor will not affect program generation (because of the attribute 100 // descriptor will not affect program generation (because of the attribute
104 // bindings in use or other descriptor field settings) it should be set 101 // bindings in use or other descriptor field settings) it should be set
105 // to a canonical value to avoid duplicate programs with different keys. 102 // to a canonical value to avoid duplicate programs with different keys.
106 103
107 GrGLProgramDesc* glDesc = (GrGLProgramDesc*) desc; 104 GrGLProgramDesc* glDesc = (GrGLProgramDesc*) desc;
108 105
109 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); 106 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t));
110 // Make room for everything up to the effect keys. 107 // Make room for everything up to the effect keys.
111 glDesc->key().reset(); 108 glDesc->key().reset();
112 glDesc->key().push_back_n(kProcessorKeysOffset); 109 glDesc->key().push_back_n(kProcessorKeysOffset);
113 110
114 GrProcessorKeyBuilder b(&glDesc->key()); 111 GrProcessorKeyBuilder b(&glDesc->key());
115 112
116 primProc.getGLSLProcessorKey(*gpu->glCaps().glslCaps(), &b); 113 primProc.getGLSLProcessorKey(*gpu->glCaps().glslCaps(), &b);
117 //**** use glslCaps here? 114 //**** use glslCaps here?
118 if (!get_meta_key(primProc, gpu->glCaps(), 0, &b)) { 115 if (!gen_meta_key(primProc, gpu->glCaps(), 0, &b)) {
119 glDesc->key().reset(); 116 glDesc->key().reset();
120 return false; 117 return false;
121 } 118 }
122 119
123 for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) { 120 for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
124 const GrFragmentProcessor& fp = pipeline.getFragmentProcessor(i); 121 const GrFragmentProcessor& fp = pipeline.getFragmentProcessor(i);
125 if (!get_frag_proc_and_meta_keys(primProc, fp, gpu->glCaps(), &b)) { 122 if (!gen_frag_proc_and_meta_keys(primProc, fp, gpu->glCaps(), &b)) {
126 glDesc->key().reset(); 123 glDesc->key().reset();
127 return false; 124 return false;
128 } 125 }
129 } 126 }
130 127
131 const GrXferProcessor& xp = *pipeline.getXferProcessor(); 128 const GrXferProcessor& xp = *pipeline.getXferProcessor();
132 xp.getGLSLProcessorKey(*gpu->glCaps().glslCaps(), &b); 129 xp.getGLSLProcessorKey(*gpu->glCaps().glslCaps(), &b);
133 //**** use glslCaps here? 130 //**** use glslCaps here?
134 if (!get_meta_key(xp, gpu->glCaps(), 0, &b)) { 131 if (!gen_meta_key(xp, gpu->glCaps(), 0, &b)) {
135 glDesc->key().reset(); 132 glDesc->key().reset();
136 return false; 133 return false;
137 } 134 }
138 135
139 // --------DO NOT MOVE HEADER ABOVE THIS LINE------------------------------- ------------------- 136 // --------DO NOT MOVE HEADER ABOVE THIS LINE------------------------------- -------------------
140 // Because header is a pointer into the dynamic array, we can't push any new data into the key 137 // Because header is a pointer into the dynamic array, we can't push any new data into the key
141 // below here. 138 // below here.
142 KeyHeader* header = glDesc->atOffset<KeyHeader, kHeaderOffset>(); 139 KeyHeader* header = glDesc->atOffset<KeyHeader, kHeaderOffset>();
143 140
144 // make sure any padding in the header is zeroed. 141 // make sure any padding in the header is zeroed.
145 memset(header, 0, kHeaderSize); 142 memset(header, 0, kHeaderSize);
146 143
147 if (pipeline.readsFragPosition()) { 144 if (pipeline.readsFragPosition()) {
148 header->fFragPosKey = 145 header->fFragPosKey =
149 GrGLSLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.get RenderTarget()); 146 GrGLSLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.get RenderTarget());
150 } else { 147 } else {
151 header->fFragPosKey = 0; 148 header->fFragPosKey = 0;
152 } 149 }
153 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); 150 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters();
154 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); 151 header->fColorEffectCnt = pipeline.numColorFragmentProcessors();
155 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); 152 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors();
156 glDesc->finalize(); 153 glDesc->finalize();
157 return true; 154 return true;
158 } 155 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgramDataManager.cpp ('k') | src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698