Blender V4.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.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(eGPUBarrier 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 eGPUWriteMask value);
66 void set_depth_test(const eGPUDepthTest value);
67 void set_stencil_test(const eGPUStencilTest test, const eGPUStencilOp operation);
68 void set_stencil_mask(const eGPUStencilTest 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 eGPUFaceCullTest test);
73 void set_provoking_vert(const eGPUProvokingVertex vert);
74 void set_shadow_bias(const bool enable);
75 void set_blend(const eGPUBlend 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(eGPUStencilTest 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:
103 ~MTLFence();
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
eGPUBlend
Definition GPU_state.hh:84
eGPUWriteMask
Definition GPU_state.hh:16
eGPUProvokingVertex
Definition GPU_state.hh:138
eGPUFaceCullTest
Definition GPU_state.hh:132
eGPUBarrier
Definition GPU_state.hh:29
eGPUStencilOp
Definition GPU_state.hh:124
eGPUDepthTest
Definition GPU_state.hh:107
eGPUStencilTest
Definition GPU_state.hh:117
Read Guarded memory(de)allocation.
void signal() override
Definition mtl_state.mm:592
void wait() override
Definition mtl_state.mm:606
void image_unbind_all() override
Definition mtl_state.mm:699
void texture_unbind(Texture *tex) override
Definition mtl_state.mm:656
void image_unbind(Texture *tex) override
Definition mtl_state.mm:690
void force_state() override
Definition mtl_state.mm:59
void image_bind(Texture *tex, int unit) override
Definition mtl_state.mm:678
void texture_unpack_row_length_set(uint len) override
Definition mtl_state.mm:628
MTLRenderPipelineStateDescriptor & get_pipeline_descriptor()
Definition mtl_state.hh:59
void texture_bind(Texture *tex, GPUSamplerState sampler, int unit) override
Definition mtl_state.mm:635
void apply_state() override
Definition mtl_state.mm:50
MTLStateManager(MTLContext *ctx)
Definition mtl_state.mm:31
void issue_barrier(eGPUBarrier barrier_bits) override
Definition mtl_state.mm:568
void texture_unbind_all() override
Definition mtl_state.mm:665
local_group_size(16, 16) .push_constant(Type local_group_size(16, 16) .push_constant(Type input_tx sampler(1, ImageType::FLOAT_2D, "matte_tx") .image(0
int len
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition invert.h:9
unsigned __int64 uint64_t
Definition stdint.h:90