blob: 5cb1aaa911c5a9987a1380495fac9a93f66227db [file] [log] [blame]
Stephen White4da34bf2019-07-30 10:37:47 -04001/*
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 Danield59a91d2020-04-23 13:22:47 -04008#ifndef GrSPIRVUniformHandler_DEFINED
9#define GrSPIRVUniformHandler_DEFINED
Stephen White4da34bf2019-07-30 10:37:47 -040010
Michael Ludwigc1ed11d2021-08-24 11:49:55 -040011#include "src/core/SkTBlockList.h"
Stephen White4da34bf2019-07-30 10:37:47 -040012#include "src/gpu/glsl/GrGLSLUniformHandler.h"
13
Greg Daniel690a4502020-04-21 09:19:51 -040014/*
Greg Danield59a91d2020-04-23 13:22:47 -040015 * This class can be used for basic SPIR-V uniform handling. It will make a single uniform buffer
Greg Daniel690a4502020-04-21 09:19:51 -040016 * 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 Danield59a91d2020-04-23 13:22:47 -040020class GrSPIRVUniformHandler : public GrGLSLUniformHandler {
Stephen White4da34bf2019-07-30 10:37:47 -040021public:
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 Danield59a91d2020-04-23 13:22:47 -040027 struct SPIRVUniformInfo : public UniformInfo {
Ethan Nicholas16464c32020-04-06 13:53:05 -040028 int fUBOOffset;
Stephen White4da34bf2019-07-30 10:37:47 -040029 };
Michael Ludwigc1ed11d2021-08-24 11:49:55 -040030 typedef SkTBlockList<SPIRVUniformInfo> UniformInfoArray;
Stephen White4da34bf2019-07-30 10:37:47 -040031 enum {
Stephen Whitedd78efd2019-10-23 15:00:20 -040032 kUniformBinding = 0,
Greg Daniel690a4502020-04-21 09:19:51 -040033 kUniformDescriptorSet = 0,
34 kSamplerTextureDescriptorSet = 1,
Stephen White4da34bf2019-07-30 10:37:47 -040035 };
Brian Salomond8d85b92021-07-07 09:41:17 -040036 uint32_t getRTFlipOffset() const;
Stephen White4da34bf2019-07-30 10:37:47 -040037
Ethan Nicholas58430122020-04-14 09:54:02 -040038 int numUniforms() const override {
39 return fUniforms.count();
40 }
41
42 UniformInfo& uniform(int idx) override {
43 return fUniforms.item(idx);
44 }
Michael Ludwige88320b2020-06-24 09:04:56 -040045 const UniformInfo& uniform(int idx) const override {
46 return fUniforms.item(idx);
47 }
Ethan Nicholas58430122020-04-14 09:54:02 -040048
Stephen White4da34bf2019-07-30 10:37:47 -040049private:
Greg Danield59a91d2020-04-23 13:22:47 -040050 explicit GrSPIRVUniformHandler(GrGLSLProgramBuilder* program);
Stephen White4da34bf2019-07-30 10:37:47 -040051
Chris Dalton1b1b0d52020-03-03 12:00:59 -070052 SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&,
Stephen White4da34bf2019-07-30 10:37:47 -040053 const char* name, const GrShaderCaps*) override;
54 const char* samplerVariable(SamplerHandle handle) const override;
55 GrSwizzle samplerSwizzle(SamplerHandle handle) const override;
Jim Van Verth14a9b082021-09-20 14:09:52 +000056 void appendUniformDecls(GrShaderFlags visibility, SkString*) const override;
Ethan Nicholas16464c32020-04-06 13:53:05 -040057 UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner,
58 uint32_t visibility,
Stephen White4da34bf2019-07-30 10:37:47 -040059 GrSLType type,
60 const char* name,
61 bool mangleName,
62 int arrayCount,
63 const char** outName) override;
64
Ethan Nicholas16464c32020-04-06 13:53:05 -040065 UniformInfoArray fUniforms;
66 UniformInfoArray fSamplers;
67 UniformInfoArray fTextures;
68 SkTArray<GrSwizzle> fSamplerSwizzles;
69 SkTArray<SkString> fSamplerReferences;
Stephen White170d9902019-08-15 16:48:24 -040070
Stephen Whitedd78efd2019-10-23 15:00:20 -040071 uint32_t fCurrentUBOOffset = 0;
Brian Salomond8d85b92021-07-07 09:41:17 -040072 uint32_t fRTFlipOffset = 0;
Stephen White4da34bf2019-07-30 10:37:47 -040073
Greg Daniel5fc5c812020-04-23 10:30:23 -040074 friend class GrD3DPipelineStateBuilder;
Stephen White4da34bf2019-07-30 10:37:47 -040075 friend class GrDawnProgramBuilder;
Greg Daniel5fc5c812020-04-23 10:30:23 -040076
John Stiles7571f9e2020-09-02 22:42:33 -040077 using INHERITED = GrGLSLUniformHandler;
Stephen White4da34bf2019-07-30 10:37:47 -040078};
79
80#endif