Blender  V3.3
mtl_context.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #pragma once
8 
9 #include "MEM_guardedalloc.h"
10 
11 #include "gpu_context_private.hh"
12 
13 #include "GPU_common_types.h"
14 #include "GPU_context.h"
15 
16 #include "mtl_backend.hh"
17 #include "mtl_capabilities.hh"
18 #include "mtl_common.hh"
19 #include "mtl_framebuffer.hh"
20 #include "mtl_memory.hh"
21 #include "mtl_texture.hh"
22 
23 #include <Cocoa/Cocoa.h>
24 #include <Metal/Metal.h>
25 #include <QuartzCore/QuartzCore.h>
26 
27 @class CAMetalLayer;
28 @class MTLCommandQueue;
29 @class MTLRenderPipelineState;
30 
31 namespace blender::gpu {
32 
33 /* Forward Declarations */
34 class MTLContext;
35 class MTLCommandBufferManager;
36 class MTLShader;
37 class MTLUniformBuf;
38 
39 /* Structs containing information on current binding state for textures and samplers. */
41  bool used;
42 
43  /* Same value as index in bindings array. */
46 };
47 
49  bool used;
51 
52  bool operator==(MTLSamplerBinding const &other) const
53  {
54  return (used == other.used && state == other.state);
55  }
56 };
57 
58 /* Metal Context Render Pass State -- Used to track active RenderCommandEncoder state based on
59  * bound MTLFrameBuffer's.Owned by MTLContext. */
61  friend class MTLContext;
62 
64  : ctx(context), cmd(command_buffer_manager){};
65 
66  /* Given a RenderPassState is associated with a live RenderCommandEncoder,
67  * this state sits within the MTLCommandBufferManager. */
70 
71  /* Caching of resource bindings for active MTLRenderCommandEncoder.
72  * In Metal, resource bindings are local to the MTLCommandEncoder,
73  * not globally to the whole pipeline/cmd buffer. */
75  MTLShader *shader_ = nullptr;
77  void set(MTLShader *shader, uint pso_index)
78  {
79  shader_ = shader;
80  pso_index_ = pso_index;
81  }
82  };
83 
85  id<MTLRenderPipelineState> bound_pso = nil;
86  id<MTLDepthStencilState> bound_ds_state = nil;
88  MTLScissorRect last_scissor_rect;
89 
90  /* Caching of CommandEncoder Vertex/Fragment buffer bindings. */
92  /* Whether the given binding slot uses byte data (Push Constant equivalent)
93  * or an MTLBuffer. */
94  bool is_bytes;
95  id<MTLBuffer> metal_buffer;
96  int offset;
97  };
98 
101 
102  /* Caching of CommandEncoder textures bindings. */
104  id<MTLTexture> metal_texture;
105  };
106 
109 
110  /* Cached of CommandEncoder sampler states. */
113  id<MTLSamplerState> sampler_state;
115  };
116 
119 
120  /* Reset RenderCommandEncoder binding state. */
121  void reset_state();
122 
123  /* Texture Binding (RenderCommandEncoder). */
124  void bind_vertex_texture(id<MTLTexture> tex, uint slot);
125  void bind_fragment_texture(id<MTLTexture> tex, uint slot);
126 
127  /* Sampler Binding (RenderCommandEncoder). */
129  bool use_argument_buffer_for_samplers,
130  uint slot);
132  bool use_argument_buffer_for_samplers,
133  uint slot);
134 
135  /* Buffer binding (RenderCommandEncoder). */
136  void bind_vertex_buffer(id<MTLBuffer> buffer, uint buffer_offset, uint index);
137  void bind_fragment_buffer(id<MTLBuffer> buffer, uint buffer_offset, uint index);
138  void bind_vertex_bytes(void *bytes, uint length, uint index);
139  void bind_fragment_bytes(void *bytes, uint length, uint index);
140 };
141 
142 /* Depth Stencil State */
144 
145  /* Depth State. */
150  MTLCompareFunction depth_function;
151  float depth_bias;
156 
157  /* Stencil State. */
162  MTLCompareFunction stencil_func;
163 
164  MTLStencilOperation stencil_op_front_stencil_fail;
165  MTLStencilOperation stencil_op_front_depth_fail;
167 
168  MTLStencilOperation stencil_op_back_stencil_fail;
169  MTLStencilOperation stencil_op_back_depth_fail;
171 
172  /* Frame-buffer State -- We need to mark this, in case stencil state remains unchanged,
173  * but attachment state has changed. */
176 
177  /* TODO(Metal): Consider optimizing this function using memcmp.
178  * Un-used, but differing, stencil state leads to over-generation
179  * of state objects when doing trivial compare. */
180  bool operator==(const MTLContextDepthStencilState &other) const
181  {
182  bool depth_state_equality = (has_depth_target == other.has_depth_target &&
185  depth_function == other.depth_function);
186 
187  bool stencil_state_equality = true;
188  if (has_stencil_target) {
189  stencil_state_equality =
200  }
201 
202  return depth_state_equality && stencil_state_equality;
203  }
204 
205  /* Depth stencil state will get hashed in order to prepare
206  * MTLDepthStencilState objects. The hash should comprise of
207  * all elements which fill the MTLDepthStencilDescriptor.
208  * These are bound when [rec setDepthStencilState:...] is called.
209  * Depth bias and stencil reference value are set dynamically on the RenderCommandEncoder:
210  * - setStencilReferenceValue:
211  * - setDepthBias:slopeScale:clamp:
212  */
213  std::size_t hash() const
214  {
215  std::size_t boolean_bitmask = (this->depth_write_enable ? 1 : 0) |
216  ((this->depth_test_enabled ? 1 : 0) << 1) |
217  ((this->depth_bias_enabled_for_points ? 1 : 0) << 2) |
218  ((this->depth_bias_enabled_for_lines ? 1 : 0) << 3) |
219  ((this->depth_bias_enabled_for_tris ? 1 : 0) << 4) |
220  ((this->stencil_test_enabled ? 1 : 0) << 5) |
221  ((this->has_depth_target ? 1 : 0) << 6) |
222  ((this->has_stencil_target ? 1 : 0) << 7);
223 
224  std::size_t stencilop_bitmask = ((std::size_t)this->stencil_op_front_stencil_fail) |
225  ((std::size_t)this->stencil_op_front_depth_fail << 3) |
226  ((std::size_t)this->stencil_op_front_depthstencil_pass << 6) |
227  ((std::size_t)this->stencil_op_back_stencil_fail << 9) |
228  ((std::size_t)this->stencil_op_back_depth_fail << 12) |
229  ((std::size_t)this->stencil_op_back_depthstencil_pass << 15);
230 
231  std::size_t main_hash = (std::size_t)this->depth_function;
232  if (this->has_stencil_target) {
233  main_hash += (std::size_t)(this->stencil_read_mask & 0xFF) << 8;
234  main_hash += (std::size_t)(this->stencil_write_mask & 0xFF) << 16;
235  }
236  main_hash ^= (std::size_t)this->stencil_func << 16;
237  main_hash ^= stencilop_bitmask;
238 
239  std::size_t final_hash = (main_hash << 8) | boolean_bitmask;
240  return final_hash;
241  }
242 };
243 
245 
246  /* Depth Update Utilities */
247  /* Depth texture updates are not directly supported with Blit operations, similarly, we cannot
248  * use a compute shader to write to depth, so we must instead render to a depth target.
249  * These processes use vertex/fragment shaders to render texture data from an intermediate
250  * source, in order to prime the depth buffer*/
253 
254  /* Texture Read/Update routines */
271 
288 
289  template<typename T> void free_cached_pso_map(blender::Map<T, id<MTLComputePipelineState>> &map)
290  {
291  for (typename blender::Map<T, id<MTLComputePipelineState>>::MutableItem item : map.items()) {
292  [item.value release];
293  }
294  map.clear();
295  }
296 
297  void init()
298  {
299  fullscreen_blit_shader = nullptr;
300  }
301 
302  void cleanup()
303  {
306  }
307 
308  /* Free Read shader maps */
326  }
327 };
328 
329 /* Combined sampler state configuration for Argument Buffer caching. */
332  /* MTLSamplerState permutations between 0..256 - slightly more than a byte. */
334  id<MTLSamplerState> mtl_sampler[MTL_MAX_TEXTURE_SLOTS];
335 
336  bool operator==(const MTLSamplerArray &other) const
337  {
338  if (this->num_samplers != other.num_samplers) {
339  return false;
340  }
341  return (memcmp(this->mtl_sampler_flags,
342  other.mtl_sampler_flags,
343  sizeof(MTLSamplerState) * this->num_samplers) == 0);
344  }
345 
346  uint32_t hash() const
347  {
348  uint32_t hash = this->num_samplers;
349  for (int i = 0; i < this->num_samplers; i++) {
350  hash ^= (uint32_t)this->mtl_sampler_flags[i] << (i % 3);
351  }
352  return hash;
353  }
354 };
355 
358  /* Whether we need to call setViewport. */
360  /* Whether we need to call setScissor.*/
362  /* Whether we need to update/rebind active depth stencil state. */
364  /* Whether we need to update/rebind active PSO. */
366  /* Whether we need to update the frontFacingWinding state. */
368  /* Whether we need to update the culling state. */
370  /* Full pipeline state needs applying. Occurs when beginning a new render pass. */
376 
377 /* Ignore full flag bit-mask `MTL_PIPELINE_STATE_ALL_FLAG`. */
379 
381  bool bound;
383 };
384 
387 
388  /* Whether the pipeline state has been modified since application.
389  * `dirty_flags` is a bitmask of the types of state which have been updated.
390  * This is in order to optimize calls and only re-apply state as needed.
391  * Some state parameters are dynamically applied on the RenderCommandEncoder,
392  * others may be encapsulated in GPU-resident state objects such as
393  * MTLDepthStencilState or MTLRenderPipelineState. */
394  bool dirty;
396 
397  /* Shader resources. */
398  MTLShader *null_shader;
399 
400  /* Active Shader State. */
401  MTLShader *active_shader;
402 
403  /* Global Uniform Buffers. */
405 
406  /* Context Texture bindings. */
409 
410  /*** --- Render Pipeline State --- ***/
411  /* Track global render pipeline state for the current context. The functions in GPU_state.h
412  * modify these parameters. Certain values, tagged [PSO], are parameters which are required to be
413  * passed into PSO creation, rather than dynamic state functions on the RenderCommandEncoder.
414  */
415 
416  /* Blending State. */
417  MTLColorWriteMask color_write_mask; /* [PSO] */
418  bool blending_enabled; /* [PSO] */
419  MTLBlendOperation alpha_blend_op; /* [PSO] */
420  MTLBlendOperation rgb_blend_op; /* [PSO] */
421  MTLBlendFactor dest_alpha_blend_factor; /* [PSO] */
422  MTLBlendFactor dest_rgb_blend_factor; /* [PSO] */
423  MTLBlendFactor src_alpha_blend_factor; /* [PSO] */
424  MTLBlendFactor src_rgb_blend_factor; /* [PSO] */
425 
426  /* Culling State. */
430 
431  /* Depth State. */
433 
434  /* Viewport/Scissor Region. */
444 
445  /* Image data access state. */
447 
448  /* Render parameters. */
449  float point_size = 1.0f;
450  float line_width = 1.0f;
451 };
452 
453 /* Command Buffer Manager - Owned by MTLContext.
454  * The MTLCommandBufferManager represents all work associated with
455  * a command buffer of a given identity. This manager is a fixed-state
456  * on the context, which coordinates the lifetime of command buffers
457  * for particular categories of work.
458  *
459  * This ensures operations on command buffers, and the state associated,
460  * is correctly tracked and managed. Workload submission and MTLCommandEncoder
461  * coordination is managed from here.
462  *
463  * There is currently only one MTLCommandBufferManager for managing submission
464  * of the "main" rendering commands. A secondary upload command buffer track,
465  * or asynchronous compute command buffer track may be added in the future. */
467  friend class MTLContext;
468 
469  public:
470  /* Event to coordinate sequential execution across all "main" command buffers. */
471  static id<MTLEvent> sync_event;
473 
474  /* Counter for active command buffers. */
476 
477  private:
478  /* Associated Context and properties. */
479  MTLContext &context_;
480  bool supports_render_ = false;
481 
482  /* CommandBuffer tracking. */
483  id<MTLCommandBuffer> active_command_buffer_ = nil;
484  id<MTLCommandBuffer> last_submitted_command_buffer_ = nil;
485 
486  /* Active MTLCommandEncoders. */
487  enum {
488  MTL_NO_COMMAND_ENCODER = 0,
489  MTL_RENDER_COMMAND_ENCODER = 1,
490  MTL_BLIT_COMMAND_ENCODER = 2,
491  MTL_COMPUTE_COMMAND_ENCODER = 3
492  } active_command_encoder_type_ = MTL_NO_COMMAND_ENCODER;
493 
494  id<MTLRenderCommandEncoder> active_render_command_encoder_ = nil;
495  id<MTLBlitCommandEncoder> active_blit_command_encoder_ = nil;
496  id<MTLComputeCommandEncoder> active_compute_command_encoder_ = nil;
497 
498  /* State associated with active RenderCommandEncoder. */
499  MTLRenderPassState render_pass_state_;
500  MTLFrameBuffer *active_frame_buffer_ = nullptr;
501  MTLRenderPassDescriptor *active_pass_descriptor_ = nullptr;
502 
503  /* Workload heuristics - We may need to split command buffers to optimize workload and balancing.
504  */
505  int current_draw_call_count_ = 0;
506  int encoder_count_ = 0;
507  int vertex_submitted_count_ = 0;
508  bool empty_ = true;
509 
510  public:
512  : context_(context), render_pass_state_(context, *this){};
513  void prepare(bool supports_render = true);
514 
515  /* If wait is true, CPU will stall until GPU work has completed. */
516  bool submit(bool wait);
517 
518  /* Fetch/query current encoder. */
519  bool is_inside_render_pass();
520  bool is_inside_blit();
521  bool is_inside_compute();
522  id<MTLRenderCommandEncoder> get_active_render_command_encoder();
523  id<MTLBlitCommandEncoder> get_active_blit_command_encoder();
524  id<MTLComputeCommandEncoder> get_active_compute_command_encoder();
526 
527  /* RenderPassState for RenderCommandEncoder. */
529  {
530  /* Render pass state should only be valid if we are inside a render pass. */
532  return render_pass_state_;
533  }
534 
535  /* Rendering Heuristics. */
536  void register_draw_counters(int vertex_submission);
537  void reset_counters();
538  bool do_break_submission();
539 
540  /* Encoder and Pass management. */
541  /* End currently active MTLCommandEncoder. */
543  id<MTLRenderCommandEncoder> ensure_begin_render_command_encoder(MTLFrameBuffer *ctx_framebuffer,
544  bool force_begin,
545  bool *new_pass);
546  id<MTLBlitCommandEncoder> ensure_begin_blit_encoder();
547  id<MTLComputeCommandEncoder> ensure_begin_compute_encoder();
548 
549  /* Workload Synchronization. */
550  bool insert_memory_barrier(eGPUBarrier barrier_bits,
551  eGPUStageBarrierBits before_stages,
552  eGPUStageBarrierBits after_stages);
553  /* TODO(Metal): Support fences in command buffer class. */
554 
555  /* Debug. */
556  void push_debug_group(const char *name, int index);
557  void pop_debug_group();
558 
559  private:
560  /* Begin new command buffer. */
561  id<MTLCommandBuffer> ensure_begin();
562 
563  void register_encoder_counters();
564 };
565 
567 /* NOTE(Metal): Partial MTLContext stub to provide wrapper functionality
568  * for work-in-progress MTL* classes. */
569 
570 class MTLContext : public Context {
571  friend class MTLBackend;
572 
573  private:
574  /* Compute and specialization caches. */
575  MTLContextTextureUtils texture_utils_;
576 
577  /* Texture Samplers. */
578  /* Cache of generated MTLSamplerState objects based on permutations of `eGPUSamplerState`. */
579  id<MTLSamplerState> sampler_state_cache_[GPU_SAMPLER_MAX];
580  id<MTLSamplerState> default_sampler_state_ = nil;
581 
582  /* When texture sampler count exceeds the resource bind limit, an
583  * argument buffer is used to pass samplers to the shader.
584  * Each unique configurations of multiple samplers can be cached, so as to not require
585  * re-generation. `samplers_` stores the current list of bound sampler objects.
586  * `cached_sampler_buffers_` is a cache of encoded argument buffers which can be re-used. */
587  MTLSamplerArray samplers_;
588  blender::Map<MTLSamplerArray, gpu::MTLBuffer *> cached_sampler_buffers_;
589 
590  /* Frame. */
591  bool is_inside_frame_ = false;
592  uint current_frame_index_;
593 
594  /* Visibility buffer for MTLQuery results. */
595  gpu::MTLBuffer *visibility_buffer_ = nullptr;
596  bool visibility_is_dirty_ = false;
597 
598  public:
599  /* Shaders and Pipeline state. */
601 
602  /* Metal API Resource Handles. */
603  id<MTLCommandQueue> queue = nil;
604  id<MTLDevice> device = nil;
605 
606  /* Memory Management */
609 
610  /* CommandBuffer managers. */
612 
613  /* GPUContext interface. */
614  MTLContext(void *ghost_window);
615  ~MTLContext();
616 
617  static void check_error(const char *info);
618 
619  void activate() override;
620  void deactivate() override;
621  void begin_frame() override;
622  void end_frame() override;
623 
624  void flush() override;
625  void finish() override;
626 
627  void memory_statistics_get(int *total_mem, int *free_mem) override;
628 
629  static MTLContext *get()
630  {
631  return static_cast<MTLContext *>(Context::get());
632  }
633 
634  void debug_group_begin(const char *name, int index) override;
635  void debug_group_end() override;
636 
637  /*** MTLContext Utility functions. */
638  /*
639  * All below functions modify the global state for the context, controlling the flow of
640  * rendering, binding resources, setting global state, resource management etc;
641  */
642 
645  /* Bind frame-buffer to context. */
646  void framebuffer_bind(MTLFrameBuffer *framebuffer);
647 
648  /* Restore frame-buffer used by active context to default back-buffer. */
649  void framebuffer_restore();
650 
651  /* Ensure a render-pass using the Context frame-buffer (active_fb_) is in progress. */
652  id<MTLRenderCommandEncoder> ensure_begin_render_pass();
653 
656 
657  /* Context Global-State Texture Binding. */
658  void texture_bind(gpu::MTLTexture *mtl_texture, uint texture_unit);
659  void sampler_bind(MTLSamplerState, uint sampler_unit);
660  void texture_unbind(gpu::MTLTexture *mtl_texture);
661  void texture_unbind_all();
662  id<MTLSamplerState> get_sampler_from_state(MTLSamplerState state);
664  id<MTLSamplerState> get_default_sampler_state();
665 
666  /* Metal Context pipeline state. */
667  void pipeline_state_init();
668  MTLShader *get_active_shader();
669 
670  /* State assignment. */
671  void set_viewport(int origin_x, int origin_y, int width, int height);
672  void set_scissor(int scissor_x, int scissor_y, int scissor_width, int scissor_height);
673  void set_scissor_enabled(bool scissor_enabled);
674 
675  /* Visibility buffer control. */
678 
679  /* Flag whether the visibility buffer for query results
680  * has changed. This requires a new RenderPass in order
681  * to update.*/
682  bool is_visibility_dirty() const;
683 
684  /* Reset dirty flag state for visibility buffer. */
685  void clear_visibility_dirty();
686 
687  /* Texture utilities. */
689  {
690  return texture_utils_;
691  }
692 
693  bool get_active()
694  {
695  return is_active_;
696  }
697 
699  {
700  return is_inside_frame_;
701  }
702 
704  {
705  return current_frame_index_;
706  }
707 
709  {
710  return this->memory_manager;
711  }
712 
714  {
716  }
717 };
718 
719 } // namespace blender::gpu
#define BLI_assert(a)
Definition: BLI_assert.h:46
unsigned int uint
Definition: BLI_sys_types.h:67
eGPUFrontFace
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
struct GPUShader GPUShader
Definition: GPU_shader.h:20
void GPU_shader_free(GPUShader *shader)
Definition: gpu_shader.cc:200
eGPUStageBarrierBits
Definition: GPU_state.h:40
eGPUFaceCullTest
Definition: GPU_state.h:107
eGPUBarrier
Definition: GPU_state.h:24
static const int GPU_SAMPLER_MAX
Definition: GPU_texture.h:52
Read Guarded memory(de)allocation.
static Context * get()
Definition: gpu_context.cc:82
id< MTLComputeCommandEncoder > get_active_compute_command_encoder()
MTLCommandBufferManager(MTLContext &context)
Definition: mtl_context.hh:511
void register_draw_counters(int vertex_submission)
void prepare(bool supports_render=true)
id< MTLRenderCommandEncoder > ensure_begin_render_command_encoder(MTLFrameBuffer *ctx_framebuffer, bool force_begin, bool *new_pass)
id< MTLComputeCommandEncoder > ensure_begin_compute_encoder()
bool insert_memory_barrier(eGPUBarrier barrier_bits, eGPUStageBarrierBits before_stages, eGPUStageBarrierBits after_stages)
id< MTLBlitCommandEncoder > ensure_begin_blit_encoder()
void push_debug_group(const char *name, int index)
id< MTLRenderCommandEncoder > get_active_render_command_encoder()
MTLRenderPassState & get_render_pass_state()
Definition: mtl_context.hh:528
id< MTLBlitCommandEncoder > get_active_blit_command_encoder()
MTLFrameBuffer * get_current_framebuffer()
Definition: mtl_context.mm:219
MTLFrameBuffer * get_default_framebuffer()
Definition: mtl_context.mm:225
id< MTLSamplerState > get_sampler_from_state(MTLSamplerState state)
Definition: mtl_context.mm:481
void deactivate() override
Definition: mtl_context.mm:129
gpu::MTLBuffer * get_visibility_buffer() const
Definition: mtl_context.mm:397
void set_visibility_buffer(gpu::MTLBuffer *buffer)
Definition: mtl_context.mm:379
void set_scissor_enabled(bool scissor_enabled)
Definition: mtl_context.mm:359
void framebuffer_bind(MTLFrameBuffer *framebuffer)
Definition: mtl_context.mm:150
id< MTLRenderCommandEncoder > ensure_begin_render_pass()
Definition: mtl_context.mm:164
void texture_bind(gpu::MTLTexture *mtl_texture, uint texture_unit)
Definition: mtl_context.mm:418
id< MTLSamplerState > generate_sampler_from_state(MTLSamplerState state)
Definition: mtl_context.mm:487
void finish() override
Definition: mtl_context.mm:138
void activate() override
Definition: mtl_context.mm:125
MTLScratchBufferManager memory_manager
Definition: mtl_context.hh:607
MTLContextGlobalShaderPipelineState pipeline_state
Definition: mtl_context.hh:600
void texture_unbind(gpu::MTLTexture *mtl_texture)
Definition: mtl_context.mm:452
void end_frame() override
Definition: mtl_context.mm:109
id< MTLDevice > device
Definition: mtl_context.hh:604
static MTLBufferPool global_memory_manager
Definition: mtl_context.hh:608
MTLShader * get_active_shader()
void set_viewport(int origin_x, int origin_y, int width, int height)
Definition: mtl_context.mm:318
void sampler_bind(MTLSamplerState, uint sampler_unit)
Definition: mtl_context.mm:438
void begin_frame() override
Definition: mtl_context.mm:98
MTLScratchBufferManager & get_scratchbuffer_manager()
Definition: mtl_context.hh:708
void flush() override
Definition: mtl_context.mm:134
void debug_group_begin(const char *name, int index) override
Definition: mtl_debug.mm:46
static void check_error(const char *info)
Definition: mtl_context.mm:120
void set_scissor(int scissor_x, int scissor_y, int scissor_width, int scissor_height)
Definition: mtl_context.mm:339
MTLCommandBufferManager main_command_buffer
Definition: mtl_context.hh:611
void debug_group_end() override
Definition: mtl_debug.mm:53
id< MTLSamplerState > get_default_sampler_state()
Definition: mtl_context.mm:538
bool is_visibility_dirty() const
Definition: mtl_context.mm:407
void memory_statistics_get(int *total_mem, int *free_mem) override
Definition: mtl_context.mm:143
id< MTLCommandQueue > queue
Definition: mtl_context.hh:603
MTLContextTextureUtils & get_texture_utils()
Definition: mtl_context.hh:688
static MTLContext * get()
Definition: mtl_context.hh:629
static MTLBufferPool & get_global_memory_manager()
Definition: mtl_context.hh:713
MTLContext(void *ghost_window)
Definition: mtl_context.mm:27
ccl_global float * buffer
const int state
#define T
#define MTL_MAX_SAMPLER_SLOTS
#define MTL_MAX_TEXTURE_SLOTS
#define MTL_MAX_UNIFORM_BUFFER_BINDINGS
ENUM_OPERATORS(MTLPipelineStateDirtyFlag, MTL_PIPELINE_STATE_CULLMODE_FLAG)
static int sampler_binding(int32_t program, uint32_t uniform_index, int32_t uniform_location, int *sampler_len)
@ MTL_PIPELINE_STATE_CULLMODE_FLAG
Definition: mtl_context.hh:369
@ MTL_PIPELINE_STATE_PSO_FLAG
Definition: mtl_context.hh:365
@ MTL_PIPELINE_STATE_SCISSOR_FLAG
Definition: mtl_context.hh:361
@ MTL_PIPELINE_STATE_FRONT_FACING_FLAG
Definition: mtl_context.hh:367
@ MTL_PIPELINE_STATE_DEPTHSTENCIL_FLAG
Definition: mtl_context.hh:363
@ MTL_PIPELINE_STATE_NULL_FLAG
Definition: mtl_context.hh:357
@ MTL_PIPELINE_STATE_VIEWPORT_FLAG
Definition: mtl_context.hh:359
@ MTL_PIPELINE_STATE_ALL_FLAG
Definition: mtl_context.hh:371
T length(const vec_base< T, Size > &a)
SocketIndexByIdentifierMap * map
unsigned int uint32_t
Definition: stdint.h:80
unsigned __int64 uint64_t
Definition: stdint.h:90
bool operator==(const MTLContextDepthStencilState &other) const
Definition: mtl_context.hh:180
MTLStencilOperation stencil_op_back_depthstencil_pass
Definition: mtl_context.hh:170
MTLStencilOperation stencil_op_back_stencil_fail
Definition: mtl_context.hh:168
MTLStencilOperation stencil_op_front_stencil_fail
Definition: mtl_context.hh:164
MTLStencilOperation stencil_op_front_depthstencil_pass
Definition: mtl_context.hh:166
MTLStencilOperation stencil_op_front_depth_fail
Definition: mtl_context.hh:165
MTLStencilOperation stencil_op_back_depth_fail
Definition: mtl_context.hh:169
MTLTextureBinding texture_bindings[MTL_MAX_TEXTURE_SLOTS]
Definition: mtl_context.hh:407
MTLContextDepthStencilState depth_stencil_state
Definition: mtl_context.hh:432
MTLSamplerBinding sampler_bindings[MTL_MAX_SAMPLER_SLOTS]
Definition: mtl_context.hh:408
MTLUniformBufferBinding ubo_bindings[MTL_MAX_UNIFORM_BUFFER_BINDINGS]
Definition: mtl_context.hh:404
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_1d_array_read_compute_psos
Definition: mtl_context.hh:258
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_cube_update_compute_psos
Definition: mtl_context.hh:283
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_3d_update_compute_psos
Definition: mtl_context.hh:281
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_1d_update_compute_psos
Definition: mtl_context.hh:273
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_3d_read_compute_psos
Definition: mtl_context.hh:264
void free_cached_pso_map(blender::Map< T, id< MTLComputePipelineState >> &map)
Definition: mtl_context.hh:289
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_cube_read_compute_psos
Definition: mtl_context.hh:266
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_1d_array_update_compute_psos
Definition: mtl_context.hh:275
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_1d_read_compute_psos
Definition: mtl_context.hh:256
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_buffer_read_compute_psos
Definition: mtl_context.hh:270
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_2d_array_update_compute_psos
Definition: mtl_context.hh:279
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_buffer_update_compute_psos
Definition: mtl_context.hh:287
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_2d_array_read_compute_psos
Definition: mtl_context.hh:262
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_2d_read_compute_psos
Definition: mtl_context.hh:260
blender::Map< DepthTextureUpdateRoutineSpecialisation, GPUShader * > depth_2d_update_shaders
Definition: mtl_context.hh:251
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_cube_array_update_compute_psos
Definition: mtl_context.hh:285
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_cube_array_read_compute_psos
Definition: mtl_context.hh:268
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_2d_update_compute_psos
Definition: mtl_context.hh:277
void set(MTLShader *shader, uint pso_index)
Definition: mtl_context.hh:77
MTLRenderPassState(MTLContext &context, MTLCommandBufferManager &command_buffer_manager)
Definition: mtl_context.hh:63
void bind_fragment_bytes(void *bytes, uint length, uint index)
void bind_fragment_sampler(MTLSamplerBinding &sampler_binding, bool use_argument_buffer_for_samplers, uint slot)
BufferBindingCached cached_vertex_buffer_bindings[MTL_MAX_UNIFORM_BUFFER_BINDINGS]
Definition: mtl_context.hh:99
SamplerStateBindingCached cached_fragment_sampler_state_bindings[MTL_MAX_TEXTURE_SLOTS]
Definition: mtl_context.hh:118
void bind_vertex_sampler(MTLSamplerBinding &sampler_binding, bool use_argument_buffer_for_samplers, uint slot)
void bind_vertex_texture(id< MTLTexture > tex, uint slot)
void bind_vertex_bytes(void *bytes, uint length, uint index)
BufferBindingCached cached_fragment_buffer_bindings[MTL_MAX_UNIFORM_BUFFER_BINDINGS]
Definition: mtl_context.hh:100
void bind_vertex_buffer(id< MTLBuffer > buffer, uint buffer_offset, uint index)
id< MTLDepthStencilState > bound_ds_state
Definition: mtl_context.hh:86
TextureBindingCached cached_vertex_texture_bindings[MTL_MAX_TEXTURE_SLOTS]
Definition: mtl_context.hh:107
SamplerStateBindingCached cached_vertex_sampler_state_bindings[MTL_MAX_TEXTURE_SLOTS]
Definition: mtl_context.hh:117
MTLCommandBufferManager & cmd
Definition: mtl_context.hh:69
void bind_fragment_buffer(id< MTLBuffer > buffer, uint buffer_offset, uint index)
id< MTLRenderPipelineState > bound_pso
Definition: mtl_context.hh:85
TextureBindingCached cached_fragment_texture_bindings[MTL_MAX_TEXTURE_SLOTS]
Definition: mtl_context.hh:108
MTLBoundShaderState last_bound_shader_state
Definition: mtl_context.hh:84
void bind_fragment_texture(id< MTLTexture > tex, uint slot)
MTLSamplerState mtl_sampler_flags[MTL_MAX_TEXTURE_SLOTS]
Definition: mtl_context.hh:333
bool operator==(const MTLSamplerArray &other) const
Definition: mtl_context.hh:336
id< MTLSamplerState > mtl_sampler[MTL_MAX_TEXTURE_SLOTS]
Definition: mtl_context.hh:334
bool operator==(MTLSamplerBinding const &other) const
Definition: mtl_context.hh:52
gpu::MTLTexture * texture_resource
Definition: mtl_context.hh:45