bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 1 | /* |
egdaniel | 0d9990f | 2016-07-29 07:36:52 -0700 | [diff] [blame] | 2 | * Copyright 2016 Google Inc. |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrProgramDesc.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/private/SkChecksum.h" |
| 11 | #include "include/private/SkTo.h" |
| 12 | #include "src/gpu/GrPipeline.h" |
| 13 | #include "src/gpu/GrPrimitiveProcessor.h" |
| 14 | #include "src/gpu/GrProcessor.h" |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrProgramInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrRenderTargetPriv.h" |
| 17 | #include "src/gpu/GrShaderCaps.h" |
| 18 | #include "src/gpu/GrTexturePriv.h" |
| 19 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 20 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 21 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 22 | enum { |
| 23 | kSamplerOrImageTypeKeyBits = 4 |
| 24 | }; |
Brian Salomon | be34882 | 2016-11-22 15:56:30 -0500 | [diff] [blame] | 25 | |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 26 | static inline uint16_t texture_type_key(GrTextureType type) { |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 27 | int value = UINT16_MAX; |
| 28 | switch (type) { |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 29 | case GrTextureType::k2D: |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 30 | value = 0; |
| 31 | break; |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 32 | case GrTextureType::kExternal: |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 33 | value = 1; |
| 34 | break; |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 35 | case GrTextureType::kRectangle: |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 36 | value = 2; |
| 37 | break; |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 38 | default: |
| 39 | SK_ABORT("Unexpected texture type"); |
| 40 | value = 3; |
| 41 | break; |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 42 | } |
| 43 | SkASSERT((value & ((1 << kSamplerOrImageTypeKeyBits) - 1)) == value); |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 44 | return SkToU16(value); |
Brian Salomon | be34882 | 2016-11-22 15:56:30 -0500 | [diff] [blame] | 45 | } |
| 46 | |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 47 | static uint32_t sampler_key(GrTextureType textureType, const GrSwizzle& swizzle, |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 48 | const GrShaderCaps& caps) { |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 49 | int samplerTypeKey = texture_type_key(textureType); |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 50 | |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 51 | GR_STATIC_ASSERT(2 == sizeof(swizzle.asKey())); |
Brian Salomon | 68ba117 | 2019-06-05 11:15:08 -0400 | [diff] [blame] | 52 | uint16_t swizzleKey = 0; |
| 53 | if (caps.textureSwizzleAppliedInShader()) { |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 54 | swizzleKey = swizzle.asKey(); |
Brian Salomon | 68ba117 | 2019-06-05 11:15:08 -0400 | [diff] [blame] | 55 | } |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 56 | return SkToU32(samplerTypeKey | swizzleKey << kSamplerOrImageTypeKeyBits); |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 57 | } |
| 58 | |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 59 | static void add_fp_sampler_keys(GrProcessorKeyBuilder* b, const GrFragmentProcessor& fp, |
| 60 | GrGpu* gpu, const GrShaderCaps& caps) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 61 | int numTextureSamplers = fp.numTextureSamplers(); |
Greg Daniel | f259b8b | 2019-02-14 09:03:43 -0500 | [diff] [blame] | 62 | if (!numTextureSamplers) { |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 63 | return; |
joshualitt | 23e280d | 2014-09-18 12:26:38 -0700 | [diff] [blame] | 64 | } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 65 | for (int i = 0; i < numTextureSamplers; ++i) { |
| 66 | const GrFragmentProcessor::TextureSampler& sampler = fp.textureSampler(i); |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 67 | const GrTexture* tex = sampler.peekTexture(); |
Brian Osman | 1a22b7f | 2019-07-23 09:32:08 -0400 | [diff] [blame] | 68 | uint32_t samplerKey = sampler_key( |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 69 | tex->texturePriv().textureType(), sampler.swizzle(), caps); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 70 | uint32_t extraSamplerKey = gpu->getExtraSamplerKeyForProgram( |
| 71 | sampler.samplerState(), sampler.proxy()->backendFormat()); |
| 72 | if (extraSamplerKey) { |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 73 | // We first mark the normal sampler key with last bit to flag that it has an extra |
Brian Osman | 1a22b7f | 2019-07-23 09:32:08 -0400 | [diff] [blame] | 74 | // sampler key. We then add both keys. |
| 75 | SkASSERT((samplerKey & (1 << 31)) == 0); |
| 76 | b->add32(samplerKey | (1 << 31)); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 77 | b->add32(extraSamplerKey); |
Brian Osman | 1a22b7f | 2019-07-23 09:32:08 -0400 | [diff] [blame] | 78 | } else { |
| 79 | b->add32(samplerKey); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 80 | } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 81 | } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 82 | } |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 83 | |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 84 | static void add_pp_sampler_keys(GrProcessorKeyBuilder* b, const GrPrimitiveProcessor& pp, |
| 85 | const GrShaderCaps& caps) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 86 | int numTextureSamplers = pp.numTextureSamplers(); |
Greg Daniel | f259b8b | 2019-02-14 09:03:43 -0500 | [diff] [blame] | 87 | if (!numTextureSamplers) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 88 | return; |
| 89 | } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 90 | for (int i = 0; i < numTextureSamplers; ++i) { |
| 91 | const GrPrimitiveProcessor::TextureSampler& sampler = pp.textureSampler(i); |
Brian Osman | 1a22b7f | 2019-07-23 09:32:08 -0400 | [diff] [blame] | 92 | uint32_t samplerKey = sampler_key( |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 93 | sampler.textureType(), sampler.swizzle(), caps); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 94 | uint32_t extraSamplerKey = sampler.extraSamplerKey(); |
| 95 | if (extraSamplerKey) { |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 96 | // We first mark the normal sampler key with last bit to flag that it has an extra |
Brian Osman | 1a22b7f | 2019-07-23 09:32:08 -0400 | [diff] [blame] | 97 | // sampler key. We then add both keys. |
| 98 | SkASSERT((samplerKey & (1 << 31)) == 0); |
| 99 | b->add32(samplerKey | (1 << 31)); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 100 | b->add32(extraSamplerKey); |
Brian Osman | 1a22b7f | 2019-07-23 09:32:08 -0400 | [diff] [blame] | 101 | } else { |
| 102 | b->add32(samplerKey); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 103 | } |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 104 | } |
joshualitt | 23e280d | 2014-09-18 12:26:38 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
| 108 | * A function which emits a meta key into the key builder. This is required because shader code may |
| 109 | * be dependent on properties of the effect that the effect itself doesn't use |
| 110 | * in its key (e.g. the pixel format of textures used). So we create a meta-key for |
| 111 | * every effect using this function. It is also responsible for inserting the effect's class ID |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 112 | * which must be different for every GrProcessor subclass. It can fail if an effect uses too many |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 113 | * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share this |
| 114 | * function because it is hairy, though FPs do not have attribs, and GPs do not have transforms |
joshualitt | 23e280d | 2014-09-18 12:26:38 -0700 | [diff] [blame] | 115 | */ |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 116 | static bool gen_fp_meta_key(const GrFragmentProcessor& fp, |
| 117 | GrGpu* gpu, |
| 118 | const GrShaderCaps& shaderCaps, |
| 119 | uint32_t transformKey, |
| 120 | GrProcessorKeyBuilder* b) { |
egdaniel | c67870c | 2014-11-26 08:50:50 -0800 | [diff] [blame] | 121 | size_t processorKeySize = b->size(); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 122 | uint32_t classID = fp.classID(); |
joshualitt | 89c7a2e | 2014-10-10 14:11:59 -0700 | [diff] [blame] | 123 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 124 | // Currently we allow 16 bits for the class id and the overall processor key size. |
Ben Wagner | b089765 | 2018-06-15 15:37:57 +0000 | [diff] [blame] | 125 | static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)UINT16_MAX); |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 126 | if ((processorKeySize | classID) & kMetaKeyInvalidMask) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 127 | return false; |
| 128 | } |
| 129 | |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 130 | add_fp_sampler_keys(b, fp, gpu, shaderCaps); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 131 | |
| 132 | uint32_t* key = b->add32n(2); |
| 133 | key[0] = (classID << 16) | SkToU32(processorKeySize); |
| 134 | key[1] = transformKey; |
| 135 | return true; |
| 136 | } |
| 137 | |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 138 | static bool gen_pp_meta_key(const GrPrimitiveProcessor& pp, |
| 139 | const GrShaderCaps& shaderCaps, |
| 140 | uint32_t transformKey, |
| 141 | GrProcessorKeyBuilder* b) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 142 | size_t processorKeySize = b->size(); |
| 143 | uint32_t classID = pp.classID(); |
| 144 | |
| 145 | // Currently we allow 16 bits for the class id and the overall processor key size. |
| 146 | static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)UINT16_MAX); |
| 147 | if ((processorKeySize | classID) & kMetaKeyInvalidMask) { |
| 148 | return false; |
| 149 | } |
| 150 | |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 151 | add_pp_sampler_keys(b, pp, shaderCaps); |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 152 | |
| 153 | uint32_t* key = b->add32n(2); |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 154 | key[0] = (classID << 16) | SkToU32(processorKeySize); |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 155 | key[1] = transformKey; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 156 | return true; |
| 157 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 158 | |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 159 | static bool gen_xp_meta_key(const GrXferProcessor& xp, |
| 160 | const GrShaderCaps& shaderCaps, |
| 161 | GrProcessorKeyBuilder* b) { |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 162 | size_t processorKeySize = b->size(); |
| 163 | uint32_t classID = xp.classID(); |
| 164 | |
| 165 | // Currently we allow 16 bits for the class id and the overall processor key size. |
Ben Wagner | b089765 | 2018-06-15 15:37:57 +0000 | [diff] [blame] | 166 | static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)UINT16_MAX); |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 167 | if ((processorKeySize | classID) & kMetaKeyInvalidMask) { |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | b->add32((classID << 16) | SkToU32(processorKeySize)); |
| 172 | return true; |
| 173 | } |
| 174 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 175 | static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 176 | const GrFragmentProcessor& fp, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 177 | GrGpu* gpu, |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 178 | const GrShaderCaps& shaderCaps, |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 179 | GrProcessorKeyBuilder* b) { |
| 180 | for (int i = 0; i < fp.numChildProcessors(); ++i) { |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 181 | if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), gpu, shaderCaps, b)) { |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 182 | return false; |
| 183 | } |
| 184 | } |
| 185 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 186 | fp.getGLSLProcessorKey(shaderCaps, b); |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 187 | |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 188 | return gen_fp_meta_key(fp, gpu, shaderCaps, primProc.getTransformKey(fp.coordTransforms(), |
| 189 | fp.numCoordTransforms()), |
| 190 | b); |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 193 | bool GrProgramDesc::Build(GrProgramDesc* desc, const GrRenderTarget* renderTarget, |
Robert Phillips | fcaae48 | 2019-11-07 10:17:03 -0500 | [diff] [blame^] | 194 | const GrProgramInfo& programInfo, GrGpu* gpu) { |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 195 | // The descriptor is used as a cache key. Thus when a field of the |
| 196 | // descriptor will not affect program generation (because of the attribute |
| 197 | // bindings in use or other descriptor field settings) it should be set |
| 198 | // to a canonical value to avoid duplicate programs with different keys. |
| 199 | |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 200 | const GrShaderCaps& shaderCaps = *gpu->caps()->shaderCaps(); |
| 201 | |
egdaniel | c67870c | 2014-11-26 08:50:50 -0800 | [diff] [blame] | 202 | GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); |
| 203 | // Make room for everything up to the effect keys. |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 204 | desc->key().reset(); |
| 205 | desc->key().push_back_n(kProcessorKeysOffset); |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 206 | |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 207 | GrProcessorKeyBuilder b(&desc->key()); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 208 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 209 | programInfo.primProc().getGLSLProcessorKey(shaderCaps, &b); |
| 210 | programInfo.primProc().getAttributeKey(&b); |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 211 | if (!gen_pp_meta_key(programInfo.primProc(), shaderCaps, 0, &b)) { |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 212 | desc->key().reset(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 213 | return false; |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 214 | } |
bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 215 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 216 | for (int i = 0; i < programInfo.pipeline().numFragmentProcessors(); ++i) { |
| 217 | const GrFragmentProcessor& fp = programInfo.pipeline().getFragmentProcessor(i); |
| 218 | if (!gen_frag_proc_and_meta_keys(programInfo.primProc(), fp, gpu, shaderCaps, &b)) { |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 219 | desc->key().reset(); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 220 | return false; |
| 221 | } |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 222 | } |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 223 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 224 | const GrXferProcessor& xp = programInfo.pipeline().getXferProcessor(); |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 225 | const GrSurfaceOrigin* originIfDstTexture = nullptr; |
| 226 | GrSurfaceOrigin origin; |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 227 | if (programInfo.pipeline().dstProxyView().proxy()) { |
| 228 | origin = programInfo.pipeline().dstProxyView().origin(); |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 229 | originIfDstTexture = &origin; |
| 230 | } |
| 231 | xp.getGLSLProcessorKey(shaderCaps, &b, originIfDstTexture); |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 232 | if (!gen_xp_meta_key(xp, shaderCaps, &b)) { |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 233 | desc->key().reset(); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 234 | return false; |
| 235 | } |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 236 | |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 237 | if (programInfo.requestedFeatures() & GrProcessor::CustomFeatures::kSampleLocations) { |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 238 | SkASSERT(programInfo.pipeline().isHWAntialiasState()); |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 239 | b.add32(renderTarget->renderTargetPriv().getSamplePatternKey()); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 240 | } |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 241 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 242 | // --------DO NOT MOVE HEADER ABOVE THIS LINE-------------------------------------------------- |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 243 | // Because header is a pointer into the dynamic array, we can't push any new data into the key |
| 244 | // below here. |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 245 | KeyHeader* header = desc->atOffset<KeyHeader, kHeaderOffset>(); |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 246 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 247 | // make sure any padding in the header is zeroed. |
| 248 | memset(header, 0, kHeaderSize); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 249 | header->fOutputSwizzle = programInfo.pipeline().outputSwizzle().asKey(); |
| 250 | header->fColorFragmentProcessorCnt = programInfo.pipeline().numColorFragmentProcessors(); |
| 251 | header->fCoverageFragmentProcessorCnt = programInfo.pipeline().numCoverageFragmentProcessors(); |
bsalomon | 2eda5b3 | 2016-09-21 10:53:24 -0700 | [diff] [blame] | 252 | // Fail if the client requested more processors than the key can fit. |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 253 | if (header->fColorFragmentProcessorCnt != programInfo.pipeline().numColorFragmentProcessors() || |
| 254 | header->fCoverageFragmentProcessorCnt != |
| 255 | programInfo.pipeline().numCoverageFragmentProcessors()) { |
bsalomon | 2eda5b3 | 2016-09-21 10:53:24 -0700 | [diff] [blame] | 256 | return false; |
| 257 | } |
Robert Phillips | 2579de4 | 2019-10-09 09:51:59 -0400 | [diff] [blame] | 258 | // If we knew the shader won't depend on origin, we could skip this (and use the same program |
| 259 | // for both origins). Instrumenting all fragment processors would be difficult and error prone. |
| 260 | header->fSurfaceOriginKey = |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 261 | GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(programInfo.origin()); |
| 262 | header->fProcessorFeatures = (uint8_t)programInfo.requestedFeatures(); |
| 263 | // Ensure enough bits. |
| 264 | SkASSERT(header->fProcessorFeatures == (int) programInfo.requestedFeatures()); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 265 | header->fSnapVerticesToPixelCenters = programInfo.pipeline().snapVerticesToPixelCenters(); |
Robert Phillips | fcaae48 | 2019-11-07 10:17:03 -0500 | [diff] [blame^] | 266 | // The base descriptor only stores whether or not the primitiveType is kPoints. Backend- |
| 267 | // specific versions (e.g., Vulkan) require more detail |
| 268 | header->fHasPointSize = (programInfo.primitiveType() == GrPrimitiveType::kPoints); |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 269 | return true; |
| 270 | } |