Blender V5.3
mtl_state.mm
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_math_base_c.hh"
10#include "BLI_math_bits.hh"
11
12#include "GPU_framebuffer.hh"
13
14#include "mtl_context.hh"
15#include "mtl_framebuffer.hh"
17#include "mtl_state.hh"
18
19namespace blender::gpu {
20
21/* -------------------------------------------------------------------- */
24
25void MTLStateManager::mtl_state_init()
26{
27 BLI_assert(context_);
28 context_->pipeline_state_init();
29}
30
32{
33 /* Initialize State. */
34 context_ = ctx;
35 mtl_state_init();
36
37 /* Force update using default state. */
38 current_ = ~state;
39 current_mutable_ = ~mutable_state;
40
41 /* Clip distances initial mask forces to 0x111, which exceeds
42 * max clip plane count of 6, so limit to ensure all clipping
43 * planes get disabled. */
44 current_.clip_distances = 6;
45
46 set_state(state);
47 set_mutable_state(mutable_state);
48}
49
51{
52 this->set_state(this->state);
53 this->set_mutable_state(this->mutable_state);
54
55 /* Apply active FrameBuffer state. */
56 static_cast<MTLFrameBuffer *>(context_->active_fb)->apply_state();
57};
58
60{
61 /* Little exception for clip distances since they need to keep the old count correct. */
62 uint32_t clip_distances = current_.clip_distances;
63 BLI_assert(clip_distances <= 6);
64 current_ = ~this->state;
65 current_.clip_distances = clip_distances;
66 current_mutable_ = ~this->mutable_state;
67 this->set_state(this->state);
68 this->set_mutable_state(this->mutable_state);
69};
70
71void MTLStateManager::set_state(const GPUState &state)
72{
73 GPUState changed = state ^ current_;
74
75 if (changed.blend != 0) {
76 set_blend((GPUBlend)state.blend);
77 }
78 if (changed.write_mask != 0) {
79 set_write_mask((GPUWriteMask)state.write_mask);
80 }
81 if (changed.depth_test != 0) {
82 set_depth_test((GPUDepthTest)state.depth_test);
83 }
84 if (changed.stencil_test != 0 || changed.stencil_op != 0) {
85 set_stencil_test((GPUStencilTest)state.stencil_test, (GPUStencilOp)state.stencil_op);
86 set_stencil_mask((GPUStencilTest)state.stencil_test, mutable_state);
87 }
88 if (changed.clip_distances != 0) {
89 set_clip_distances(state.clip_distances, current_.clip_distances);
90 }
91 if (changed.culling_test != 0) {
92 set_backface_culling((GPUFaceCullTest)state.culling_test);
93 }
94
95 if (changed.invert_facing != 0) {
96 set_facing(state.invert_facing);
97 }
98 if (changed.provoking_vert != 0) {
99 set_provoking_vert((GPUProvokingVertex)state.provoking_vert);
100 }
101
102 /* TODO remove (Following GLState). */
103 if (changed.polygon_smooth) {
104 /* NOTE: Unsupported in Metal. */
105 }
106 if (changed.line_smooth) {
107 /* NOTE: Unsupported in Metal. */
108 }
109
110 current_ = state;
111}
112
113void MTLStateManager::set_mutable_state(const GPUStateMutable &state)
114{
115 GPUStateMutable changed = state ^ current_mutable_;
116 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
117
118 if (float_as_uint(changed.point_size) != 0) {
119 pipeline_state.point_size = state.point_size;
120 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_PSO_FLAG;
121 }
122
123 if (changed.line_width != 0) {
124 pipeline_state.line_width = state.line_width;
125 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_PSO_FLAG;
126 }
127
128 if (changed.stencil_compare_mask != 0 || changed.stencil_reference != 0 ||
129 changed.stencil_write_mask != 0)
130 {
131 set_stencil_mask((GPUStencilTest)current_.stencil_test, state);
132 }
133
134 current_mutable_ = state;
135}
136
138
139/* -------------------------------------------------------------------- */
142
143void MTLStateManager::set_write_mask(const GPUWriteMask value)
144{
145 BLI_assert(context_);
146 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
147 pipeline_state.depth_stencil_state.depth_write_enable = ((value & GPU_WRITE_DEPTH) != 0);
148 pipeline_state.color_write_mask =
149 (((value & GPU_WRITE_RED) != 0) ? MTLColorWriteMaskRed : MTLColorWriteMaskNone) |
150 (((value & GPU_WRITE_GREEN) != 0) ? MTLColorWriteMaskGreen : MTLColorWriteMaskNone) |
151 (((value & GPU_WRITE_BLUE) != 0) ? MTLColorWriteMaskBlue : MTLColorWriteMaskNone) |
152 (((value & GPU_WRITE_ALPHA) != 0) ? MTLColorWriteMaskAlpha : MTLColorWriteMaskNone);
153 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_PSO_FLAG;
154}
155
156static MTLCompareFunction gpu_depth_function_to_metal(GPUDepthTest depth_func)
157{
158 switch (depth_func) {
159 case GPU_DEPTH_NONE:
160 return MTLCompareFunctionNever;
161 case GPU_DEPTH_LESS:
162 return MTLCompareFunctionLess;
163 case GPU_DEPTH_EQUAL:
164 return MTLCompareFunctionEqual;
166 return MTLCompareFunctionLessEqual;
168 return MTLCompareFunctionGreater;
170 return MTLCompareFunctionGreaterEqual;
171 case GPU_DEPTH_ALWAYS:
172 return MTLCompareFunctionAlways;
173 default:
174 BLI_assert(false && "Invalid GPUDepthTest");
175 break;
176 }
177 return MTLCompareFunctionAlways;
178}
179
180static MTLCompareFunction gpu_stencil_func_to_metal(GPUStencilTest stencil_func)
181{
182 switch (stencil_func) {
183 case GPU_STENCIL_NONE:
184 return MTLCompareFunctionAlways;
186 return MTLCompareFunctionEqual;
188 return MTLCompareFunctionNotEqual;
190 return MTLCompareFunctionAlways;
191 default:
192 BLI_assert(false && "Unrecognized GPUStencilTest function");
193 break;
194 }
195 return MTLCompareFunctionAlways;
196}
197
198void MTLStateManager::set_depth_test(const GPUDepthTest value)
199{
200 BLI_assert(context_);
201 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
202 MTLContextDepthStencilState &ds_state = pipeline_state.depth_stencil_state;
203
204 ds_state.depth_test_enabled = (value != GPU_DEPTH_NONE);
207}
208
209void MTLStateManager::mtl_stencil_mask(uint mask)
210{
211 BLI_assert(context_);
212 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
214 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_DEPTHSTENCIL_FLAG;
215}
216
217void MTLStateManager::mtl_stencil_set_func(GPUStencilTest stencil_func, int ref, uint mask)
218{
219 BLI_assert(context_);
220 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
221 MTLContextDepthStencilState &ds_state = pipeline_state.depth_stencil_state;
222
223 ds_state.stencil_func = gpu_stencil_func_to_metal(stencil_func);
224 ds_state.stencil_ref = ref;
225 ds_state.stencil_read_mask = mask;
226 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_DEPTHSTENCIL_FLAG;
227}
228
230 GPUFaceCullTest face,
231 MTLStencilOperation stencil_fail,
232 MTLStencilOperation depth_test_fail,
233 MTLStencilOperation depthstencil_pass)
234{
235 BLI_assert(context);
236 MTLContextGlobalShaderPipelineState &pipeline_state = context->pipeline_state;
237 MTLContextDepthStencilState &ds_state = pipeline_state.depth_stencil_state;
238
239 if (face == GPU_CULL_FRONT) {
240 ds_state.stencil_op_front_stencil_fail = stencil_fail;
241 ds_state.stencil_op_front_depth_fail = depth_test_fail;
242 ds_state.stencil_op_front_depthstencil_pass = depthstencil_pass;
243 }
244 else if (face == GPU_CULL_BACK) {
245 ds_state.stencil_op_back_stencil_fail = stencil_fail;
246 ds_state.stencil_op_back_depth_fail = depth_test_fail;
247 ds_state.stencil_op_back_depthstencil_pass = depthstencil_pass;
248 }
249
251}
252
253static void mtl_stencil_set_op(MTLContext *context,
254 MTLStencilOperation stencil_fail,
255 MTLStencilOperation depth_test_fail,
256 MTLStencilOperation depthstencil_pass)
257{
259 context, GPU_CULL_FRONT, stencil_fail, depth_test_fail, depthstencil_pass);
261 context, GPU_CULL_BACK, stencil_fail, depth_test_fail, depthstencil_pass);
262}
263
264void MTLStateManager::set_stencil_test(const GPUStencilTest test, const GPUStencilOp operation)
265{
266 switch (operation) {
269 context_, MTLStencilOperationKeep, MTLStencilOperationKeep, MTLStencilOperationReplace);
270 break;
274 MTLStencilOperationKeep,
275 MTLStencilOperationKeep,
276 MTLStencilOperationIncrementWrap);
279 MTLStencilOperationKeep,
280 MTLStencilOperationKeep,
281 MTLStencilOperationDecrementWrap);
282 break;
286 MTLStencilOperationKeep,
287 MTLStencilOperationDecrementWrap,
288 MTLStencilOperationKeep);
291 MTLStencilOperationKeep,
292 MTLStencilOperationIncrementWrap,
293 MTLStencilOperationKeep);
294 break;
296 default:
298 context_, MTLStencilOperationKeep, MTLStencilOperationKeep, MTLStencilOperationKeep);
299 }
300
301 BLI_assert(context_);
302 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
304 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_DEPTHSTENCIL_FLAG;
305}
306
307void MTLStateManager::set_stencil_mask(const GPUStencilTest test, const GPUStateMutable &state)
308{
309 if (test == GPU_STENCIL_NONE) {
310 mtl_stencil_mask(0x00);
311 mtl_stencil_set_func(GPU_STENCIL_ALWAYS, 0x00, 0x00);
312 }
313 else {
314 mtl_stencil_mask(state.stencil_write_mask);
315 mtl_stencil_set_func(test, state.stencil_reference, state.stencil_compare_mask);
316 }
317}
318
319void MTLStateManager::mtl_clip_plane_enable(uint i)
320{
321 BLI_assert(context_);
322 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
323 pipeline_state.clip_distance_enabled[i] = true;
324 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_PSO_FLAG;
325}
326
327void MTLStateManager::mtl_clip_plane_disable(uint i)
328{
329 BLI_assert(context_);
330 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
331 pipeline_state.clip_distance_enabled[i] = false;
332 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_PSO_FLAG;
333}
334
335void MTLStateManager::set_clip_distances(const int new_dist_len, const int old_dist_len)
336{
337 BLI_assert(new_dist_len <= 6);
338 BLI_assert(old_dist_len <= 6);
339 for (uint i = 0; i < new_dist_len; i++) {
340 mtl_clip_plane_enable(i);
341 }
342 for (uint i = new_dist_len; i < old_dist_len; i++) {
343 mtl_clip_plane_disable(i);
344 }
345}
346
347void MTLStateManager::set_facing(const bool invert)
348{
349 /* Check Current Context. */
350 BLI_assert(context_);
351 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
352
353 /* Apply State -- opposite of GL, as METAL default is GPU_CLOCKWISE, GL default is
354 * COUNTERCLOCKWISE. This needs to be the inverse of the default. */
355 pipeline_state.front_face = (invert) ? GPU_COUNTERCLOCKWISE : GPU_CLOCKWISE;
356
357 /* Mark Dirty - Ensure context updates state between draws. */
358 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_FRONT_FACING_FLAG;
359 pipeline_state.dirty = true;
360}
361
362void MTLStateManager::set_backface_culling(const GPUFaceCullTest test)
363{
364 /* Check Current Context. */
365 BLI_assert(context_);
366 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
367
368 /* Apply State. */
369 pipeline_state.culling_enabled = (test != GPU_CULL_NONE);
370 pipeline_state.cull_mode = test;
371
372 /* Mark Dirty - Ensure context updates state between draws. */
373 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_CULLMODE_FLAG;
374 pipeline_state.dirty = true;
375}
376
377void MTLStateManager::set_provoking_vert(const GPUProvokingVertex /*vert*/)
378{
379 /* NOTE(Metal): Provoking vertex is not a feature in the Metal API.
380 * Shaders are handled on a case-by-case basis using a modified vertex shader.
381 * For example, wireframe rendering and edit-mesh shaders utilize an SSBO-based
382 * vertex pulling mechanism which considers the inverse convention for flat
383 * shading, to ensure consistent results with OpenGL. */
384}
385
386void MTLStateManager::set_blend(const GPUBlend value)
387{
395 MTLBlendFactor src_rgb;
396 MTLBlendFactor dst_rgb;
397 MTLBlendFactor src_alpha;
398 MTLBlendFactor dst_alpha;
399 switch (value) {
400 default:
401 case GPU_BLEND_ALPHA: {
402 src_rgb = MTLBlendFactorSourceAlpha;
403 dst_rgb = MTLBlendFactorOneMinusSourceAlpha;
404 src_alpha = MTLBlendFactorOne;
405 dst_alpha = MTLBlendFactorOneMinusSourceAlpha;
406 break;
407 }
409 src_rgb = MTLBlendFactorOne;
410 dst_rgb = MTLBlendFactorOneMinusSourceAlpha;
411 src_alpha = MTLBlendFactorOne;
412 dst_alpha = MTLBlendFactorOneMinusSourceAlpha;
413 break;
414 }
415 case GPU_BLEND_ADDITIVE: {
416 /* Do not let alpha accumulate but pre-multiply the source RGB by it. */
417 src_rgb = MTLBlendFactorSourceAlpha;
418 dst_rgb = MTLBlendFactorOne;
419 src_alpha = MTLBlendFactorZero;
420 dst_alpha = MTLBlendFactorOne;
421 break;
422 }
423 /* Factors are not use in min or max mode, but avoid uninitialized values. */;
424 case GPU_BLEND_MIN:
425 case GPU_BLEND_MAX:
428 /* Let alpha accumulate. */
429 src_rgb = MTLBlendFactorOne;
430 dst_rgb = MTLBlendFactorOne;
431 src_alpha = MTLBlendFactorOne;
432 dst_alpha = MTLBlendFactorOne;
433 break;
434 }
435 case GPU_BLEND_MULTIPLY: {
436 src_rgb = MTLBlendFactorDestinationColor;
437 dst_rgb = MTLBlendFactorZero;
438 src_alpha = MTLBlendFactorDestinationAlpha;
439 dst_alpha = MTLBlendFactorZero;
440 break;
441 }
442 case GPU_BLEND_INVERT: {
443 src_rgb = MTLBlendFactorOneMinusDestinationColor;
444 dst_rgb = MTLBlendFactorZero;
445 src_alpha = MTLBlendFactorZero;
446 dst_alpha = MTLBlendFactorOne;
447 break;
448 }
449 case GPU_BLEND_OIT: {
450 src_rgb = MTLBlendFactorOne;
451 dst_rgb = MTLBlendFactorOne;
452 src_alpha = MTLBlendFactorZero;
453 dst_alpha = MTLBlendFactorOneMinusSourceAlpha;
454 break;
455 }
457 src_rgb = MTLBlendFactorOneMinusDestinationAlpha;
458 dst_rgb = MTLBlendFactorSourceAlpha;
459 src_alpha = MTLBlendFactorZero;
460 dst_alpha = MTLBlendFactorSourceAlpha;
461 break;
462 }
464 src_rgb = MTLBlendFactorOneMinusDestinationAlpha;
465 dst_rgb = MTLBlendFactorOne;
466 src_alpha = MTLBlendFactorOneMinusDestinationAlpha;
467 dst_alpha = MTLBlendFactorOne;
468 break;
469 }
470 case GPU_BLEND_CUSTOM: {
471 src_rgb = MTLBlendFactorOne;
472 dst_rgb = MTLBlendFactorSource1Color;
473 src_alpha = MTLBlendFactorOne;
474 dst_alpha = MTLBlendFactorSource1Alpha;
475 break;
476 }
478 src_rgb = MTLBlendFactorZero;
479 dst_rgb = MTLBlendFactorOneMinusSourceAlpha;
480 src_alpha = MTLBlendFactorZero;
481 dst_alpha = MTLBlendFactorOneMinusSourceAlpha;
482 break;
483 }
485 src_rgb = MTLBlendFactorOne;
486 dst_rgb = MTLBlendFactorSourceAlpha;
487 src_alpha = MTLBlendFactorZero;
488 dst_alpha = MTLBlendFactorSourceAlpha;
489 break;
490 }
491 }
492
493 /* Check Current Context. */
494 BLI_assert(context_);
495 MTLContextGlobalShaderPipelineState &pipeline_state = context_->pipeline_state;
496
497 if (value == GPU_BLEND_MIN) {
498 pipeline_state.rgb_blend_op = MTLBlendOperationMin;
499 pipeline_state.alpha_blend_op = MTLBlendOperationMin;
500 }
501 else if (value == GPU_BLEND_MAX) {
502 pipeline_state.rgb_blend_op = MTLBlendOperationMax;
503 pipeline_state.alpha_blend_op = MTLBlendOperationMax;
504 }
505 else if (value == GPU_BLEND_SUBTRACT) {
506 pipeline_state.rgb_blend_op = MTLBlendOperationReverseSubtract;
507 pipeline_state.alpha_blend_op = MTLBlendOperationReverseSubtract;
508 }
509 else {
510 pipeline_state.rgb_blend_op = MTLBlendOperationAdd;
511 pipeline_state.alpha_blend_op = MTLBlendOperationAdd;
512 }
513
514 /* Apply State. */
515 pipeline_state.blending_enabled = (value != GPU_BLEND_NONE);
516 pipeline_state.src_rgb_blend_factor = src_rgb;
517 pipeline_state.dest_rgb_blend_factor = dst_rgb;
518 pipeline_state.src_alpha_blend_factor = src_alpha;
519 pipeline_state.dest_alpha_blend_factor = dst_alpha;
520
521 /* Mark Dirty - Ensure context updates PSOs between draws. */
522 pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_PSO_FLAG;
523 pipeline_state.dirty = true;
524}
525
527
528/* -------------------------------------------------------------------- */
531
532/* NOTE(Metal): Granular option for specifying before/after stages for a barrier
533 * Would be a useful feature. */
534#if 0
536 GPUStageBarrierBits before_stages,
537 GPUStageBarrierBits after_stages)
538#endif
540{
541 /* NOTE(Metal): The Metal API implicitly tracks dependencies between resources.
542 * Memory barriers and execution barriers (Fences/Events) can be used to coordinate
543 * this explicitly, however, in most cases, the driver will be able to
544 * resolve these dependencies automatically.
545 * For untracked resources, such as MTLHeap's, explicit barriers are necessary. */
548
550 BLI_assert(ctx);
551
552 ctx->main_command_buffer.insert_memory_barrier(barrier_bits, before_stages, after_stages);
553}
554
556{
557 if (mtl_event_) {
558 [mtl_event_ release];
559 mtl_event_ = nil;
560 }
561}
562
564{
565 if (mtl_event_ == nil) {
567 BLI_assert(ctx);
568 mtl_event_ = [ctx->device newEvent];
569 }
571 BLI_assert(ctx);
572 ctx->main_command_buffer.encode_signal_event(mtl_event_, ++last_signalled_value_);
573
574 signalled_ = true;
575}
576
578{
579 /* do not attempt to wait if event has not yet been signalled for the first time. */
580 if (mtl_event_ == nil) {
581 return;
582 }
583
584 if (signalled_) {
586 BLI_assert(ctx);
587
588 ctx->main_command_buffer.encode_wait_for_event(mtl_event_, last_signalled_value_);
589 signalled_ = false;
590 }
591}
592
594
595/* -------------------------------------------------------------------- */
598
599void MTLStateManager::texture_bind(Texture *tex_, GPUSamplerState sampler_type, int unit)
600{
601 BLI_assert(tex_);
602 gpu::MTLTexture *mtl_tex = static_cast<gpu::MTLTexture *>(tex_);
603 BLI_assert(mtl_tex);
604
606 if (unit >= 0) {
607 ctx->texture_bind(mtl_tex, unit, false);
608
609 /* Fetching textures default sampler configuration and applying
610 * eGPUSampler State on top. This path exists to support
611 * Any of the sampler state which is associated with the
612 * texture itself such as min/max mip levels. */
614 sampler.state = sampler_type;
615
616 ctx->sampler_bind(sampler, unit);
617 }
618}
619
621{
622 BLI_assert(tex_);
623 gpu::MTLTexture *mtl_tex = static_cast<gpu::MTLTexture *>(tex_);
624 BLI_assert(mtl_tex);
626 ctx->texture_unbind(mtl_tex, false, this);
627}
628
630{
632 BLI_assert(ctx);
633 ctx->texture_unbind_all(false);
634}
635
637
638/* -------------------------------------------------------------------- */
641
643{
644 BLI_assert(tex_);
645 gpu::MTLTexture *mtl_tex = static_cast<gpu::MTLTexture *>(tex_);
646 BLI_assert(mtl_tex);
647
649 if (unit >= 0) {
650 ctx->texture_bind(mtl_tex, unit, true);
651 /* An sRGB texture bound as a storage image is written as UNORM: the hardware does the sRGB
652 * encode/decode. TextureWriteFormat has no sRGB entry, use UNORM instead to avoid adding
653 * a bunch of complexity elsewhere. */
654 TextureFormat format = tex_->format_get();
655 if (format == TextureFormat::SRGBA_8_8_8_8) {
656 format = TextureFormat::UNORM_8_8_8_8;
657 }
658 image_formats[unit] = TextureWriteFormat(format);
659 }
660}
661
663{
664 BLI_assert(tex_);
665 gpu::MTLTexture *mtl_tex = static_cast<gpu::MTLTexture *>(tex_);
666 BLI_assert(mtl_tex);
668 ctx->texture_unbind(mtl_tex, true, this);
669}
670
678
680
681} // namespace blender::gpu
#define BLI_assert(a)
void encode_signal_event(id< MTLEvent > event, uint64_t value)
bool insert_memory_barrier(GPUBarrier barrier_bits, GPUStageBarrierBits before_stages, GPUStageBarrierBits after_stages)
void encode_wait_for_event(id< MTLEvent > event, uint64_t value)
static MTLContext * get()
MTLContextGlobalShaderPipelineState pipeline_state
void texture_unbind(gpu::MTLTexture *mtl_texture, bool is_image, StateManager *state_manager)
void sampler_bind(MTLSamplerState, uint sampler_unit)
void texture_bind(gpu::MTLTexture *mtl_texture, uint texture_unit, bool is_image)
MTLCommandBufferManager main_command_buffer
void texture_unbind_all(bool is_image)
void signal() override
Definition mtl_state.mm:563
void wait() override
Definition mtl_state.mm:577
void image_unbind_all() override
Definition mtl_state.mm:671
void texture_unbind(Texture *tex) override
Definition mtl_state.mm:620
void image_unbind(Texture *tex) override
Definition mtl_state.mm:662
void force_state() override
Definition mtl_state.mm:59
void issue_barrier(GPUBarrier barrier_bits) override
Definition mtl_state.mm:539
void image_bind(Texture *tex, int unit) override
Definition mtl_state.mm:642
void texture_bind(Texture *tex, GPUSamplerState sampler, int unit) override
Definition mtl_state.mm:599
void apply_state() override
Definition mtl_state.mm:50
MTLStateManager(MTLContext *ctx)
Definition mtl_state.mm:31
void texture_unbind_all() override
Definition mtl_state.mm:629
MTLSamplerState get_sampler_state()
std::array< TextureWriteFormat, GPU_MAX_IMAGE > image_formats
TextureFormat format_get() const
#define sampler(slot)
float2x2 invert(float2x2 mat)
const int state
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
static void mtl_stencil_set_op_separate(MTLContext *context, GPUFaceCullTest face, MTLStencilOperation stencil_fail, MTLStencilOperation depth_test_fail, MTLStencilOperation depthstencil_pass)
Definition mtl_state.mm:229
static void mtl_stencil_set_op(MTLContext *context, MTLStencilOperation stencil_fail, MTLStencilOperation depth_test_fail, MTLStencilOperation depthstencil_pass)
Definition mtl_state.mm:253
@ MTL_PIPELINE_STATE_CULLMODE_FLAG
@ MTL_PIPELINE_STATE_PSO_FLAG
@ MTL_PIPELINE_STATE_FRONT_FACING_FLAG
@ MTL_PIPELINE_STATE_DEPTHSTENCIL_FLAG
static MTLCompareFunction gpu_stencil_func_to_metal(GPUStencilTest stencil_func)
Definition mtl_state.mm:180
static MTLCompareFunction gpu_depth_function_to_metal(GPUDepthTest depth_func)
Definition mtl_state.mm:156
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ GPU_CULL_FRONT
Definition GPU_state.hh:158
@ GPU_CULL_NONE
Definition GPU_state.hh:157
@ GPU_CULL_BACK
Definition GPU_state.hh:159
@ GPU_STENCIL_OP_COUNT_DEPTH_FAIL
Definition GPU_state.hh:153
@ GPU_STENCIL_OP_COUNT_DEPTH_PASS
Definition GPU_state.hh:152
@ GPU_STENCIL_OP_NONE
Definition GPU_state.hh:149
@ GPU_STENCIL_OP_REPLACE
Definition GPU_state.hh:150
GPUStageBarrierBits
Definition GPU_state.hh:68
@ GPU_BARRIER_STAGE_ANY
Definition GPU_state.hh:73
unsigned int uint
Definition BKE_text.h:55
MINLINE unsigned int float_as_uint(float f)
@ GPU_BLEND_MIN
Definition GPU_state.hh:102
@ GPU_BLEND_OVERLAY_MASK_FROM_ALPHA
Definition GPU_state.hh:122
@ GPU_BLEND_TRANSPARENCY
Definition GPU_state.hh:128
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_OIT
Definition GPU_state.hh:109
@ GPU_BLEND_MAX
Definition GPU_state.hh:104
@ GPU_BLEND_ALPHA_UNDER_PREMUL
Definition GPU_state.hh:117
@ GPU_BLEND_ADDITIVE_PREMULT
Definition GPU_state.hh:93
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
@ GPU_BLEND_ADDITIVE
Definition GPU_state.hh:92
@ GPU_BLEND_BACKGROUND
Definition GPU_state.hh:111
@ GPU_BLEND_SUBTRACT
Definition GPU_state.hh:95
@ GPU_BLEND_ALPHA_PREMULT
Definition GPU_state.hh:91
@ GPU_BLEND_INVERT
Definition GPU_state.hh:100
@ GPU_BLEND_MULTIPLY
Definition GPU_state.hh:94
@ GPU_BLEND_CUSTOM
Definition GPU_state.hh:116
unsigned int uint32_t
Definition BKE_text.h:81
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:135
@ GPU_DEPTH_ALWAYS
Definition GPU_state.hh:133
@ GPU_DEPTH_GREATER
Definition GPU_state.hh:137
@ GPU_DEPTH_LESS
Definition GPU_state.hh:134
@ GPU_DEPTH_GREATER_EQUAL
Definition GPU_state.hh:138
@ GPU_DEPTH_EQUAL
Definition GPU_state.hh:136
@ GPU_STENCIL_ALWAYS
Definition GPU_state.hh:143
@ GPU_STENCIL_EQUAL
Definition GPU_state.hh:144
@ GPU_STENCIL_NONE
Definition GPU_state.hh:142
@ GPU_STENCIL_NEQUAL
Definition GPU_state.hh:145
@ GPU_WRITE_ALPHA
Definition GPU_state.hh:24
@ GPU_WRITE_RED
Definition GPU_state.hh:21
@ GPU_WRITE_BLUE
Definition GPU_state.hh:23
@ GPU_WRITE_GREEN
Definition GPU_state.hh:22
@ GPU_WRITE_DEPTH
Definition GPU_state.hh:25
GPUProvokingVertex
Definition GPU_state.hh:162
void mask(PageMask &srt, TileMaps &tilemaps, const uint3 global_id, const uint local_tile_index)
MTLStencilOperation stencil_op_back_depthstencil_pass
MTLStencilOperation stencil_op_front_stencil_fail
MTLStencilOperation stencil_op_front_depthstencil_pass