| 1 |
/* |
| 2 |
* Copyright 2018 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 GrMtlPipelineState_DEFINED |
| 9 |
#define GrMtlPipelineState_DEFINED |
| 10 |
|
| 11 |
#include "include/private/gpu/ganesh/GrTypesPriv.h" |
| 12 |
#include "src/gpu/ganesh/GrStencilSettings.h" |
| 13 |
#include "src/gpu/ganesh/glsl/GrGLSLProgramBuilder.h" |
| 14 |
#include "src/gpu/ganesh/mtl/GrMtlBuffer.h" |
| 15 |
#include "src/gpu/ganesh/mtl/GrMtlPipeline.h" |
| 16 |
#include "src/gpu/ganesh/mtl/GrMtlPipelineStateDataManager.h" |
| 17 |
|
| 18 |
#import <Metal/Metal.h> |
| 19 |
|
| 20 |
class GrMtlFramebuffer; |
| 21 |
class GrMtlGpu; |
| 22 |
class GrMtlPipelineStateDataManager; |
| 23 |
class GrMtlRenderCommandEncoder; |
| 24 |
class GrMtlRenderPipeline; |
| 25 |
class GrMtlSampler; |
| 26 |
class GrMtlTexture; |
| 27 |
class GrPipeline; |
| 28 |
|
| 29 |
/** |
| 30 |
* Wraps a MTLRenderPipelineState object and also contains more info about the pipeline as needed |
| 31 |
* by Ganesh |
| 32 |
*/ |
| 33 |
class GrMtlPipelineState { |
| 34 |
public: |
| 35 |
using UniformInfoArray = GrMtlPipelineStateDataManager::UniformInfoArray; |
| 36 |
using UniformHandle = GrGLSLProgramDataManager::UniformHandle; |
| 37 |
|
| 38 |
GrMtlPipelineState(GrMtlGpu*, |
| 39 |
sk_sp<GrMtlRenderPipeline> pipeline, |
| 40 |
MTLPixelFormat, |
| 41 |
const GrGLSLBuiltinUniformHandles& builtinUniformHandles, |
| 42 |
const UniformInfoArray& uniforms, |
| 43 |
uint32_t uniformBufferSize, |
| 44 |
uint32_t numSamplers, |
| 45 |
std::unique_ptr<GrGeometryProcessor::ProgramImpl>, |
| 46 |
std::unique_ptr<GrXferProcessor::ProgramImpl>, |
| 47 |
std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fpImpls); |
| 48 |
|
| 49 |
const sk_sp<GrMtlRenderPipeline>& pipeline() const { return fPipeline; } |
| 50 |
|
| 51 |
void setData(GrMtlFramebuffer*, const GrProgramInfo&); |
| 52 |
|
| 53 |
void setTextures(const GrGeometryProcessor&, |
| 54 |
const GrPipeline&, |
| 55 |
const GrSurfaceProxy* const geomProcTextures[]); |
| 56 |
void bindTextures(GrMtlRenderCommandEncoder* renderCmdEncoder); |
| 57 |
|
| 58 |
void setDrawState(GrMtlRenderCommandEncoder*, |
| 59 |
const skgpu::Swizzle& writeSwizzle, |
| 60 |
const GrXferProcessor&); |
| 61 |
|
| 62 |
static void SetDynamicScissorRectState(GrMtlRenderCommandEncoder* renderCmdEncoder, |
| 63 |
SkISize colorAttachmentDimensions, |
| 64 |
GrSurfaceOrigin rtOrigin, |
| 65 |
SkIRect scissorRect); |
| 66 |
|
| 67 |
bool doesntSampleAttachment(const MTLRenderPassAttachmentDescriptor*) const; |
| 68 |
|
| 69 |
private: |
| 70 |
/** |
| 71 |
* We use the RT's size and origin to adjust from Skia device space to Metal normalized device |
| 72 |
* space and to make device space positions have the correct origin for processors that require |
| 73 |
* them. |
| 74 |
*/ |
| 75 |
struct RenderTargetState { |
| 76 |
SkISize fRenderTargetSize; |
| 77 |
GrSurfaceOrigin fRenderTargetOrigin; |
| 78 |
|
| 79 |
RenderTargetState() { this->invalidate(); } |
| 80 |
void invalidate() { |
| 81 |
fRenderTargetSize.fWidth = -1; |
| 82 |
fRenderTargetSize.fHeight = -1; |
| 83 |
fRenderTargetOrigin = (GrSurfaceOrigin)-1; |
| 84 |
} |
| 85 |
}; |
| 86 |
|
| 87 |
void setRenderTargetState(SkISize colorAttachmentDimensions, GrSurfaceOrigin); |
| 88 |
|
| 89 |
void bindUniforms(GrMtlRenderCommandEncoder*); |
| 90 |
|
| 91 |
void setBlendConstants(GrMtlRenderCommandEncoder*, |
| 92 |
const skgpu::Swizzle&, |
| 93 |
const GrXferProcessor&); |
| 94 |
|
| 95 |
void setDepthStencilState(GrMtlRenderCommandEncoder* renderCmdEncoder); |
| 96 |
|
| 97 |
struct SamplerBindings { |
| 98 |
GrMtlSampler* fSampler; |
| 99 |
id<MTLTexture> fTexture; |
| 100 |
|
| 101 |
SamplerBindings(GrSamplerState state, GrTexture* texture, GrMtlGpu*); |
| 102 |
}; |
| 103 |
|
| 104 |
GrMtlGpu* fGpu; |
| 105 |
sk_sp<GrMtlRenderPipeline> fPipeline; |
| 106 |
MTLPixelFormat fPixelFormat; |
| 107 |
|
| 108 |
RenderTargetState fRenderTargetState; |
| 109 |
GrGLSLBuiltinUniformHandles fBuiltinUniformHandles; |
| 110 |
|
| 111 |
GrStencilSettings fStencil; |
| 112 |
|
| 113 |
int fNumSamplers; |
| 114 |
skia_private::TArray<SamplerBindings> fSamplerBindings; |
| 115 |
|
| 116 |
std::unique_ptr<GrGeometryProcessor::ProgramImpl> fGPImpl; |
| 117 |
std::unique_ptr<GrXferProcessor::ProgramImpl> fXPImpl; |
| 118 |
std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fFPImpls; |
| 119 |
|
| 120 |
GrMtlPipelineStateDataManager fDataManager; |
| 121 |
}; |
| 122 |
|
| 123 |
#endif |