8#ifndef skgpu_graphite_MtlRenderCommandEncoder_DEFINED
9#define skgpu_graphite_MtlRenderCommandEncoder_DEFINED
15#import <Metal/Metal.h>
25 id<MTLCommandBuffer> commandBuffer,
26 MTLRenderPassDescriptor* descriptor) {
31 sk_cfp<id<MTLRenderCommandEncoder>>
encoder =
32 sk_ret_cfp([commandBuffer renderCommandEncoderWithDescriptor:descriptor]);
38 const char*
getResourceType()
const override {
return "Metal Render Command Encoder"; }
55 if (fCurrentRenderPipelineState != pso) {
57 fCurrentRenderPipelineState = pso;
62 if (fCurrentTriangleFillMode != fillMode) {
64 fCurrentTriangleFillMode = fillMode;
78 SkASSERT(index < kMaxExpectedBuffers);
79 if (@available(macOS 10.11, iOS 8.3, tvOS 9.0, *)) {
80 if (fCurrentVertexBuffer[index] ==
buffer) {
85 if (fCurrentVertexBuffer[index] !=
buffer || fCurrentVertexOffset[index] !=
offset) {
89 fCurrentVertexBuffer[index] =
buffer;
90 fCurrentVertexOffset[index] =
offset;
95 SkASSERT(index < kMaxExpectedBuffers);
96 if (fCurrentVertexOffset[index] !=
offset) {
99 fCurrentVertexOffset[index] =
offset;
105 SkASSERT(index < kMaxExpectedBuffers);
106 if (@available(macOS 10.11, iOS 8.3, tvOS 9.0, *)) {
107 if (fCurrentFragmentBuffer[index] ==
buffer) {
112 if (fCurrentFragmentBuffer[index] !=
buffer || fCurrentFragmentOffset[index] !=
offset) {
116 fCurrentFragmentBuffer[index] =
buffer;
117 fCurrentFragmentOffset[index] =
offset;
122 SkASSERT(index < kMaxExpectedBuffers);
123 if (fCurrentFragmentOffset[index] !=
offset) {
126 fCurrentFragmentOffset[index] =
offset;
144 SkASSERT(index < kMaxExpectedTextures);
145 if (fCurrentTexture[index] !=
texture) {
148 fCurrentTexture[index] =
texture;
152 SkASSERT(index < kMaxExpectedTextures);
153 if (fCurrentSampler[index] != sampler) {
156 fCurrentSampler[index] = sampler;
161 [(*fCommandEncoder) setBlendColorRed: blendConst[0]
164 alpha: blendConst[3]];
168 if (referenceValue != fCurrentStencilReferenceValue) {
170 fCurrentStencilReferenceValue = referenceValue;
174 if (depthStencilState != fCurrentDepthStencilState) {
176 fCurrentDepthStencilState = depthStencilState;
181 if (fCurrentScissorRect.x != scissorRect.x ||
182 fCurrentScissorRect.y != scissorRect.y ||
183 fCurrentScissorRect.width != scissorRect.width ||
184 fCurrentScissorRect.height != scissorRect.height) {
186 fCurrentScissorRect = scissorRect;
191 NSUInteger vertexCount) {
193 vertexStart:vertexStart
194 vertexCount:vertexCount];
197 NSUInteger vertexCount, NSUInteger instanceCount,
198 NSUInteger baseInstance)
201 vertexStart:vertexStart
202 vertexCount:vertexCount
203 instanceCount:instanceCount
204 baseInstance:baseInstance];
206 void drawPrimitives(MTLPrimitiveType primitiveType, id<MTLBuffer> indirectBuffer,
207 NSUInteger indirectBufferOffset)
210 indirectBuffer:indirectBuffer
211 indirectBufferOffset:indirectBufferOffset];
215 MTLIndexType indexType, id<MTLBuffer> indexBuffer,
216 NSUInteger indexBufferOffset) {
218 indexCount:indexCount
220 indexBuffer:indexBuffer
221 indexBufferOffset:indexBufferOffset];
224 MTLIndexType indexType, id<MTLBuffer> indexBuffer,
225 NSUInteger indexBufferOffset,
226 NSUInteger instanceCount,
227 NSInteger baseVertex,
228 NSUInteger baseInstance)
231 indexCount:indexCount
233 indexBuffer:indexBuffer
234 indexBufferOffset:indexBufferOffset
235 instanceCount:instanceCount
236 baseVertex:baseVertex
237 baseInstance:baseInstance];
240 MTLIndexType indexType, id<MTLBuffer> indexBuffer,
241 NSUInteger indexBufferOffset, id<MTLBuffer> indirectBuffer,
242 NSUInteger indirectBufferOffset)
246 indexBuffer:indexBuffer
247 indexBufferOffset:indexBufferOffset
248 indirectBuffer:indirectBuffer
249 indirectBufferOffset:indirectBufferOffset];
257 inline static constexpr int kMaxExpectedBuffers = 6;
258 inline static constexpr int kMaxExpectedTextures = 16;
261 sk_cfp<id<MTLRenderCommandEncoder>>
encoder)
267 for (
int i = 0;
i < kMaxExpectedBuffers;
i++) {
268 fCurrentVertexBuffer[
i] = nil;
269 fCurrentFragmentBuffer[
i] = nil;
276 for (
int i = 0;
i < kMaxExpectedTextures;
i++) {
277 fCurrentTexture[
i] = nil;
278 fCurrentSampler[
i] = nil;
282 void freeGpuData()
override {
283 fCommandEncoder.reset();
286 sk_cfp<id<MTLRenderCommandEncoder>> fCommandEncoder;
288 id<MTLRenderPipelineState> fCurrentRenderPipelineState = nil;
289 id<MTLDepthStencilState> fCurrentDepthStencilState = nil;
290 uint32_t fCurrentStencilReferenceValue = 0;
292 id<MTLBuffer> fCurrentVertexBuffer[kMaxExpectedBuffers];
293 NSUInteger fCurrentVertexOffset[kMaxExpectedBuffers];
294 id<MTLBuffer> fCurrentFragmentBuffer[kMaxExpectedBuffers];
295 NSUInteger fCurrentFragmentOffset[kMaxExpectedBuffers];
297 id<MTLTexture> fCurrentTexture[kMaxExpectedTextures];
298 id<MTLSamplerState> fCurrentSampler[kMaxExpectedTextures];
300 MTLScissorRect fCurrentScissorRect = { 0, 0, 0, 0 };
301 MTLTriangleFillMode fCurrentTriangleFillMode = (MTLTriangleFillMode)-1;
#define SK_API_AVAILABLE(...)
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
void setScissorRect(const MTLScissorRect &scissorRect)
void drawIndexedPrimitives(MTLPrimitiveType primitiveType, MTLIndexType indexType, id< MTLBuffer > indexBuffer, NSUInteger indexBufferOffset, id< MTLBuffer > indirectBuffer, NSUInteger indirectBufferOffset) SK_API_AVAILABLE(macos(10.11)
void drawIndexedPrimitives(MTLPrimitiveType primitiveType, NSUInteger indexCount, MTLIndexType indexType, id< MTLBuffer > indexBuffer, NSUInteger indexBufferOffset)
void setVertexBuffer(id< MTLBuffer > buffer, NSUInteger offset, NSUInteger index)
void insertDebugSignpost(NSString *string)
void drawIndexedPrimitives(MTLPrimitiveType primitiveType, NSUInteger indexCount, MTLIndexType indexType, id< MTLBuffer > indexBuffer, NSUInteger indexBufferOffset, NSUInteger instanceCount, NSInteger baseVertex, NSUInteger baseInstance) SK_API_AVAILABLE(macos(10.11)
void setStencilReferenceValue(uint32_t referenceValue)
void setFragmentSamplerState(id< MTLSamplerState > sampler, NSUInteger index)
void pushDebugGroup(NSString *string)
void setTriangleFillMode(MTLTriangleFillMode fillMode)
static sk_sp< MtlRenderCommandEncoder > Make(const SharedContext *sharedContext, id< MTLCommandBuffer > commandBuffer, MTLRenderPassDescriptor *descriptor)
void drawPrimitives(MTLPrimitiveType primitiveType, NSUInteger vertexStart, NSUInteger vertexCount)
const char * getResourceType() const override
void setViewport(const MTLViewport &viewport)
void setRenderPipelineState(id< MTLRenderPipelineState > pso)
void setFrontFacingWinding(MTLWinding winding)
void setFragmentBufferOffset(NSUInteger offset, NSUInteger index) SK_API_AVAILABLE(macos(10.11)
void drawPrimitives(MTLPrimitiveType primitiveType, id< MTLBuffer > indirectBuffer, NSUInteger indirectBufferOffset) SK_API_AVAILABLE(macos(10.11)
void setFragmentBytes(const void *bytes, NSUInteger length, NSUInteger index) SK_API_AVAILABLE(macos(10.11)
void setFragmentBuffer(id< MTLBuffer > buffer, NSUInteger offset, NSUInteger index)
void setFragmentTexture(id< MTLTexture > texture, NSUInteger index)
void setLabel(NSString *label)
void setVertexBytes(const void *bytes, NSUInteger length, NSUInteger index) SK_API_AVAILABLE(macos(10.11)
void setBlendColor(float blendConst[4])
void setVertexBufferOffset(NSUInteger offset, NSUInteger index) SK_API_AVAILABLE(macos(10.11)
void drawPrimitives(MTLPrimitiveType primitiveType, NSUInteger vertexStart, NSUInteger vertexCount, NSUInteger instanceCount, NSUInteger baseInstance) SK_API_AVAILABLE(macos(10.11)
void setDepthStencilState(id< MTLDepthStencilState > depthStencilState)
const SharedContext * sharedContext() 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