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 uint8_t texture_target_key(GrGLenum target) { | 20 static uint8_t sampler_type_key_4_bits(GrSLType samplerType) { |
21 switch (target) { | 21 static constexpr int kFirstSamplerType = kSampler2D_GrSLType; |
22 case GR_GL_TEXTURE_2D: | 22 static constexpr int kLastSamplerType = kSampler2DRect_GrSLType; |
23 return 0; | 23 |
24 case GR_GL_TEXTURE_EXTERNAL: | 24 SkASSERT(samplerType >= kFirstSamplerType && samplerType <= kLastSamplerType
); |
25 return 1; | 25 return samplerType - kFirstSamplerType; |
26 case GR_GL_TEXTURE_RECTANGLE: | 26 |
27 return 2; | 27 GR_STATIC_ASSERT(kLastSamplerType - kFirstSamplerType < (1 << 4)); |
28 default: | 28 } |
29 SkFAIL("Unexpected texture target."); | 29 |
30 return 0; | 30 static uint8_t precision_key_nonzero_2_bits(GrShaderType shaderType, GrSLPrecisi
on precision, |
31 } | 31 const GrShaderCaps& caps) { |
| 32 return 1 + caps.effectiveFloatPrecision(shaderType, precision); |
| 33 |
| 34 GR_STATIC_ASSERT(1 + kLast_GrSLPrecision < (1 << 2)); |
32 } | 35 } |
33 | 36 |
34 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc, | 37 static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc, |
35 const GrGLSLCaps& caps) { | 38 const GrGLSLCaps& caps) { |
36 int numTextures = proc.numTextures(); | 39 int numTextures = proc.numTextures(); |
37 // Need two bytes per key (swizzle and target). | 40 // Need two bytes per key (swizzle, sampler type, and precision). |
38 int word32Count = (proc.numTextures() + 1) / 2; | 41 int word32Count = (proc.numTextures() + 1) / 2; |
39 if (0 == word32Count) { | 42 if (0 == word32Count) { |
40 return; | 43 return; |
41 } | 44 } |
42 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count)); | 45 uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count)); |
43 for (int i = 0; i < numTextures; ++i) { | 46 for (int i = 0; i < numTextures; ++i) { |
44 const GrTextureAccess& access = proc.textureAccess(i); | 47 const GrTextureAccess& access = proc.textureAccess(i); |
45 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()); | 48 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()); |
46 k16[i] = SkToU16(caps.configTextureSwizzle(texture->config()).asKey() | | 49 k16[i] = SkToU16(caps.configTextureSwizzle(texture->config()).asKey() | |
47 (texture_target_key(texture->target()) << 8)); | 50 (sampler_type_key_4_bits(texture->samplerType()) << 8))
; |
| 51 if (caps.usesPrecisionModifiers()) { |
| 52 GrSLPrecision p = GrPixelConfigPrecision(texture->config()); |
| 53 if (access.getVisibility() & kFragment_GrShaderFlag) { |
| 54 k16[i] |= precision_key_nonzero_2_bits(kFragment_GrShaderType, p
, caps) << 12; |
| 55 } |
| 56 if (access.getVisibility() & (kVertex_GrShaderFlag | kGeometry_GrSha
derFlag)) { |
| 57 SkASSERT(precision_key_nonzero_2_bits(kVertex_GrShaderType, p, c
aps) == |
| 58 precision_key_nonzero_2_bits(kGeometry_GrShaderType, p,
caps)); |
| 59 k16[i] |= precision_key_nonzero_2_bits(kVertex_GrShaderType, p,
caps) << 14; |
| 60 } |
| 61 } |
48 } | 62 } |
49 // zero the last 16 bits if the number of textures is odd. | 63 // zero the last 16 bits if the number of textures is odd. |
50 if (numTextures & 0x1) { | 64 if (numTextures & 0x1) { |
51 k16[numTextures] = 0; | 65 k16[numTextures] = 0; |
52 } | 66 } |
53 } | 67 } |
54 | 68 |
55 /** | 69 /** |
56 * A function which emits a meta key into the key builder. This is required bec
ause shader code may | 70 * 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 | 71 * be dependent on properties of the effect that the effect itself doesn't use |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } else { | 186 } else { |
173 header->fIgnoresCoverage = 0; | 187 header->fIgnoresCoverage = 0; |
174 } | 188 } |
175 | 189 |
176 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); | 190 header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); |
177 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); | 191 header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); |
178 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); | 192 header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); |
179 glDesc->finalize(); | 193 glDesc->finalize(); |
180 return true; | 194 return true; |
181 } | 195 } |
OLD | NEW |