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" |
Brian Salomon | f7f5433 | 2020-07-28 09:23:35 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrShaderCaps.h" |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrTexture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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, |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 48 | const GrCaps& 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 | |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 51 | static_assert(2 == sizeof(swizzle.asKey())); |
Brian Salomon | 280fa3d | 2020-08-27 17:16:49 -0400 | [diff] [blame] | 52 | uint16_t swizzleKey = swizzle.asKey(); |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 53 | return SkToU32(samplerTypeKey | swizzleKey << kSamplerOrImageTypeKeyBits); |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 56 | static void add_pp_sampler_keys(GrProcessorKeyBuilder* b, const GrPrimitiveProcessor& pp, |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 57 | const GrCaps& caps) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 58 | int numTextureSamplers = pp.numTextureSamplers(); |
Greg Daniel | f259b8b | 2019-02-14 09:03:43 -0500 | [diff] [blame] | 59 | if (!numTextureSamplers) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 60 | return; |
| 61 | } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 62 | for (int i = 0; i < numTextureSamplers; ++i) { |
| 63 | const GrPrimitiveProcessor::TextureSampler& sampler = pp.textureSampler(i); |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 64 | const GrBackendFormat& backendFormat = sampler.backendFormat(); |
| 65 | |
| 66 | uint32_t samplerKey = sampler_key(backendFormat.textureType(), sampler.swizzle(), caps); |
| 67 | b->add32(samplerKey); |
| 68 | |
| 69 | caps.addExtraSamplerKey(b, sampler.samplerState(), backendFormat); |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 70 | } |
joshualitt | 23e280d | 2014-09-18 12:26:38 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 73 | // Currently we allow 8 bits for the class id and 24 bits for the overall processor key size |
| 74 | // (as measured in bits, so the byte count of the processor key must be < 2^21). |
| 75 | static constexpr uint32_t kClassIDBits = 8; |
| 76 | static constexpr uint32_t kKeySizeBits = 24; |
| 77 | |
| 78 | static bool processor_meta_data_fits(uint32_t classID, size_t keySize) { |
| 79 | return (classID < (1u << kClassIDBits)) && (keySize < (1u << kKeySizeBits)); |
| 80 | } |
| 81 | |
joshualitt | 23e280d | 2014-09-18 12:26:38 -0700 | [diff] [blame] | 82 | /** |
| 83 | * A function which emits a meta key into the key builder. This is required because shader code may |
| 84 | * be dependent on properties of the effect that the effect itself doesn't use |
| 85 | * in its key (e.g. the pixel format of textures used). So we create a meta-key for |
| 86 | * 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] | 87 | * 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] | 88 | * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share this |
| 89 | * 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] | 90 | */ |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 91 | static bool gen_fp_meta_key(const GrFragmentProcessor& fp, |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 92 | const GrCaps& caps, |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 93 | uint32_t transformKey, |
| 94 | GrProcessorKeyBuilder* b) { |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 95 | size_t processorKeySize = b->sizeInBits(); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 96 | uint32_t classID = fp.classID(); |
joshualitt | 89c7a2e | 2014-10-10 14:11:59 -0700 | [diff] [blame] | 97 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 98 | if (!processor_meta_data_fits(classID, processorKeySize)) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 99 | return false; |
| 100 | } |
| 101 | |
Brian Salomon | d90b3d3 | 2020-07-09 12:04:31 -0400 | [diff] [blame] | 102 | fp.visitTextureEffects([&](const GrTextureEffect& te) { |
| 103 | const GrBackendFormat& backendFormat = te.view().proxy()->backendFormat(); |
| 104 | uint32_t samplerKey = sampler_key(backendFormat.textureType(), te.view().swizzle(), caps); |
| 105 | b->add32(samplerKey); |
| 106 | caps.addExtraSamplerKey(b, te.samplerState(), backendFormat); |
| 107 | }); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 108 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 109 | b->addBits(kClassIDBits, classID, "fpClassID"); |
| 110 | b->addBits(kKeySizeBits, processorKeySize, "fpKeySize"); |
| 111 | b->add32(transformKey, "fpTransforms"); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 112 | return true; |
| 113 | } |
| 114 | |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 115 | static bool gen_pp_meta_key(const GrPrimitiveProcessor& pp, |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 116 | const GrCaps& caps, |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 117 | GrProcessorKeyBuilder* b) { |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 118 | size_t processorKeySize = b->sizeInBits(); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 119 | uint32_t classID = pp.classID(); |
| 120 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 121 | if (!processor_meta_data_fits(classID, processorKeySize)) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 122 | return false; |
| 123 | } |
| 124 | |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 125 | add_pp_sampler_keys(b, pp, caps); |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 126 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 127 | b->addBits(kClassIDBits, classID, "ppClassID"); |
| 128 | b->addBits(kKeySizeBits, processorKeySize, "ppKeySize"); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 129 | return true; |
| 130 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 131 | |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 132 | static bool gen_xp_meta_key(const GrXferProcessor& xp, GrProcessorKeyBuilder* b) { |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 133 | size_t processorKeySize = b->sizeInBits(); |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 134 | uint32_t classID = xp.classID(); |
| 135 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 136 | if (!processor_meta_data_fits(classID, processorKeySize)) { |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 137 | return false; |
| 138 | } |
| 139 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 140 | b->addBits(kClassIDBits, classID, "xpClassID"); |
| 141 | b->addBits(kKeySizeBits, processorKeySize, "xpKeySize"); |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 142 | return true; |
| 143 | } |
| 144 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 145 | static bool gen_frag_proc_and_meta_keys(const GrFragmentProcessor& fp, |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 146 | const GrCaps& caps, |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 147 | GrProcessorKeyBuilder* b) { |
| 148 | for (int i = 0; i < fp.numChildProcessors(); ++i) { |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 149 | if (auto child = fp.childProcessor(i)) { |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 150 | if (!gen_frag_proc_and_meta_keys(*child, caps, b)) { |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 151 | return false; |
| 152 | } |
| 153 | } else { |
| 154 | // Fold in a sentinel value as the "class ID" for any null children |
| 155 | b->add32(GrProcessor::ClassID::kNull_ClassID); |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 159 | b->addString([&](){ return fp.name(); }); |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 160 | fp.getGLSLProcessorKey(*caps.shaderCaps(), b); |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 161 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 162 | return gen_fp_meta_key(fp, caps, GrPrimitiveProcessor::ComputeCoordTransformsKey(fp), b); |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Brian Salomon | f7f5433 | 2020-07-28 09:23:35 -0400 | [diff] [blame] | 165 | bool GrProgramDesc::Build(GrProgramDesc* desc, |
| 166 | GrRenderTarget* renderTarget, |
| 167 | const GrProgramInfo& programInfo, |
| 168 | const GrCaps& caps) { |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame] | 169 | #ifdef SK_DEBUG |
| 170 | if (renderTarget) { |
| 171 | SkASSERT(programInfo.backendFormat() == renderTarget->backendFormat()); |
| 172 | } |
| 173 | #endif |
| 174 | |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 175 | // The descriptor is used as a cache key. Thus when a field of the |
| 176 | // descriptor will not affect program generation (because of the attribute |
| 177 | // bindings in use or other descriptor field settings) it should be set |
| 178 | // to a canonical value to avoid duplicate programs with different keys. |
| 179 | |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 180 | desc->key().reset(); |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 181 | GrProcessorKeyBuilder b(&desc->key()); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 182 | |
John Stiles | d3feb6f | 2020-07-23 18:18:12 -0400 | [diff] [blame] | 183 | const GrPrimitiveProcessor& primitiveProcessor = programInfo.primProc(); |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 184 | b.addString([&](){ return primitiveProcessor.name(); }); |
John Stiles | d3feb6f | 2020-07-23 18:18:12 -0400 | [diff] [blame] | 185 | primitiveProcessor.getGLSLProcessorKey(*caps.shaderCaps(), &b); |
| 186 | primitiveProcessor.getAttributeKey(&b); |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 187 | if (!gen_pp_meta_key(primitiveProcessor, caps, &b)) { |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 188 | desc->key().reset(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 189 | return false; |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 190 | } |
bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 191 | |
John Stiles | d3feb6f | 2020-07-23 18:18:12 -0400 | [diff] [blame] | 192 | const GrPipeline& pipeline = programInfo.pipeline(); |
| 193 | int numColorFPs = 0, numCoverageFPs = 0; |
| 194 | for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) { |
| 195 | const GrFragmentProcessor& fp = pipeline.getFragmentProcessor(i); |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 196 | if (!gen_frag_proc_and_meta_keys(fp, caps, &b)) { |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 197 | desc->key().reset(); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 198 | return false; |
| 199 | } |
John Stiles | d3feb6f | 2020-07-23 18:18:12 -0400 | [diff] [blame] | 200 | if (pipeline.isColorFragmentProcessor(i)) { |
| 201 | ++numColorFPs; |
| 202 | } else if (pipeline.isCoverageFragmentProcessor(i)) { |
| 203 | ++numCoverageFPs; |
| 204 | } |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 205 | } |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 206 | |
John Stiles | d3feb6f | 2020-07-23 18:18:12 -0400 | [diff] [blame] | 207 | const GrXferProcessor& xp = pipeline.getXferProcessor(); |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 208 | const GrSurfaceOrigin* originIfDstTexture = nullptr; |
| 209 | GrSurfaceOrigin origin; |
John Stiles | d3feb6f | 2020-07-23 18:18:12 -0400 | [diff] [blame] | 210 | if (pipeline.dstProxyView().proxy()) { |
| 211 | origin = pipeline.dstProxyView().origin(); |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 212 | originIfDstTexture = &origin; |
| 213 | } |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 214 | b.addString([&](){ return xp.name(); }); |
Greg Daniel | 70dd6a9 | 2020-10-09 10:09:06 -0400 | [diff] [blame] | 215 | xp.getGLSLProcessorKey(*caps.shaderCaps(), &b, originIfDstTexture, pipeline.dstSampleType()); |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 216 | if (!gen_xp_meta_key(xp, &b)) { |
egdaniel | 5d8f69f | 2016-09-07 07:24:12 -0700 | [diff] [blame] | 217 | desc->key().reset(); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 218 | return false; |
| 219 | } |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 220 | |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 221 | if (programInfo.requestedFeatures() & GrProcessor::CustomFeatures::kSampleLocations) { |
John Stiles | d3feb6f | 2020-07-23 18:18:12 -0400 | [diff] [blame] | 222 | SkASSERT(pipeline.isHWAntialiasState()); |
Brian Salomon | f7f5433 | 2020-07-28 09:23:35 -0400 | [diff] [blame] | 223 | b.add32(renderTarget->getSamplePatternKey()); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 224 | } |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 225 | |
Brian Osman | 9b510a3 | 2021-02-26 14:29:39 -0500 | [diff] [blame] | 226 | // Add "header" metadata |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 227 | b.addBits(16, pipeline.writeSwizzle().asKey(), "writeSwizzle"); |
| 228 | b.addBits( 1, numColorFPs, "numColorFPs"); |
| 229 | b.addBits( 2, numCoverageFPs, "numCoverageFPs"); |
Robert Phillips | 2579de4 | 2019-10-09 09:51:59 -0400 | [diff] [blame] | 230 | // If we knew the shader won't depend on origin, we could skip this (and use the same program |
| 231 | // for both origins). Instrumenting all fragment processors would be difficult and error prone. |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 232 | b.addBits( 2, GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(programInfo.origin()), "origin"); |
| 233 | b.addBits( 1, static_cast<uint32_t>(programInfo.requestedFeatures()), "requestedFeatures"); |
| 234 | b.addBits( 1, pipeline.snapVerticesToPixelCenters(), "snapVertices"); |
Robert Phillips | fcaae48 | 2019-11-07 10:17:03 -0500 | [diff] [blame] | 235 | // The base descriptor only stores whether or not the primitiveType is kPoints. Backend- |
| 236 | // specific versions (e.g., Vulkan) require more detail |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 237 | b.addBits( 1, (programInfo.primitiveType() == GrPrimitiveType::kPoints), "isPoints"); |
Robert Phillips | c15e890 | 2019-11-26 14:26:36 -0500 | [diff] [blame] | 238 | |
Brian Osman | bbbf1a7 | 2021-02-26 13:54:11 -0500 | [diff] [blame] | 239 | // This keyLength includes any partial uint32_t that's been written (rounded up). |
| 240 | // The GrProcessorKeyBuilder destructor will call flush() when we exit this function, putting |
| 241 | // a clean break between the "common" data written by this function, and any backend-specific |
| 242 | // data appended later. |
Brian Osman | 9b510a3 | 2021-02-26 14:29:39 -0500 | [diff] [blame] | 243 | desc->fInitialKeyLength = desc->keyLength(); |
Robert Phillips | c15e890 | 2019-11-26 14:26:36 -0500 | [diff] [blame] | 244 | |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 245 | return true; |
| 246 | } |