21#if !__has_feature(objc_arc)
22#error This file must be compiled with Arc. Use -fobjc-arc flag
33 , fFramebuffer(
std::move(framebuffer)) {
34 this->setupRenderPass(colorInfo, stencilInfo);
47 fActiveRenderCmdEncoder =
nullptr;
51 const static MTLPrimitiveType mtlPrimitiveType[] {
52 MTLPrimitiveTypeTriangle,
53 MTLPrimitiveTypeTriangleStrip,
54 MTLPrimitiveTypePoint,
56 MTLPrimitiveTypeLineStrip
65 return mtlPrimitiveType[
static_cast<int>(primitiveType)];
68bool GrMtlOpsRenderPass::onBindPipeline(
const GrProgramInfo& programInfo,
69 const SkRect& drawBounds) {
78 programDesc, programInfo);
79 if (!fActivePipelineState) {
83 fActivePipelineState->
setData(fFramebuffer.
get(), programInfo);
86 if (!fActiveRenderCmdEncoder) {
87 this->setupRenderCommandEncoder(fActivePipelineState);
88 if (!fActiveRenderCmdEncoder) {
97#ifdef SK_ENABLE_MTL_DEBUG_INFO
98 if (!fDebugGroupActive) {
100 fDebugGroupActive =
true;
103 fActivePipelineState->
setDrawState(fActiveRenderCmdEncoder,
122 fBounds.
join(drawBounds);
126void GrMtlOpsRenderPass::onSetScissorRect(
const SkIRect& scissor) {
139#ifdef SK_ENABLE_MTL_DEBUG_INFO
140 if (!fDebugGroupActive) {
142 fDebugGroupActive =
true;
145 fActivePipelineState->
setTextures(geomProc, pipeline, geomProcTextures);
146 fActivePipelineState->
bindTextures(fActiveRenderCmdEncoder);
150void GrMtlOpsRenderPass::onClear(
const GrScissorState& scissor, std::array<float, 4>
color) {
156 auto colorAttachment = fRenderPassDesc.colorAttachments[0];
158 colorAttachment.loadAction = MTLLoadActionClear;
159 if (!this->setupResolve()) {
160 this->setupRenderCommandEncoder(
nullptr);
164void GrMtlOpsRenderPass::onClearStencilClip(
const GrScissorState& scissor,
bool insideStencilMask) {
176 auto stencilAttachment = fRenderPassDesc.stencilAttachment;
177 if (insideStencilMask) {
178 stencilAttachment.clearStencil = (1 << (stencilBitCount - 1));
180 stencilAttachment.clearStencil = 0;
183 stencilAttachment.loadAction = MTLLoadActionClear;
184 if (!this->setupResolve()) {
185 this->setupRenderCommandEncoder(
nullptr);
195 if (!this->setupResolve()) {
198 this->setupRenderCommandEncoder(
nullptr);
206#ifdef SK_ENABLE_MTL_DEBUG_INFO
207 encoder->pushDebugGroup(
@"initRenderState");
209 encoder->setFrontFacingWinding(MTLWindingCounterClockwise);
213 MTLViewport viewport = { 0.0, 0.0,
214 (double) colorAttachmentDimensions.
width(),
215 (double) colorAttachmentDimensions.
height(),
217 encoder->setViewport(viewport);
218#ifdef SK_ENABLE_MTL_DEBUG_INFO
223void GrMtlOpsRenderPass::setupRenderPass(
226 const static MTLLoadAction mtlLoadAction[] {
229 MTLLoadActionDontCare
237 const static MTLStoreAction mtlStoreAction[] {
239 MTLStoreActionDontCare
246 fRenderPassDesc = [MTLRenderPassDescriptor
new];
247 auto colorAttachment = fRenderPassDesc.colorAttachments[0];
249 colorAttachment.texture =
color->mtlTexture();
250 const std::array<float, 4>& clearColor = colorInfo.
fClearColor;
251 colorAttachment.clearColor =
252 MTLClearColorMake(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
253 colorAttachment.loadAction = mtlLoadAction[
static_cast<int>(colorInfo.
fLoadOp)];
254 colorAttachment.storeAction = mtlStoreAction[
static_cast<int>(colorInfo.
fStoreOp)];
257 auto mtlStencil = fRenderPassDesc.stencilAttachment;
259 mtlStencil.texture = stencil->mtlTexture();
261 mtlStencil.clearStencil = 0;
262 mtlStencil.loadAction = mtlLoadAction[
static_cast<int>(stencilInfo.
fLoadOp)];
263 mtlStencil.storeAction = mtlStoreAction[
static_cast<int>(stencilInfo.
fStoreOp)];
265 if (!this->setupResolve()) {
269 color->dimensions().height());
270 this->setupRenderCommandEncoder(
nullptr);
281bool GrMtlOpsRenderPass::setupResolve() {
282 fActiveRenderCmdEncoder =
nullptr;
285 auto colorAttachment = fRenderPassDesc.colorAttachments[0];
286 colorAttachment.resolveTexture = resolve->mtlTexture();
289 colorAttachment.storeAction = MTLStoreActionMultisampleResolve;
290 if (colorAttachment.loadAction == MTLLoadActionLoad) {
292 auto dimensions =
color->dimensions();
296 fActiveRenderCmdEncoder =
298 fRenderPassDesc.stencilAttachment);
302 return (fActiveRenderCmdEncoder !=
nullptr);
305void GrMtlOpsRenderPass::setupRenderCommandEncoder(
GrMtlPipelineState* pipelineState) {
306 fActiveRenderCmdEncoder =
310 auto colorAttachment = fRenderPassDesc.colorAttachments[0];
311 colorAttachment.loadAction = MTLLoadActionLoad;
312 auto stencilAttachment = fRenderPassDesc.stencilAttachment;
313 stencilAttachment.loadAction = MTLLoadActionLoad;
320#ifdef SK_ENABLE_MTL_DEBUG_INFO
321 if (!fDebugGroupActive) {
323 fDebugGroupActive =
true;
327 int inputBufferIndex = 0;
335 if (instanceBuffer) {
338 this->setVertexBuffer(fActiveRenderCmdEncoder, instanceBuffer.
get(), 0, inputBufferIndex++);
350void GrMtlOpsRenderPass::onDraw(
int vertexCount,
int baseVertex) {
352 SkASSERT(nil != fActiveRenderCmdEncoder);
353#ifdef SK_ENABLE_MTL_DEBUG_INFO
354 if (!fDebugGroupActive) {
356 fDebugGroupActive =
true;
361 fActiveRenderCmdEncoder->
drawPrimitives(fActivePrimitiveType, baseVertex, vertexCount);
363#ifdef SK_ENABLE_MTL_DEBUG_INFO
366 fDebugGroupActive =
false;
370void GrMtlOpsRenderPass::onDrawIndexed(
int indexCount,
int baseIndex, uint16_t minIndexValue,
371 uint16_t maxIndexValue,
int baseVertex) {
373 SkASSERT(nil != fActiveRenderCmdEncoder);
375#ifdef SK_ENABLE_MTL_DEBUG_INFO
376 if (!fDebugGroupActive) {
378 fDebugGroupActive =
true;
382 fCurrentVertexStride * baseVertex, 0);
385 size_t indexOffset =
sizeof(uint16_t) * baseIndex;
386 id<MTLBuffer> indexBuffer = mtlIndexBuffer->mtlBuffer();
388 MTLIndexTypeUInt16, indexBuffer, indexOffset);
390#ifdef SK_ENABLE_MTL_DEBUG_INFO
393 fDebugGroupActive =
false;
397void GrMtlOpsRenderPass::onDrawInstanced(
int instanceCount,
int baseInstance,
int vertexCount,
400 SkASSERT(nil != fActiveRenderCmdEncoder);
401#ifdef SK_ENABLE_MTL_DEBUG_INFO
402 if (!fDebugGroupActive) {
404 fDebugGroupActive =
true;
409 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
410 fActiveRenderCmdEncoder->
drawPrimitives(fActivePrimitiveType, baseVertex, vertexCount,
411 instanceCount, baseInstance);
416#ifdef SK_ENABLE_MTL_DEBUG_INFO
419 fDebugGroupActive =
false;
423void GrMtlOpsRenderPass::onDrawIndexedInstanced(
424 int indexCount,
int baseIndex,
int instanceCount,
int baseInstance,
int baseVertex) {
426 SkASSERT(nil != fActiveRenderCmdEncoder);
428#ifdef SK_ENABLE_MTL_DEBUG_INFO
429 if (!fDebugGroupActive) {
431 fDebugGroupActive =
true;
437 size_t indexOffset =
sizeof(uint16_t) * baseIndex;
438 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
441 mtlIndexBuffer->mtlBuffer(), indexOffset,
442 instanceCount, baseVertex, baseInstance);
447#ifdef SK_ENABLE_MTL_DEBUG_INFO
450 fDebugGroupActive =
false;
454void GrMtlOpsRenderPass::onDrawIndirect(
const GrBuffer* drawIndirectBuffer,
459 SkASSERT(nil != fActiveRenderCmdEncoder);
460#ifdef SK_ENABLE_MTL_DEBUG_INFO
461 if (!fDebugGroupActive) {
463 fDebugGroupActive =
true;
468 auto mtlIndirectBuffer =
static_cast<const GrMtlBuffer*
>(drawIndirectBuffer);
470 while (drawCount >= 1) {
471 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
473 mtlIndirectBuffer->mtlBuffer(), bufferOffset);
478 bufferOffset += stride;
481#ifdef SK_ENABLE_MTL_DEBUG_INFO
484 fDebugGroupActive =
false;
488void GrMtlOpsRenderPass::onDrawIndexedIndirect(
const GrBuffer* drawIndirectBuffer,
493 SkASSERT(nil != fActiveRenderCmdEncoder);
495#ifdef SK_ENABLE_MTL_DEBUG_INFO
496 if (!fDebugGroupActive) {
498 fDebugGroupActive =
true;
504 auto mtlIndirectBuffer =
static_cast<const GrMtlBuffer*
>(drawIndirectBuffer);
505 size_t indexOffset = 0;
508 while (drawCount >= 1) {
509 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
512 mtlIndexBuffer->mtlBuffer(),
514 mtlIndirectBuffer->mtlBuffer(),
520 bufferOffset += stride;
523#ifdef SK_ENABLE_MTL_DEBUG_INFO
526 fDebugGroupActive =
false;
533 size_t inputBufferIndex) {
539 int index = inputBufferIndex + kFirstBufferBindingIdx;
542 id<MTLBuffer> mtlVertexBuffer = mtlBuffer->
mtlBuffer();
544 size_t offset = vertexOffset;
int GrBackendFormatStencilBits(const GrBackendFormat &format)
std::function< void(GrDeferredTextureUploadWritePixelsFn &)> GrDeferredTextureUploadFn
static MTLPrimitiveType gr_to_mtl_primitive(GrPrimitiveType primitiveType)
virtual bool isCpuBuffer() const =0
bool nativeDrawIndirectSupport() const
size_t vertexStride() const
const GrCaps * caps() const
id< MTLBuffer > mtlBuffer() const
GrProgramDesc makeDesc(GrRenderTarget *, const GrProgramInfo &, ProgramDescOverrideFlags) const override
GrMtlRenderCommandEncoder * getRenderCommandEncoder(MTLRenderPassDescriptor *, const GrMtlPipelineState *, GrMtlOpsRenderPass *opsRenderPass)
void addGrBuffer(sk_sp< const GrBuffer > buffer)
void addGrSurface(sk_sp< const GrSurface > surface)
GrMtlAttachment * stencilAttachment()
GrMtlAttachment * colorAttachment()
GrMtlAttachment * resolveAttachment()
GrMtlRenderCommandEncoder * loadMSAAFromResolve(GrAttachment *dst, GrMtlAttachment *src, const SkIRect &srcRect, MTLRenderPassStencilAttachmentDescriptor *)
GrMtlCommandBuffer * commandBuffer()
const GrMtlCaps & mtlCaps() const
GrMtlResourceProvider & resourceProvider()
void submitIndirectCommandBuffer(GrSurface *surface, GrSurfaceOrigin origin, const SkIRect *bounds)
~GrMtlOpsRenderPass() override
GrMtlOpsRenderPass(GrMtlGpu *gpu, GrRenderTarget *rt, sk_sp< GrMtlFramebuffer >, GrSurfaceOrigin origin, const GrOpsRenderPass::LoadAndStoreInfo &colorInfo, const GrOpsRenderPass::StencilLoadAndStoreInfo &stencilInfo)
void inlineUpload(GrOpFlushState *state, GrDeferredTextureUploadFn &upload) override
void initRenderState(GrMtlRenderCommandEncoder *)
void setDrawState(GrMtlRenderCommandEncoder *, const skgpu::Swizzle &writeSwizzle, const GrXferProcessor &)
static void SetDynamicScissorRectState(GrMtlRenderCommandEncoder *renderCmdEncoder, SkISize colorAttachmentDimensions, GrSurfaceOrigin rtOrigin, SkIRect scissorRect)
void bindTextures(GrMtlRenderCommandEncoder *renderCmdEncoder)
void setTextures(const GrGeometryProcessor &, const GrPipeline &, const GrSurfaceProxy *const geomProcTextures[])
void setData(GrMtlFramebuffer *, const GrProgramInfo &)
const sk_sp< GrMtlRenderPipeline > & pipeline() const
void drawPrimitives(MTLPrimitiveType primitiveType, NSUInteger vertexStart, NSUInteger vertexCount)
void pushDebugGroup(NSString *string)
void drawIndexedPrimitives(MTLPrimitiveType primitiveType, NSUInteger indexCount, MTLIndexType indexType, id< MTLBuffer > indexBuffer, NSUInteger indexBufferOffset)
void setTriangleFillMode(MTLTriangleFillMode fillMode)
void setRenderPipelineState(id< MTLRenderPipelineState > pso)
id< MTLRenderPipelineState > mtlPipelineState() const
GrMtlPipelineState * findOrCreateCompatiblePipelineState(const GrProgramDesc &, const GrProgramInfo &, GrThreadSafePipelineBuilder::Stats::ProgramCacheResult *stat=nullptr)
sk_sp< const GrBuffer > fActiveIndexBuffer
sk_sp< const GrBuffer > fActiveInstanceBuffer
sk_sp< const GrBuffer > fActiveVertexBuffer
GrRenderTarget * fRenderTarget
const skgpu::Swizzle & writeSwizzle() const
bool isScissorTestEnabled() const
const GrXferProcessor & getXferProcessor() const
GrPrimitiveType primitiveType() const
const GrPipeline & pipeline() const
const GrGeometryProcessor & geomProc() const
virtual GrBackendFormat backendFormat() const =0
SkISize dimensions() const
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
static SkIRect MakeIRectRelativeTo(GrSurfaceOrigin origin, int rtHeight, SkIRect devRect)
std::array< float, 4 > fClearColor
static constexpr SkIRect MakeSize(const SkISize &size)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
constexpr int32_t width() const
constexpr int32_t height() const
void roundOut(SkIRect *dst) const
void join(const SkRect &r)
static constexpr SkRect MakeWH(float w, float h)