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 GrDawnProgramBuilder_DEFINED 9 #define GrDawnProgramBuilder_DEFINED 10 11 #include "src/gpu/ganesh/GrSPIRVUniformHandler.h" 12 #include "src/gpu/ganesh/GrSPIRVVaryingHandler.h" 13 #include "src/gpu/ganesh/dawn/GrDawnProgramDataManager.h" 14 #include "src/sksl/ir/SkSLProgram.h" 15 #include "webgpu/webgpu_cpp.h" 16 #include "src/gpu/ganesh/glsl/GrGLSLProgramBuilder.h" 17 18 #include <vector> 19 20 class GrPipeline; 21 22 namespace SkSL { class Compiler; } 23 24 struct GrDawnProgram : public SkRefCnt { 25 struct RenderTargetState { 26 SkISize fRenderTargetSize; 27 GrSurfaceOrigin fRenderTargetOrigin; 28 RenderTargetStateGrDawnProgram::RenderTargetState29 RenderTargetState() { this->invalidate(); } invalidateGrDawnProgram::RenderTargetState30 void invalidate() { 31 fRenderTargetSize.fWidth = -1; 32 fRenderTargetSize.fHeight = -1; 33 fRenderTargetOrigin = (GrSurfaceOrigin) -1; 34 } 35 }; 36 typedef GrGLSLBuiltinUniformHandles BuiltinUniformHandles; GrDawnProgramGrDawnProgram37 GrDawnProgram(const GrSPIRVUniformHandler::UniformInfoArray& uniforms, 38 uint32_t uniformBufferSize) 39 : fDataManager(uniforms, uniformBufferSize) { 40 } 41 std::unique_ptr<GrGeometryProcessor::ProgramImpl> fGPImpl; 42 std::unique_ptr<GrXferProcessor::ProgramImpl> fXPImpl; 43 std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fFPImpls; 44 std::vector<wgpu::BindGroupLayout> fBindGroupLayouts; 45 wgpu::RenderPipeline fRenderPipeline; 46 GrDawnProgramDataManager fDataManager; 47 RenderTargetState fRenderTargetState; 48 BuiltinUniformHandles fBuiltinUniformHandles; 49 50 void setRenderTargetState(const GrRenderTarget*, GrSurfaceOrigin); 51 wgpu::BindGroup setUniformData(GrDawnGpu*, const GrRenderTarget*, const GrProgramInfo&); 52 wgpu::BindGroup setTextures(GrDawnGpu*, 53 const GrGeometryProcessor&, 54 const GrPipeline&, 55 const GrSurfaceProxy* const geomProcTextures[]); 56 }; 57 58 class GrDawnProgramBuilder : public GrGLSLProgramBuilder { 59 public: 60 static sk_sp<GrDawnProgram> Build(GrDawnGpu*, 61 GrRenderTarget*, 62 const GrProgramInfo&, 63 wgpu::TextureFormat colorFormat, 64 bool hasDepthStencil, 65 wgpu::TextureFormat depthStencilFormat, 66 GrProgramDesc*); 67 const GrCaps* caps() const override; uniformHandler()68 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } uniformHandler()69 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } varyingHandler()70 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } 71 gpu()72 GrDawnGpu* gpu() const { return fGpu; } 73 74 SkSL::Compiler* shaderCompiler() const override; 75 76 private: 77 GrDawnProgramBuilder(GrDawnGpu*, 78 const GrProgramInfo&, 79 GrProgramDesc*); 80 wgpu::ShaderModule createShaderModule(const GrGLSLShaderBuilder&, SkSL::ProgramKind, 81 bool flipY, SkSL::Program::Inputs* inputs); 82 GrDawnGpu* fGpu; 83 GrSPIRVVaryingHandler fVaryingHandler; 84 GrSPIRVUniformHandler fUniformHandler; 85 86 using INHERITED = GrGLSLProgramBuilder; 87 }; 88 #endif 89