xref: /aosp_15_r20/external/skia/src/gpu/ganesh/d3d/GrD3DPipelineState.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 GrD3DPipelineState_DEFINED
9 #define GrD3DPipelineState_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/gpu/ganesh/GrTypes.h"
13 #include "include/gpu/ganesh/d3d/GrD3DTypes.h"
14 #include "src/gpu/ganesh/GrBuffer.h"
15 #include "src/gpu/ganesh/GrManagedResource.h"
16 #include "src/gpu/ganesh/d3d/GrD3DPipelineStateDataManager.h"
17 #include "src/gpu/ganesh/glsl/GrGLSLProgramBuilder.h"
18 
19 #include <vector>
20 
21 class GrD3DDirectCommandList;
22 class GrD3DGpu;
23 class GrD3DPipeline;
24 class GrD3DRootSignature;
25 class GrProgramInfo;
26 
27 class GrD3DPipelineState {
28 public:
29     using UniformInfoArray = GrD3DPipelineStateDataManager::UniformInfoArray;
30 
31     GrD3DPipelineState(sk_sp<GrD3DPipeline> pipeline,
32                        sk_sp<GrD3DRootSignature> rootSignature,
33                        const GrGLSLBuiltinUniformHandles& builtinUniformHandles,
34                        const UniformInfoArray& uniforms,
35                        uint32_t uniformSize,
36                        uint32_t numSamplers,
37                        std::unique_ptr<GrGeometryProcessor::ProgramImpl> gpImpl,
38                        std::unique_ptr<GrXferProcessor::ProgramImpl> xpImpl,
39                        std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fpImpls,
40                        size_t vertexStride,
41                        size_t instanceStride);
42 
pipeline()43     const sk_sp<GrD3DPipeline>& pipeline() const { return fPipeline; }
rootSignature()44     const sk_sp<GrD3DRootSignature>& rootSignature() const { return fRootSignature; }
45 
46     void setAndBindConstants(GrD3DGpu*, const GrRenderTarget*, const GrProgramInfo&);
47 
48     void setAndBindTextures(GrD3DGpu*,
49                             const GrGeometryProcessor&,
50                             const GrSurfaceProxy* const geomProcTextures[],
51                             const GrPipeline&);
52 
53     void bindBuffers(GrD3DGpu*, sk_sp<const GrBuffer> indexBuffer,
54                      sk_sp<const GrBuffer> instanceBuffer, sk_sp<const GrBuffer> vertexBuffer,
55                      GrD3DDirectCommandList* commandList);
56 
57     // We can only cache non dirty uniform values until we submit a command list. After that, the
58     // next frame will get a completely different uniform buffer and/or offset into the buffer. Thus
59     // we need a way to mark them all as dirty during submit.
markUniformsDirty()60     void markUniformsDirty() { fDataManager.markDirty(); }
61 
62 private:
63     /**
64      * We use the RT's size and origin to adjust from Skia device space to d3d normalized device
65      * space and to make device space positions have the correct origin for processors that require
66      * them.
67      */
68     struct RenderTargetState {
69         SkISize         fRenderTargetSize;
70         GrSurfaceOrigin fRenderTargetOrigin;
71 
RenderTargetStateRenderTargetState72         RenderTargetState() { this->invalidate(); }
invalidateRenderTargetState73         void invalidate() {
74             fRenderTargetSize.fWidth = -1;
75             fRenderTargetSize.fHeight = -1;
76             fRenderTargetOrigin = (GrSurfaceOrigin)-1;
77         }
78     };
79 
80     // Helper for setData() that sets the view matrix and loads the render target height uniform
81     void setRenderTargetState(const GrRenderTarget*, GrSurfaceOrigin);
82 
83     sk_sp<GrD3DPipeline> fPipeline;
84     sk_sp<GrD3DRootSignature> fRootSignature;
85 
86     // Tracks the current render target uniforms stored in the vertex buffer.
87     RenderTargetState fRenderTargetState;
88     GrGLSLBuiltinUniformHandles fBuiltinUniformHandles;
89 
90     // Processors in the GrD3DPipelineState
91     std::unique_ptr<GrGeometryProcessor::ProgramImpl>              fGPImpl;
92     std::unique_ptr<GrXferProcessor::ProgramImpl>                  fXPImpl;
93     std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fFPImpls;
94 
95     GrD3DPipelineStateDataManager fDataManager;
96 
97     unsigned int fNumSamplers;
98     size_t fVertexStride;
99     size_t fInstanceStride;
100 };
101 
102 #endif
103