Blender V5.3
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.hh"
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
56 /* Global pipeline descriptors. */
58 {
59 return pipeline_descriptor_;
60 }
61
62 private:
63 void set_write_mask(const GPUWriteMask value);
64 void set_depth_test(const GPUDepthTest value);
65 void set_stencil_test(const GPUStencilTest test, const GPUStencilOp operation);
66 void set_stencil_mask(const GPUStencilTest test, const GPUStateMutable &state);
67 void set_clip_distances(const int new_dist_len, const int old_dist_len);
68
69 void set_facing(const bool invert);
70 void set_backface_culling(const GPUFaceCullTest test);
71 void set_provoking_vert(const GPUProvokingVertex vert);
72 void set_blend(const GPUBlend value);
73
74 void set_state(const GPUState &state);
75 void set_mutable_state(const GPUStateMutable &state);
76
77 /* METAL State utility functions. */
78 void mtl_state_init();
79 void mtl_stencil_mask(uint mask);
80 void mtl_stencil_set_func(GPUStencilTest stencil_func, int ref, uint mask);
81 void mtl_clip_plane_enable(uint i);
82 void mtl_clip_plane_disable(uint i);
83
84 MEM_CXX_CLASS_ALLOC_FUNCS("MTLStateManager")
85};
86
87/* Fence synchronization primitive. */
88class MTLFence : public Fence {
89 private:
90 /* Using an event in this instance, as this is global for the command stream, rather than being
91 * inserted at the encoder level. This has the behavior to match the GL functionality. */
92 id<MTLEvent> mtl_event_ = nil;
93 /* Events can be re-used multiple times. We can track a counter flagging the latest value
94 * signalled. */
95 uint64_t last_signalled_value_ = 0;
96
97 public:
98 MTLFence() : Fence() {};
99 ~MTLFence() override;
100
101 void signal() override;
102 void wait() override;
103
104 MEM_CXX_CLASS_ALLOC_FUNCS("MTLFence")
105};
106
107} // namespace blender::gpu
Read Blender memory allocation and freeing.
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
MTLRenderPipelineStateDescriptor & get_pipeline_descriptor()
Definition mtl_state.hh:57
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
#define sampler(slot)
float2x2 invert(float2x2 mat)
const int state
unsigned __int64 uint64_t
Definition BKE_text.h:91
unsigned int uint
Definition BKE_text.h:55
GPUProvokingVertex
Definition GPU_state.hh:162