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

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

Issue 1567733005: Add a class representing texture swizzle. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add .a for color table FP texture reads. Created 4 years, 11 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/gl/GrGLGpu.cpp ('k') | src/gpu/glsl/GrGLSLCaps.h » ('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"
11 #include "GrPipeline.h" 11 #include "GrPipeline.h"
12 #include "SkChecksum.h" 12 #include "SkChecksum.h"
13 #include "glsl/GrGLSLFragmentProcessor.h" 13 #include "glsl/GrGLSLFragmentProcessor.h"
14 #include "glsl/GrGLSLFragmentShaderBuilder.h" 14 #include "glsl/GrGLSLFragmentShaderBuilder.h"
15 15
16 /** 16
17 * Do we need to either map r,g,b->a or a->r. configComponentMask indicates whic h channels are 17 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc,
18 * present in the texture's config. swizzleComponentMask indicates the channels present in the 18 const GrGLSLCaps& caps) {
19 * shader swizzle. 19 int numTextures = proc.numTextures();
20 */ 20 // Need two bytes per key (swizzle and target).
21 static bool swizzle_requires_alpha_remapping(const GrGLSLCaps& caps, GrPixelConf ig config) { 21 int word32Count = (proc.numTextures() + 1) / 2;
22 if (!caps.mustSwizzleInShader()) { 22 if (0 == word32Count) {
23 // Any remapping is handled using texture swizzling not shader modificat ions. 23 return;
24 return false;
25 } 24 }
26 const char* swizzleMap = caps.getSwizzleMap(config); 25 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count));
27 26 for (int i = 0; i < numTextures; ++i) {
28 return SkToBool(memcmp(swizzleMap, "rgba", 4)); 27 const GrTextureAccess& access = proc.textureAccess(i);
29 } 28 bool isExternal = (GR_GL_TEXTURE_EXTERNAL ==
30 29 static_cast<GrGLTexture*>(access.getTexture())->targe t());
31 static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) { 30 k16[i] = caps.configTextureSwizzle(access.getTexture()->config()).asKey( ) |
32 uint32_t key = 0; 31 (isExternal ? 0xFF00 : 0x0000);
33 int numTextures = proc.numTextures();
34 int shift = 0;
35 for (int t = 0; t < numTextures; ++t) {
36 const GrTextureAccess& access = proc.textureAccess(t);
37 if (swizzle_requires_alpha_remapping(*caps.glslCaps(), access.getTexture ()->config())) {
38 key |= 1 << shift;
39 }
40 if (GR_GL_TEXTURE_EXTERNAL == static_cast<GrGLTexture*>(access.getTextur e())->target()) {
41 key |= 2 << shift;
42 }
43 shift += 2;
44 } 32 }
45 return key;
46 } 33 }
47 34
48 /** 35 /**
49 * A function which emits a meta key into the key builder. This is required bec ause shader code may 36 * A function which emits a meta key into the key builder. This is required bec ause shader code may
50 * be dependent on properties of the effect that the effect itself doesn't use 37 * be dependent on properties of the effect that the effect itself doesn't use
51 * in its key (e.g. the pixel format of textures used). So we create a meta-key for 38 * in its key (e.g. the pixel format of textures used). So we create a meta-key for
52 * every effect using this function. It is also responsible for inserting the ef fect's class ID 39 * every effect using this function. It is also responsible for inserting the ef fect's class ID
53 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many 40 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many
54 * textures, transforms, etc, for the space allotted in the meta-key. NOTE, bot h FPs and GPs share 41 * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share this
55 * this function because it is hairy, though FPs do not have attribs, and GPs do not have transforms 42 * function because it is hairy, though FPs do not have attribs, and GPs do not have transforms
56 */ 43 */
57 static bool gen_meta_key(const GrProcessor& proc, 44 static bool gen_meta_key(const GrProcessor& proc,
58 const GrGLCaps& caps, 45 const GrGLCaps& caps,
59 uint32_t transformKey, 46 uint32_t transformKey,
60 GrProcessorKeyBuilder* b) { 47 GrProcessorKeyBuilder* b) {
61 size_t processorKeySize = b->size(); 48 size_t processorKeySize = b->size();
62 uint32_t textureKey = gen_texture_key(proc, caps);
63 uint32_t classID = proc.classID(); 49 uint32_t classID = proc.classID();
64 50
65 // Currently we allow 16 bits for the class id and the overall processor key size. 51 // Currently we allow 16 bits for the class id and the overall processor key size.
66 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); 52 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16);
67 if ((processorKeySize | classID) & kMetaKeyInvalidMask) { 53 if ((processorKeySize | classID) & kMetaKeyInvalidMask) {
68 return false; 54 return false;
69 } 55 }
70 56
71 uint32_t* key = b->add32n(3); 57 add_texture_key(b, proc, *caps.glslCaps());
58
59 uint32_t* key = b->add32n(2);
72 key[0] = (classID << 16) | SkToU32(processorKeySize); 60 key[0] = (classID << 16) | SkToU32(processorKeySize);
73 key[1] = textureKey; 61 key[1] = transformKey;
74 key[2] = transformKey;
75 return true; 62 return true;
76 } 63 }
77 64
78 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, 65 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
79 const GrFragmentProcessor& fp, 66 const GrFragmentProcessor& fp,
80 const GrGLCaps& caps, 67 const GrGLCaps& caps,
81 GrProcessorKeyBuilder* b) { 68 GrProcessorKeyBuilder* b) {
82 for (int i = 0; i < fp.numChildProcessors(); ++i) { 69 for (int i = 0; i < fp.numChildProcessors(); ++i) {
83 if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), caps, b )) { 70 if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), caps, b )) {
84 return false; 71 return false;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } else { 140 } else {
154 header->fIgnoresCoverage = 0; 141 header->fIgnoresCoverage = 0;
155 } 142 }
156 143
157 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); 144 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters();
158 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); 145 header->fColorEffectCnt = pipeline.numColorFragmentProcessors();
159 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); 146 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors();
160 glDesc->finalize(); 147 glDesc->finalize();
161 return true; 148 return true;
162 } 149 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.cpp ('k') | src/gpu/glsl/GrGLSLCaps.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698