OLD | NEW |
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 "GrPipeline.h" | 10 #include "GrPipeline.h" |
11 #include "GrRenderTargetPriv.h" | 11 #include "GrRenderTargetPriv.h" |
12 #include "SkChecksum.h" | 12 #include "SkChecksum.h" |
13 #include "gl/GrGLDefines.h" | 13 #include "gl/GrGLDefines.h" |
14 #include "gl/GrGLTexture.h" | 14 #include "gl/GrGLTexture.h" |
15 #include "gl/GrGLTypes.h" | 15 #include "gl/GrGLTypes.h" |
16 #include "glsl/GrGLSLFragmentProcessor.h" | 16 #include "glsl/GrGLSLFragmentProcessor.h" |
17 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 17 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
18 #include "glsl/GrGLSLCaps.h" | 18 #include "glsl/GrGLSLCaps.h" |
19 | 19 |
20 static uint16_t texture_key(GrSLType samplerType, GrPixelConfig config, GrShader
Flags visibility, | 20 static uint16_t sampler_key(GrSLType samplerType, GrPixelConfig config, GrShader
Flags visibility, |
21 const GrGLSLCaps& caps) { | 21 const GrGLSLCaps& caps) { |
22 static constexpr int kFirstSamplerType = kSampler2D_GrSLType; | 22 static constexpr int kFirstSamplerType = kSampler2D_GrSLType; |
23 static constexpr int kLastSamplerType = kSampler2DRect_GrSLType; | 23 static constexpr int kLastSamplerType = kSamplerBuffer_GrSLType; |
24 static constexpr int kSamplerTypeKeyBits = 4; | 24 static constexpr int kSamplerTypeKeyBits = 4; |
25 GR_STATIC_ASSERT(kLastSamplerType - kFirstSamplerType < (1 << kSamplerTypeKe
yBits)); | 25 GR_STATIC_ASSERT(kLastSamplerType - kFirstSamplerType < (1 << kSamplerTypeKe
yBits)); |
26 | 26 |
27 SkASSERT(samplerType >= kFirstSamplerType && samplerType <= kLastSamplerType
); | 27 SkASSERT(samplerType >= kFirstSamplerType && samplerType <= kLastSamplerType
); |
28 int samplerTypeKey = samplerType - kFirstSamplerType; | 28 int samplerTypeKey = samplerType - kFirstSamplerType; |
29 | 29 |
30 return SkToU16(caps.configTextureSwizzle(config).asKey() | | 30 return SkToU16(caps.configTextureSwizzle(config).asKey() | |
31 (samplerTypeKey << 8) | | 31 (samplerTypeKey << 8) | |
32 (caps.samplerPrecision(config, visibility) << (8 + kSamplerTy
peKeyBits))); | 32 (caps.samplerPrecision(config, visibility) << (8 + kSamplerTy
peKeyBits))); |
33 } | 33 } |
34 | 34 |
35 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc, | 35 static void add_sampler_keys(GrProcessorKeyBuilder* b, const GrProcessor& proc, |
36 const GrGLSLCaps& caps) { | 36 const GrGLSLCaps& caps) { |
37 int numTextures = proc.numTextures(); | 37 int numTextures = proc.numTextures(); |
| 38 int numSamplers = numTextures + proc.numBuffers(); |
38 // Need two bytes per key (swizzle, sampler type, and precision). | 39 // Need two bytes per key (swizzle, sampler type, and precision). |
39 int word32Count = (proc.numTextures() + 1) / 2; | 40 int word32Count = (numSamplers + 1) / 2; |
40 if (0 == word32Count) { | 41 if (0 == word32Count) { |
41 return; | 42 return; |
42 } | 43 } |
43 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count)); | 44 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count)); |
44 for (int i = 0; i < numTextures; ++i) { | 45 int i = 0; |
| 46 for (; i < numTextures; ++i) { |
45 const GrTextureAccess& access = proc.textureAccess(i); | 47 const GrTextureAccess& access = proc.textureAccess(i); |
46 const GrTexture* tex = access.getTexture(); | 48 const GrTexture* tex = access.getTexture(); |
47 k16[i] = texture_key(tex->samplerType(), tex->config(), access.getVisibi
lity(), caps); | 49 k16[i] = sampler_key(tex->samplerType(), tex->config(), access.getVisibi
lity(), caps); |
48 } | 50 } |
49 // zero the last 16 bits if the number of textures is odd. | 51 for (; i < numSamplers; ++i) { |
50 if (numTextures & 0x1) { | 52 const GrBufferAccess& access = proc.bufferAccess(i - numTextures); |
51 k16[numTextures] = 0; | 53 k16[i] = sampler_key(kSamplerBuffer_GrSLType, access.texelConfig(), acce
ss.visibility(), |
| 54 caps); |
| 55 } |
| 56 // zero the last 16 bits if the number of samplers is odd. |
| 57 if (numSamplers & 0x1) { |
| 58 k16[numSamplers] = 0; |
52 } | 59 } |
53 } | 60 } |
54 | 61 |
55 /** | 62 /** |
56 * A function which emits a meta key into the key builder. This is required bec
ause shader code may | 63 * A function which emits a meta key into the key builder. This is required bec
ause shader code may |
57 * be dependent on properties of the effect that the effect itself doesn't use | 64 * be dependent on properties of the effect that the effect itself doesn't use |
58 * in its key (e.g. the pixel format of textures used). So we create a meta-key
for | 65 * in its key (e.g. the pixel format of textures used). So we create a meta-key
for |
59 * every effect using this function. It is also responsible for inserting the ef
fect's class ID | 66 * every effect using this function. It is also responsible for inserting the ef
fect's class ID |
60 * which must be different for every GrProcessor subclass. It can fail if an eff
ect uses too many | 67 * which must be different for every GrProcessor subclass. It can fail if an eff
ect uses too many |
61 * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and
GPs share this | 68 * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and
GPs share this |
62 * function because it is hairy, though FPs do not have attribs, and GPs do not
have transforms | 69 * function because it is hairy, though FPs do not have attribs, and GPs do not
have transforms |
63 */ | 70 */ |
64 static bool gen_meta_key(const GrProcessor& proc, | 71 static bool gen_meta_key(const GrProcessor& proc, |
65 const GrGLSLCaps& glslCaps, | 72 const GrGLSLCaps& glslCaps, |
66 uint32_t transformKey, | 73 uint32_t transformKey, |
67 GrProcessorKeyBuilder* b) { | 74 GrProcessorKeyBuilder* b) { |
68 size_t processorKeySize = b->size(); | 75 size_t processorKeySize = b->size(); |
69 uint32_t classID = proc.classID(); | 76 uint32_t classID = proc.classID(); |
70 | 77 |
71 // Currently we allow 16 bits for the class id and the overall processor key
size. | 78 // Currently we allow 16 bits for the class id and the overall processor key
size. |
72 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); | 79 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); |
73 if ((processorKeySize | classID) & kMetaKeyInvalidMask) { | 80 if ((processorKeySize | classID) & kMetaKeyInvalidMask) { |
74 return false; | 81 return false; |
75 } | 82 } |
76 | 83 |
77 add_texture_key(b, proc, glslCaps); | 84 add_sampler_keys(b, proc, glslCaps); |
78 | 85 |
79 uint32_t* key = b->add32n(2); | 86 uint32_t* key = b->add32n(2); |
80 key[0] = (classID << 16) | SkToU32(processorKeySize); | 87 key[0] = (classID << 16) | SkToU32(processorKeySize); |
81 key[1] = transformKey; | 88 key[1] = transformKey; |
82 return true; | 89 return true; |
83 } | 90 } |
84 | 91 |
85 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, | 92 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, |
86 const GrFragmentProcessor& fp, | 93 const GrFragmentProcessor& fp, |
87 const GrGLSLCaps& glslCaps, | 94 const GrGLSLCaps& glslCaps, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } else { | 179 } else { |
173 header->fIgnoresCoverage = 0; | 180 header->fIgnoresCoverage = 0; |
174 } | 181 } |
175 | 182 |
176 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); | 183 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); |
177 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); | 184 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); |
178 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); | 185 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); |
179 glDesc->finalize(); | 186 glDesc->finalize(); |
180 return true; | 187 return true; |
181 } | 188 } |
OLD | NEW |