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 | |
| 8 | #ifndef GrDawnUniformHandler_DEFINED |
| 9 | #define GrDawnUniformHandler_DEFINED |
| 10 | |
Michael Ludwig | 4519134 | 2020-03-24 12:29:39 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrTAllocator.h" |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 12 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
| 13 | |
| 14 | class GrDawnGpu; |
| 15 | |
| 16 | class GrDawnUniformHandler : public GrGLSLUniformHandler { |
| 17 | public: |
| 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 Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 23 | struct DawnUniformInfo : public UniformInfo { |
| 24 | int fUBOOffset; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 25 | }; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 26 | typedef GrTAllocator<DawnUniformInfo> UniformInfoArray; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 27 | enum { |
Stephen White | dd78efd | 2019-10-23 15:00:20 -0400 | [diff] [blame] | 28 | kUniformBinding = 0, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 29 | }; |
Stephen White | 40c47e1 | 2019-11-01 13:13:03 -0400 | [diff] [blame] | 30 | uint32_t getRTHeightOffset() const; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 31 | |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame^] | 32 | int numUniforms() const override { |
| 33 | return fUniforms.count(); |
| 34 | } |
| 35 | |
| 36 | UniformInfo& uniform(int idx) override { |
| 37 | return fUniforms.item(idx); |
| 38 | } |
| 39 | |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 40 | private: |
| 41 | explicit GrDawnUniformHandler(GrGLSLProgramBuilder* program); |
| 42 | |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 43 | SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 44 | 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 Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 48 | UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner, |
| 49 | uint32_t visibility, |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 50 | GrSLType type, |
| 51 | const char* name, |
| 52 | bool mangleName, |
| 53 | int arrayCount, |
| 54 | const char** outName) override; |
| 55 | |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 56 | UniformInfoArray fUniforms; |
| 57 | UniformInfoArray fSamplers; |
| 58 | UniformInfoArray fTextures; |
| 59 | SkTArray<GrSwizzle> fSamplerSwizzles; |
| 60 | SkTArray<SkString> fSamplerReferences; |
Stephen White | 170d990 | 2019-08-15 16:48:24 -0400 | [diff] [blame] | 61 | |
Stephen White | dd78efd | 2019-10-23 15:00:20 -0400 | [diff] [blame] | 62 | uint32_t fCurrentUBOOffset = 0; |
Stephen White | 40c47e1 | 2019-11-01 13:13:03 -0400 | [diff] [blame] | 63 | uint32_t fRTHeightOffset = 0; |
Stephen White | 4da34bf | 2019-07-30 10:37:47 -0400 | [diff] [blame] | 64 | |
| 65 | friend class GrDawnProgramBuilder; |
| 66 | typedef GrGLSLUniformHandler INHERITED; |
| 67 | }; |
| 68 | |
| 69 | #endif |