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" |
Brian Salomon | a59925f | 2021-09-16 09:25:47 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrUniformDataManager.h" |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 13 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
| 14 | |
Greg Daniel | 690a450 | 2020-04-21 09:19:51 -0400 | [diff] [blame] | 15 | /* |
Greg Daniel | d59a91d | 2020-04-23 13:22:47 -0400 | [diff] [blame] | 16 | * 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] | 17 | * for all the uniforms and will be placed in the first set and binding. Textures and samplers are |
| 18 | * placed in the second set and kept as separate objects. They are interleaved as sampler texture |
| 19 | * pairs with each object in the next binding slot. |
| 20 | */ |
Greg Daniel | d59a91d | 2020-04-23 13:22:47 -0400 | [diff] [blame] | 21 | class GrSPIRVUniformHandler : public GrGLSLUniformHandler { |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 22 | public: |
| 23 | static const int kUniformsPerBlock = 8; |
| 24 | |
| 25 | const GrShaderVar& getUniformVariable(UniformHandle u) const override; |
| 26 | const char* getUniformCStr(UniformHandle u) const override; |
| 27 | |
Greg Daniel | d59a91d | 2020-04-23 13:22:47 -0400 | [diff] [blame] | 28 | struct SPIRVUniformInfo : public UniformInfo { |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 29 | int fUBOOffset; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 30 | }; |
Michael Ludwig | c1ed11d | 2021-08-24 11:49:55 -0400 | [diff] [blame] | 31 | typedef SkTBlockList<SPIRVUniformInfo> UniformInfoArray; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 32 | enum { |
Stephen White | dd78efd | 2019-10-23 15:00:20 -0400 | [diff] [blame] | 33 | kUniformBinding = 0, |
Greg Daniel | 690a450 | 2020-04-21 09:19:51 -0400 | [diff] [blame] | 34 | kUniformDescriptorSet = 0, |
| 35 | kSamplerTextureDescriptorSet = 1, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 36 | }; |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 37 | uint32_t getRTFlipOffset() const; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 38 | |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 39 | int numUniforms() const override { |
| 40 | return fUniforms.count(); |
| 41 | } |
| 42 | |
| 43 | UniformInfo& uniform(int idx) override { |
| 44 | return fUniforms.item(idx); |
| 45 | } |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 46 | const UniformInfo& uniform(int idx) const override { |
| 47 | return fUniforms.item(idx); |
| 48 | } |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 49 | |
Brian Salomon | a59925f | 2021-09-16 09:25:47 -0400 | [diff] [blame] | 50 | /** |
| 51 | * Call after all legacy style uniforms have been added to assign offsets to new style uniforms |
| 52 | * and create the data structure needed to transfer new style uniforms to GrUniformDataManager. |
| 53 | * This must be called before appendUniformDecls() in order to ensure new style uniforms get |
| 54 | * declared. It must be called only once. |
| 55 | */ |
| 56 | GrUniformDataManager::ProgramUniforms getNewProgramUniforms(const GrUniformAggregator&); |
| 57 | |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 58 | private: |
Greg Daniel | d59a91d | 2020-04-23 13:22:47 -0400 | [diff] [blame] | 59 | explicit GrSPIRVUniformHandler(GrGLSLProgramBuilder* program); |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 60 | |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 61 | SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 62 | const char* name, const GrShaderCaps*) override; |
| 63 | const char* samplerVariable(SamplerHandle handle) const override; |
| 64 | GrSwizzle samplerSwizzle(SamplerHandle handle) const override; |
Brian Salomon | a59925f | 2021-09-16 09:25:47 -0400 | [diff] [blame] | 65 | void appendUniformDecls(const GrUniformAggregator&, |
| 66 | GrShaderFlags visibility, |
| 67 | SkString*) const override; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 68 | UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner, |
| 69 | uint32_t visibility, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 70 | GrSLType type, |
| 71 | const char* name, |
| 72 | bool mangleName, |
| 73 | int arrayCount, |
| 74 | const char** outName) override; |
| 75 | |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 76 | UniformInfoArray fUniforms; |
Brian Salomon | a59925f | 2021-09-16 09:25:47 -0400 | [diff] [blame] | 77 | UniformInfoArray fNewUniforms; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 78 | UniformInfoArray fSamplers; |
| 79 | UniformInfoArray fTextures; |
| 80 | SkTArray<GrSwizzle> fSamplerSwizzles; |
| 81 | SkTArray<SkString> fSamplerReferences; |
Stephen White | 170d990 | 2019-08-15 16:48:24 -0400 | [diff] [blame] | 82 | |
Stephen White | dd78efd | 2019-10-23 15:00:20 -0400 | [diff] [blame] | 83 | uint32_t fCurrentUBOOffset = 0; |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 84 | uint32_t fRTFlipOffset = 0; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 85 | |
Greg Daniel | 5fc5c81 | 2020-04-23 10:30:23 -0400 | [diff] [blame] | 86 | friend class GrD3DPipelineStateBuilder; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 87 | friend class GrDawnProgramBuilder; |
Greg Daniel | 5fc5c81 | 2020-04-23 10:30:23 -0400 | [diff] [blame] | 88 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 89 | using INHERITED = GrGLSLUniformHandler; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | #endif |