OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2016 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 "GrGLSLProgramDesc.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" | |
14 #include "gl/GrGLTexture.h" | |
15 #include "gl/GrGLTypes.h" | |
16 #include "glsl/GrGLSLFragmentProcessor.h" | 13 #include "glsl/GrGLSLFragmentProcessor.h" |
17 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
18 #include "glsl/GrGLSLCaps.h" | 15 #include "glsl/GrGLSLCaps.h" |
19 | 16 |
20 static uint16_t sampler_key(GrSLType samplerType, GrPixelConfig config, GrShader
Flags visibility, | 17 static uint16_t sampler_key(GrSLType samplerType, GrPixelConfig config, GrShader
Flags visibility, |
21 const GrGLSLCaps& caps) { | 18 const GrGLSLCaps& caps) { |
22 enum { | 19 enum { |
23 kFirstSamplerType = kTexture2DSampler_GrSLType, | 20 kFirstSamplerType = kTexture2DSampler_GrSLType, |
24 kLastSamplerType = kTextureBufferSampler_GrSLType, | 21 kLastSamplerType = kTextureBufferSampler_GrSLType, |
25 kSamplerTypeKeyBits = 4 | 22 kSamplerTypeKeyBits = 4 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 * function because it is hairy, though FPs do not have attribs, and GPs do not
have transforms | 68 * function because it is hairy, though FPs do not have attribs, and GPs do not
have transforms |
72 */ | 69 */ |
73 static bool gen_meta_key(const GrProcessor& proc, | 70 static bool gen_meta_key(const GrProcessor& proc, |
74 const GrGLSLCaps& glslCaps, | 71 const GrGLSLCaps& glslCaps, |
75 uint32_t transformKey, | 72 uint32_t transformKey, |
76 GrProcessorKeyBuilder* b) { | 73 GrProcessorKeyBuilder* b) { |
77 size_t processorKeySize = b->size(); | 74 size_t processorKeySize = b->size(); |
78 uint32_t classID = proc.classID(); | 75 uint32_t classID = proc.classID(); |
79 | 76 |
80 // Currently we allow 16 bits for the class id and the overall processor key
size. | 77 // Currently we allow 16 bits for the class id and the overall processor key
size. |
81 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); | 78 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)SK_MaxU16); |
82 if ((processorKeySize | classID) & kMetaKeyInvalidMask) { | 79 if ((processorKeySize | classID) & kMetaKeyInvalidMask) { |
83 return false; | 80 return false; |
84 } | 81 } |
85 | 82 |
86 add_sampler_keys(b, proc, glslCaps); | 83 add_sampler_keys(b, proc, glslCaps); |
87 | 84 |
88 uint32_t* key = b->add32n(2); | 85 uint32_t* key = b->add32n(2); |
89 key[0] = (classID << 16) | SkToU32(processorKeySize); | 86 key[0] = (classID << 16) | SkToU32(processorKeySize); |
90 key[1] = transformKey; | 87 key[1] = transformKey; |
91 return true; | 88 return true; |
92 } | 89 } |
93 | 90 |
94 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, | 91 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, |
95 const GrFragmentProcessor& fp, | 92 const GrFragmentProcessor& fp, |
96 const GrGLSLCaps& glslCaps, | 93 const GrGLSLCaps& glslCaps, |
97 GrProcessorKeyBuilder* b) { | 94 GrProcessorKeyBuilder* b) { |
98 for (int i = 0; i < fp.numChildProcessors(); ++i) { | 95 for (int i = 0; i < fp.numChildProcessors(); ++i) { |
99 if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), glslCap
s, b)) { | 96 if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), glslCap
s, b)) { |
100 return false; | 97 return false; |
101 } | 98 } |
102 } | 99 } |
103 | 100 |
104 fp.getGLSLProcessorKey(glslCaps, b); | 101 fp.getGLSLProcessorKey(glslCaps, b); |
105 | 102 |
106 return gen_meta_key(fp, glslCaps, primProc.getTransformKey(fp.coordTransform
s(), | 103 return gen_meta_key(fp, glslCaps, primProc.getTransformKey(fp.coordTransform
s(), |
107 fp.numTransformsE
xclChildren()), b); | 104 fp.numTransformsE
xclChildren()), b); |
108 } | 105 } |
109 | 106 |
110 bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc, | 107 bool GrGLSLProgramDescBuilder::Build(GrProgramDesc* desc, |
111 const GrPrimitiveProcessor& primProc, | 108 const GrPrimitiveProcessor& primProc, |
112 const GrPipeline& pipeline, | 109 const GrPipeline& pipeline, |
113 const GrGLSLCaps& glslCaps) { | 110 const GrGLSLCaps& glslCaps) { |
114 // The descriptor is used as a cache key. Thus when a field of the | 111 // The descriptor is used as a cache key. Thus when a field of the |
115 // descriptor will not affect program generation (because of the attribute | 112 // descriptor will not affect program generation (because of the attribute |
116 // bindings in use or other descriptor field settings) it should be set | 113 // bindings in use or other descriptor field settings) it should be set |
117 // to a canonical value to avoid duplicate programs with different keys. | 114 // to a canonical value to avoid duplicate programs with different keys. |
118 | 115 |
119 GrGLProgramDesc* glDesc = (GrGLProgramDesc*) desc; | 116 GrGLSLProgramDesc* glDesc = (GrGLSLProgramDesc*)desc; |
120 | 117 |
121 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); | 118 GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); |
122 // Make room for everything up to the effect keys. | 119 // Make room for everything up to the effect keys. |
123 glDesc->key().reset(); | 120 glDesc->key().reset(); |
124 glDesc->key().push_back_n(kProcessorKeysOffset); | 121 glDesc->key().push_back_n(kProcessorKeysOffset); |
125 | 122 |
126 GrProcessorKeyBuilder b(&glDesc->key()); | 123 GrProcessorKeyBuilder b(&glDesc->key()); |
127 | 124 |
128 primProc.getGLSLProcessorKey(glslCaps, &b); | 125 primProc.getGLSLProcessorKey(glslCaps, &b); |
129 if (!gen_meta_key(primProc, glslCaps, 0, &b)) { | 126 if (!gen_meta_key(primProc, glslCaps, 0, &b)) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } else { | 178 } else { |
182 header->fIgnoresCoverage = 0; | 179 header->fIgnoresCoverage = 0; |
183 } | 180 } |
184 | 181 |
185 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); | 182 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); |
186 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); | 183 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); |
187 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); | 184 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); |
188 glDesc->finalize(); | 185 glDesc->finalize(); |
189 return true; | 186 return true; |
190 } | 187 } |
OLD | NEW |