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