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