blob: 23940566b028a96b46473bea425a393f36d21061 [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
8#ifndef GrDawnUniformHandler_DEFINED
9#define GrDawnUniformHandler_DEFINED
10
Michael Ludwig45191342020-03-24 12:29:39 -040011#include "src/gpu/GrTAllocator.h"
Stephen White4da34bf2019-07-30 10:37:47 -040012#include "src/gpu/glsl/GrGLSLUniformHandler.h"
13
14class GrDawnGpu;
15
16class GrDawnUniformHandler : public GrGLSLUniformHandler {
17public:
18 static const int kUniformsPerBlock = 8;
19
20 const GrShaderVar& getUniformVariable(UniformHandle u) const override;
21 const char* getUniformCStr(UniformHandle u) const override;
22
Ethan Nicholas16464c32020-04-06 13:53:05 -040023 struct DawnUniformInfo : public UniformInfo {
24 int fUBOOffset;
Stephen White4da34bf2019-07-30 10:37:47 -040025 };
Ethan Nicholas16464c32020-04-06 13:53:05 -040026 typedef GrTAllocator<DawnUniformInfo> UniformInfoArray;
Stephen White4da34bf2019-07-30 10:37:47 -040027 enum {
Stephen Whitedd78efd2019-10-23 15:00:20 -040028 kUniformBinding = 0,
Stephen White4da34bf2019-07-30 10:37:47 -040029 };
Stephen White40c47e12019-11-01 13:13:03 -040030 uint32_t getRTHeightOffset() const;
Stephen White4da34bf2019-07-30 10:37:47 -040031
Ethan Nicholas58430122020-04-14 09:54:02 -040032 int numUniforms() const override {
33 return fUniforms.count();
34 }
35
36 UniformInfo& uniform(int idx) override {
37 return fUniforms.item(idx);
38 }
39
Stephen White4da34bf2019-07-30 10:37:47 -040040private:
41 explicit GrDawnUniformHandler(GrGLSLProgramBuilder* program);
42
Chris Dalton1b1b0d52020-03-03 12:00:59 -070043 SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&,
Stephen White4da34bf2019-07-30 10:37:47 -040044 const char* name, const GrShaderCaps*) override;
45 const char* samplerVariable(SamplerHandle handle) const override;
46 GrSwizzle samplerSwizzle(SamplerHandle handle) const override;
47 void appendUniformDecls(GrShaderFlags visibility, SkString*) const override;
Ethan Nicholas16464c32020-04-06 13:53:05 -040048 UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner,
49 uint32_t visibility,
Stephen White4da34bf2019-07-30 10:37:47 -040050 GrSLType type,
51 const char* name,
52 bool mangleName,
53 int arrayCount,
54 const char** outName) override;
55
Ethan Nicholas16464c32020-04-06 13:53:05 -040056 UniformInfoArray fUniforms;
57 UniformInfoArray fSamplers;
58 UniformInfoArray fTextures;
59 SkTArray<GrSwizzle> fSamplerSwizzles;
60 SkTArray<SkString> fSamplerReferences;
Stephen White170d9902019-08-15 16:48:24 -040061
Stephen Whitedd78efd2019-10-23 15:00:20 -040062 uint32_t fCurrentUBOOffset = 0;
Stephen White40c47e12019-11-01 13:13:03 -040063 uint32_t fRTHeightOffset = 0;
Stephen White4da34bf2019-07-30 10:37:47 -040064
65 friend class GrDawnProgramBuilder;
66 typedef GrGLSLUniformHandler INHERITED;
67};
68
69#endif