1/*
2 * Copyright 2020 Google LLC
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 GrD3DPipelineStateBuilder_DEFINED
9#define GrD3DPipelineStateBuilder_DEFINED
10
11#include "src/gpu/GrPipeline.h"
12#include "src/gpu/GrSPIRVUniformHandler.h"
13#include "src/gpu/GrSPIRVVaryingHandler.h"
14#include "src/gpu/d3d/GrD3DPipelineState.h"
15#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
16#include "src/sksl/ir/SkSLProgram.h"
17
18class GrProgramDesc;
19class GrD3DGpu;
20class GrVkRenderPass;
21
22class GrD3DPipelineStateBuilder : public GrGLSLProgramBuilder {
23public:
24    /** Generates a pipeline state.
25     *
26     * The returned GrD3DPipelineState implements the supplied GrProgramInfo.
27     *
28     * @return the created pipeline if generation was successful; nullptr otherwise
29     */
30    static std::unique_ptr<GrD3DPipelineState> MakePipelineState(GrD3DGpu*,
31                                                                 GrD3DRenderTarget*,
32                                                                 const GrProgramDesc&,
33                                                                 const GrProgramInfo&);
34
35    static sk_sp<GrD3DPipeline> MakeComputePipeline(GrD3DGpu*, GrD3DRootSignature*,
36                                                    const char* shader);
37
38    const GrCaps* caps() const override;
39
40    GrD3DGpu* gpu() const { return fGpu; }
41
42    SkSL::Compiler* shaderCompiler() const override;
43
44    void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
45    void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
46
47private:
48    GrD3DPipelineStateBuilder(GrD3DGpu*, GrD3DRenderTarget*, const GrProgramDesc&,
49                              const GrProgramInfo&);
50
51    std::unique_ptr<GrD3DPipelineState> finalize();
52
53    bool loadHLSLFromCache(SkReadBuffer* reader, gr_cp<ID3DBlob> shaders[]);
54
55    gr_cp<ID3DBlob> compileD3DProgram(SkSL::ProgramKind kind,
56                                      const SkSL::String& sksl,
57                                      const SkSL::Program::Settings& settings,
58                                      SkSL::Program::Inputs* outInputs,
59                                      SkSL::String* outHLSL);
60
61    GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
62    const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
63    GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
64
65    GrD3DGpu* fGpu;
66    GrSPIRVVaryingHandler fVaryingHandler;
67    GrSPIRVUniformHandler fUniformHandler;
68    GrD3DRenderTarget* fRenderTarget;
69
70    using INHERITED = GrGLSLProgramBuilder;
71};
72
73#endif
74