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 8 #ifndef GrSPIRVUniformHandler_DEFINED 9 #define GrSPIRVUniformHandler_DEFINED 10 11 #include "include/private/base/SkTArray.h" 12 #include "src/base/SkTBlockList.h" 13 #include "src/gpu/ganesh/glsl/GrGLSLUniformHandler.h" 14 15 /* 16 * This class can be used for basic SPIR-V uniform handling. It will make a single uniform buffer 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 */ 21 class GrSPIRVUniformHandler : public GrGLSLUniformHandler { 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 28 struct SPIRVUniformInfo : public UniformInfo { 29 int fUBOOffset; 30 }; 31 typedef SkTBlockList<SPIRVUniformInfo> UniformInfoArray; 32 enum { 33 kUniformBinding = 0, 34 kUniformDescriptorSet = 0, 35 kSamplerTextureDescriptorSet = 1, 36 }; 37 uint32_t getRTFlipOffset() const; 38 numUniforms()39 int numUniforms() const override { 40 return fUniforms.count(); 41 } 42 uniform(int idx)43 UniformInfo& uniform(int idx) override { 44 return fUniforms.item(idx); 45 } uniform(int idx)46 const UniformInfo& uniform(int idx) const override { 47 return fUniforms.item(idx); 48 } 49 50 private: 51 explicit GrSPIRVUniformHandler(GrGLSLProgramBuilder* program); 52 53 SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const skgpu::Swizzle&, 54 const char* name, const GrShaderCaps*) override; 55 const char* samplerVariable(SamplerHandle handle) const override; 56 skgpu::Swizzle samplerSwizzle(SamplerHandle handle) const override; 57 void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; 58 UniformHandle internalAddUniformArray(const GrProcessor* owner, 59 uint32_t visibility, 60 SkSLType type, 61 const char* name, 62 bool mangleName, 63 int arrayCount, 64 const char** outName) override; 65 66 UniformInfoArray fUniforms; 67 UniformInfoArray fSamplers; 68 skia_private::TArray<skgpu::Swizzle> fSamplerSwizzles; 69 70 uint32_t fCurrentUBOOffset = 0; 71 uint32_t fRTFlipOffset = 0; 72 73 friend class GrD3DPipelineStateBuilder; 74 friend class GrDawnProgramBuilder; 75 76 using INHERITED = GrGLSLUniformHandler; 77 }; 78 79 #endif 80