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 | d59a91d | 2020-04-23 13:22:47 -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 | c1ed11d | 2021-08-24 11:49:55 -0400 | [diff] [blame] | 11 | #include "src/core/SkTBlockList.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 | /* |
Greg Daniel | d59a91d | 2020-04-23 13:22:47 -0400 | [diff] [blame] | 15 | * This class can be used for basic SPIR-V uniform handling. It will make a single uniform buffer |
Greg Daniel | 690a450 | 2020-04-21 09:19:51 -0400 | [diff] [blame] | 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 | */ |
Greg Daniel | d59a91d | 2020-04-23 13:22:47 -0400 | [diff] [blame] | 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 | d59a91d | 2020-04-23 13:22:47 -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 | }; |
Michael Ludwig | c1ed11d | 2021-08-24 11:49:55 -0400 | [diff] [blame] | 30 | typedef SkTBlockList<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 | }; |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 36 | uint32_t getRTFlipOffset() 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 | } |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 45 | const UniformInfo& uniform(int idx) const override { |
| 46 | return fUniforms.item(idx); |
| 47 | } |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 48 | |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 49 | private: |
Greg Daniel | d59a91d | 2020-04-23 13:22:47 -0400 | [diff] [blame] | 50 | explicit GrSPIRVUniformHandler(GrGLSLProgramBuilder* program); |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 51 | |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 52 | SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 53 | const char* name, const GrShaderCaps*) override; |
| 54 | const char* samplerVariable(SamplerHandle handle) const override; |
| 55 | GrSwizzle samplerSwizzle(SamplerHandle handle) const override; |
Jim Van Verth | 14a9b08 | 2021-09-20 14:09:52 +0000 | [diff] [blame] | 56 | void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 57 | UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner, |
| 58 | uint32_t visibility, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 59 | GrSLType type, |
| 60 | const char* name, |
| 61 | bool mangleName, |
| 62 | int arrayCount, |
| 63 | const char** outName) override; |
| 64 | |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 65 | UniformInfoArray fUniforms; |
| 66 | UniformInfoArray fSamplers; |
| 67 | UniformInfoArray fTextures; |
| 68 | SkTArray<GrSwizzle> fSamplerSwizzles; |
| 69 | SkTArray<SkString> fSamplerReferences; |
Stephen White | 170d990 | 2019-08-15 16:48:24 -0400 | [diff] [blame] | 70 | |
Stephen White | dd78efd | 2019-10-23 15:00:20 -0400 | [diff] [blame] | 71 | uint32_t fCurrentUBOOffset = 0; |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 72 | uint32_t fRTFlipOffset = 0; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 73 | |
Greg Daniel | 5fc5c81 | 2020-04-23 10:30:23 -0400 | [diff] [blame] | 74 | friend class GrD3DPipelineStateBuilder; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 75 | friend class GrDawnProgramBuilder; |
Greg Daniel | 5fc5c81 | 2020-04-23 10:30:23 -0400 | [diff] [blame] | 76 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 77 | using INHERITED = GrGLSLUniformHandler; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | #endif |