Blender V5.0
mtl_state.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8#pragma once
9
10#include "MEM_guardedalloc.h"
11
12#include "BLI_utildefines.h"
13
14#include "GPU_state.hh"
15#include "gpu_state_private.hh"
16
18
19namespace blender::gpu {
20
21/* Forward Declarations. */
22class MTLContext;
23
29
30 private:
31 /* Current state of the associated MTLContext.
32 * Avoids resetting the whole state for every change. */
33 GPUState current_;
34 GPUStateMutable current_mutable_;
35 MTLContext *context_;
36
37 /* Global pipeline descriptors. */
38 MTLRenderPipelineStateDescriptor pipeline_descriptor_;
39
40 public:
42
43 void apply_state() override;
44 void force_state() override;
45
46 void issue_barrier(GPUBarrier barrier_bits) override;
47
48 void texture_bind(Texture *tex, GPUSamplerState sampler, int unit) override;
49 void texture_unbind(Texture *tex) override;
50 void texture_unbind_all() override;
51
52 void image_bind(Texture *tex, int unit) override;
53 void image_unbind(Texture *tex) override;
54 void image_unbind_all() override;
55
57
58 /* Global pipeline descriptors. */
60 {
61 return pipeline_descriptor_;
62 }
63
64 private:
65 void set_write_mask(const GPUWriteMask value);
66 void set_depth_test(const GPUDepthTest value);
67 void set_stencil_test(const GPUStencilTest test, const GPUStencilOp operation);
68 void set_stencil_mask(const GPUStencilTest test, const GPUStateMutable &state);
69 void set_clip_distances(const int new_dist_len, const int old_dist_len);
70 void set_logic_op(const bool enable);
71 void set_facing(const bool invert);
72 void set_backface_culling(const GPUFaceCullTest test);
73 void set_provoking_vert(const GPUProvokingVertex vert);
74 void set_shadow_bias(const bool enable);
75 void set_blend(const GPUBlend value);
76
77 void set_state(const GPUState &state);
78 void set_mutable_state(const GPUStateMutable &state);
79
80 /* METAL State utility functions. */
81 void mtl_state_init();
82 void mtl_depth_range(float near, float far);
83 void mtl_stencil_mask(uint mask);
84 void mtl_stencil_set_func(GPUStencilTest stencil_func, int ref, uint mask);
85 void mtl_clip_plane_enable(uint i);
86 void mtl_clip_plane_disable(uint i);
87
88 MEM_CXX_CLASS_ALLOC_FUNCS("MTLStateManager")
89};
90
91/* Fence synchronization primitive. */
92class MTLFence : public Fence {
93 private:
94 /* Using an event in this instance, as this is global for the command stream, rather than being
95 * inserted at the encoder level. This has the behavior to match the GL functionality. */
96 id<MTLEvent> mtl_event_ = nil;
97 /* Events can be re-used multiple times. We can track a counter flagging the latest value
98 * signalled. */
99 uint64_t last_signalled_value_ = 0;
100
101 public:
102 MTLFence() : Fence() {};
103 ~MTLFence() override;
104
105 void signal() override;
106 void wait() override;
107
108 MEM_CXX_CLASS_ALLOC_FUNCS("MTLFence")
109};
110
111} // namespace blender::gpu
unsigned int uint
GPUBarrier
Definition GPU_state.hh:29
GPUDepthTest
Definition GPU_state.hh:110
GPUBlend
Definition GPU_state.hh:84
GPUProvokingVertex
Definition GPU_state.hh:141
GPUStencilTest
Definition GPU_state.hh:120
GPUWriteMask
Definition GPU_state.hh:16
GPUFaceCullTest
Definition GPU_state.hh:135
GPUStencilOp
Definition GPU_state.hh:127
Read Guarded memory(de)allocation.
unsigned long long int uint64_t
void signal() override
Definition mtl_state.mm:599
void wait() override
Definition mtl_state.mm:613
void image_unbind_all() override
Definition mtl_state.mm:707
void texture_unbind(Texture *tex) override
Definition mtl_state.mm:663
void image_unbind(Texture *tex) override
Definition mtl_state.mm:698
void force_state() override
Definition mtl_state.mm:59
void issue_barrier(GPUBarrier barrier_bits) override
Definition mtl_state.mm:575
void image_bind(Texture *tex, int unit) override
Definition mtl_state.mm:685
void texture_unpack_row_length_set(uint len) override
Definition mtl_state.mm:635
MTLRenderPipelineStateDescriptor & get_pipeline_descriptor()
Definition mtl_state.hh:59
void texture_bind(Texture *tex, GPUSamplerState sampler, int unit) override
Definition mtl_state.mm:642
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:672
CCL_NAMESPACE_BEGIN ccl_device float invert(const float color, const float factor)
Definition invert.h:11
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
static ulong state[N]
i
Definition text_draw.cc:230
uint len