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 "include/private/gpu/ganesh/GrTypesPriv.h" 13 #include "src/base/SkTBlockList.h" 14 #include "src/gpu/Swizzle.h" 15 #include "src/gpu/ganesh/GrSamplerState.h" 16 #include "src/gpu/ganesh/glsl/GrGLSLUniformHandler.h" 17 18 #include <cstdint> 19 20 class GrBackendFormat; 21 class GrGLSLProgramBuilder; 22 class GrProcessor; 23 class GrShaderVar; 24 class SkString; 25 enum class SkSLType : char; 26 struct GrShaderCaps; 27 28 /* 29 * This class can be used for basic SPIR-V uniform handling. It will make a single uniform buffer 30 * for all the uniforms and will be placed in the first set and binding. Textures and samplers are 31 * placed in the second set and kept as separate objects. They are interleaved as sampler texture 32 * pairs with each object in the next binding slot. 33 */ 34 class GrSPIRVUniformHandler : public GrGLSLUniformHandler { 35 public: 36 const GrShaderVar& getUniformVariable(UniformHandle u) const override; 37 const char* getUniformCStr(UniformHandle u) const override; 38 39 struct SPIRVUniformInfo : public UniformInfo { 40 int fUBOOffset; 41 }; 42 typedef SkTBlockList<SPIRVUniformInfo> UniformInfoArray; 43 static constexpr int kUniformDescriptorSet = 0; 44 static constexpr int kSamplerTextureDescriptorSet = 1; 45 46 uint32_t getRTFlipOffset() const; 47 numUniforms()48 int numUniforms() const override { 49 return fUniforms.count(); 50 } 51 uniform(int idx)52 UniformInfo& uniform(int idx) override { 53 return fUniforms.item(idx); 54 } uniform(int idx)55 const UniformInfo& uniform(int idx) const override { 56 return fUniforms.item(idx); 57 } 58 59 private: 60 explicit GrSPIRVUniformHandler(GrGLSLProgramBuilder* program); 61 62 SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const skgpu::Swizzle&, 63 const char* name, const GrShaderCaps*) override; 64 const char* samplerVariable(SamplerHandle handle) const override; 65 skgpu::Swizzle samplerSwizzle(SamplerHandle handle) const override; 66 void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; 67 UniformHandle internalAddUniformArray(const GrProcessor* owner, 68 uint32_t visibility, 69 SkSLType type, 70 const char* name, 71 bool mangleName, 72 int arrayCount, 73 const char** outName) override; 74 75 UniformInfoArray fUniforms; 76 UniformInfoArray fSamplers; 77 skia_private::TArray<skgpu::Swizzle> fSamplerSwizzles; 78 79 uint32_t fCurrentUBOOffset = 0; 80 uint32_t fRTFlipOffset = 0; 81 82 friend class GrD3DPipelineStateBuilder; 83 friend class GrDawnProgramBuilder; 84 85 using INHERITED = GrGLSLUniformHandler; 86 }; 87 88 #endif 89