Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Greg Daniel | 690a450 | 2020-04-21 09:19:51 -0400 | [diff] [blame] | 8 | #ifndef GrSpirvUniformHandler_DEFINED |
| 9 | #define GrSpirvUniformHandler_DEFINED |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 10 | |
Michael Ludwig | 4519134 | 2020-03-24 12:29:39 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrTAllocator.h" |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 12 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
| 13 | |
Greg Daniel | 690a450 | 2020-04-21 09:19:51 -0400 | [diff] [blame] | 14 | /* |
| 15 | * This class can be used for basic spir-v uniform handling. It will make a single uniform buffer |
| 16 | * for all the uniforms and will be placed in the first set and binding. Textures and samplers are |
| 17 | * placed in the second set and kept as separate objects. They are interleaved as sampler texture |
| 18 | * pairs with each object in the next binding slot. |
| 19 | */ |
| 20 | class GrSpirvUniformHandler : public GrGLSLUniformHandler { |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 21 | public: |
| 22 | static const int kUniformsPerBlock = 8; |
| 23 | |
| 24 | const GrShaderVar& getUniformVariable(UniformHandle u) const override; |
| 25 | const char* getUniformCStr(UniformHandle u) const override; |
| 26 | |
Greg Daniel | 690a450 | 2020-04-21 09:19:51 -0400 | [diff] [blame] | 27 | struct SpirvUniformInfo : public UniformInfo { |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 28 | int fUBOOffset; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 29 | }; |
Greg Daniel | 690a450 | 2020-04-21 09:19:51 -0400 | [diff] [blame] | 30 | typedef GrTAllocator<SpirvUniformInfo> UniformInfoArray; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 31 | enum { |
Stephen White | dd78efd | 2019-10-23 15:00:20 -0400 | [diff] [blame] | 32 | kUniformBinding = 0, |
Greg Daniel | 690a450 | 2020-04-21 09:19:51 -0400 | [diff] [blame] | 33 | kUniformDescriptorSet = 0, |
| 34 | kSamplerTextureDescriptorSet = 1, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 35 | }; |
Stephen White | 40c47e1 | 2019-11-01 13:13:03 -0400 | [diff] [blame] | 36 | uint32_t getRTHeightOffset() const; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 37 | |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 38 | int numUniforms() const override { |
| 39 | return fUniforms.count(); |
| 40 | } |
| 41 | |
| 42 | UniformInfo& uniform(int idx) override { |
| 43 | return fUniforms.item(idx); |
| 44 | } |
| 45 | |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 46 | private: |
Greg Daniel | 690a450 | 2020-04-21 09:19:51 -0400 | [diff] [blame] | 47 | explicit GrSpirvUniformHandler(GrGLSLProgramBuilder* program); |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 48 | |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 49 | SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 50 | const char* name, const GrShaderCaps*) override; |
| 51 | const char* samplerVariable(SamplerHandle handle) const override; |
| 52 | GrSwizzle samplerSwizzle(SamplerHandle handle) const override; |
| 53 | void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 54 | UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner, |
| 55 | uint32_t visibility, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 56 | GrSLType type, |
| 57 | const char* name, |
| 58 | bool mangleName, |
| 59 | int arrayCount, |
| 60 | const char** outName) override; |
| 61 | |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 62 | UniformInfoArray fUniforms; |
| 63 | UniformInfoArray fSamplers; |
| 64 | UniformInfoArray fTextures; |
| 65 | SkTArray<GrSwizzle> fSamplerSwizzles; |
| 66 | SkTArray<SkString> fSamplerReferences; |
Stephen White | 170d990 | 2019-08-15 16:48:24 -0400 | [diff] [blame] | 67 | |
Stephen White | dd78efd | 2019-10-23 15:00:20 -0400 | [diff] [blame] | 68 | uint32_t fCurrentUBOOffset = 0; |
Stephen White | 40c47e1 | 2019-11-01 13:13:03 -0400 | [diff] [blame] | 69 | uint32_t fRTHeightOffset = 0; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 70 | |
Greg Daniel | 5fc5c81 | 2020-04-23 10:30:23 -0400 | [diff] [blame^] | 71 | friend class GrD3DPipelineStateBuilder; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 72 | friend class GrDawnProgramBuilder; |
Greg Daniel | 5fc5c81 | 2020-04-23 10:30:23 -0400 | [diff] [blame^] | 73 | |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 74 | typedef GrGLSLUniformHandler INHERITED; |
| 75 | }; |
| 76 | |
| 77 | #endif |