Blender  V3.3
mtl_context.mm
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
6 #include "mtl_context.hh"
7 #include "mtl_debug.hh"
8 #include "mtl_state.hh"
9 
10 #include "DNA_userdef_types.h"
11 
12 #include "GPU_capabilities.h"
13 
14 using namespace blender;
15 using namespace blender::gpu;
16 
17 namespace blender::gpu {
18 
19 /* Global memory manager. */
21 
22 /* -------------------------------------------------------------------- */
26 /* Placeholder functions */
27 MTLContext::MTLContext(void *ghost_window) : memory_manager(*this), main_command_buffer(*this)
28 {
29  /* Init debug. */
31 
32  /* Initialize command buffer state. */
34 
35  /* Frame management. */
36  is_inside_frame_ = false;
37  current_frame_index_ = 0;
38 
39  /* Create FrameBuffer handles. */
40  MTLFrameBuffer *mtl_front_left = new MTLFrameBuffer(this, "front_left");
41  MTLFrameBuffer *mtl_back_left = new MTLFrameBuffer(this, "back_left");
42  this->front_left = mtl_front_left;
43  this->back_left = mtl_back_left;
44  this->active_fb = this->back_left;
45  /* Prepare platform and capabilities. (NOTE: With METAL, this needs to be done after CTX
46  * initialization). */
47  MTLBackend::platform_init(this);
48  MTLBackend::capabilities_init(this);
49 
50  /* Initialize Metal modules. */
51  this->memory_manager.init();
52  this->state_manager = new MTLStateManager(this);
53 
54  /* Ensure global memory manager is initialized. */
56 
57  /* Initialize texture read/update structures. */
58  this->get_texture_utils().init();
59 
60  /* Bound Samplers struct. */
61  for (int i = 0; i < MTL_MAX_TEXTURE_SLOTS; i++) {
62  samplers_.mtl_sampler[i] = nil;
64  }
65 
66  /* Initialize samplers. */
67  for (uint i = 0; i < GPU_SAMPLER_MAX; i++) {
69  state.state = static_cast<eGPUSamplerState>(i);
70  sampler_state_cache_[i] = this->generate_sampler_from_state(state);
71  }
72 }
73 
75 {
76  BLI_assert(this == reinterpret_cast<MTLContext *>(GPU_context_active_get()));
77  /* Ensure rendering is complete command encoders/command buffers are freed. */
78  if (MTLBackend::get()->is_inside_render_boundary()) {
79  this->finish();
80 
81  /* End frame. */
82  if (this->get_inside_frame()) {
83  this->end_frame();
84  }
85  }
86  /* Release update/blit shaders. */
87  this->get_texture_utils().cleanup();
88 
89  /* Release Sampler States. */
90  for (int i = 0; i < GPU_SAMPLER_MAX; i++) {
91  if (sampler_state_cache_[i] != nil) {
92  [sampler_state_cache_[i] release];
93  sampler_state_cache_[i] = nil;
94  }
95  }
96 }
97 
99 {
100  BLI_assert(MTLBackend::get()->is_inside_render_boundary());
101  if (this->get_inside_frame()) {
102  return;
103  }
104 
105  /* Begin Command buffer for next frame. */
106  is_inside_frame_ = true;
107 }
108 
110 {
111  BLI_assert(this->get_inside_frame());
112 
113  /* Ensure pre-present work is committed. */
114  this->flush();
115 
116  /* Increment frame counter. */
117  is_inside_frame_ = false;
118 }
119 
120 void MTLContext::check_error(const char *info)
121 {
122  /* TODO(Metal): Implement. */
123 }
124 
126 {
127  /* TODO(Metal): Implement. */
128 }
130 {
131  /* TODO(Metal): Implement. */
132 }
133 
135 {
136  /* TODO(Metal): Implement. */
137 }
139 {
140  /* TODO(Metal): Implement. */
141 }
142 
143 void MTLContext::memory_statistics_get(int *total_mem, int *free_mem)
144 {
145  /* TODO(Metal): Implement. */
146  *total_mem = 0;
147  *free_mem = 0;
148 }
149 
151 {
152  /* We do not yet begin the pass -- We defer beginning the pass until a draw is requested. */
153  BLI_assert(framebuffer);
154  this->active_fb = framebuffer;
155 }
156 
158 {
159  /* Bind default framebuffer from context --
160  * We defer beginning the pass until a draw is requested. */
161  this->active_fb = this->back_left;
162 }
163 
164 id<MTLRenderCommandEncoder> MTLContext::ensure_begin_render_pass()
165 {
166  BLI_assert(this);
167 
168  /* Ensure the rendering frame has started. */
169  if (!this->get_inside_frame()) {
170  this->begin_frame();
171  }
172 
173  /* Check whether a framebuffer is bound. */
174  if (!this->active_fb) {
175  BLI_assert(false && "No framebuffer is bound!");
177  }
178 
179  /* Ensure command buffer workload submissions are optimal --
180  * Though do not split a batch mid-IMM recording */
181  /* TODO(Metal): Add IMM Check once MTLImmediate has been implemented. */
183  !((MTLImmediate *)(this->imm))->imm_is_recording()*/) {
184  this->flush();
185  }
186 
187  /* Begin pass or perform a pass switch if the active framebuffer has been changed, or if the
188  * framebuffer state has been modified (is_dirty). */
190  this->active_fb != this->main_command_buffer.get_active_framebuffer() ||
191  this->main_command_buffer.get_active_framebuffer()->get_dirty() ||
192  this->is_visibility_dirty()) {
193 
194  /* Validate bound framebuffer before beginning render pass. */
195  if (!static_cast<MTLFrameBuffer *>(this->active_fb)->validate_render_pass()) {
196  MTL_LOG_WARNING("Framebuffer validation failed, falling back to default framebuffer\n");
197  this->framebuffer_restore();
198 
199  if (!static_cast<MTLFrameBuffer *>(this->active_fb)->validate_render_pass()) {
200  MTL_LOG_ERROR("CRITICAL: DEFAULT FRAMEBUFFER FAIL VALIDATION!!\n");
201  }
202  }
203 
204  /* Begin RenderCommandEncoder on main CommandBuffer. */
205  bool new_render_pass = false;
206  id<MTLRenderCommandEncoder> new_enc =
208  static_cast<MTLFrameBuffer *>(this->active_fb), true, &new_render_pass);
209  if (new_render_pass) {
210  /* Flag context pipeline state as dirty - dynamic pipeline state need re-applying. */
212  }
213  return new_enc;
214  }
217 }
218 
220 {
221  MTLFrameBuffer *last_bound = static_cast<MTLFrameBuffer *>(this->active_fb);
222  return last_bound ? last_bound : this->get_default_framebuffer();
223 }
224 
226 {
227  return static_cast<MTLFrameBuffer *>(this->back_left);
228 }
229 
232 /* -------------------------------------------------------------------- */
236 /* Metal Context Pipeline State. */
238 {
239  /*** Initialize state only once. ***/
240  if (!this->pipeline_state.initialised) {
241  this->pipeline_state.initialised = true;
243 
244  /* Clear bindings state. */
245  for (int t = 0; t < GPU_max_textures(); t++) {
246  this->pipeline_state.texture_bindings[t].used = false;
249  }
250  for (int s = 0; s < MTL_MAX_SAMPLER_SLOTS; s++) {
251  this->pipeline_state.sampler_bindings[s].used = false;
252  }
253  for (int u = 0; u < MTL_MAX_UNIFORM_BUFFER_BINDINGS; u++) {
254  this->pipeline_state.ubo_bindings[u].bound = false;
255  this->pipeline_state.ubo_bindings[u].ubo = NULL;
256  }
257  }
258 
259  /*** State defaults -- restored by GPU_state_init. ***/
260  /* Clear blending State. */
261  this->pipeline_state.color_write_mask = MTLColorWriteMaskRed | MTLColorWriteMaskGreen |
262  MTLColorWriteMaskBlue | MTLColorWriteMaskAlpha;
263  this->pipeline_state.blending_enabled = false;
264  this->pipeline_state.alpha_blend_op = MTLBlendOperationAdd;
265  this->pipeline_state.rgb_blend_op = MTLBlendOperationAdd;
266  this->pipeline_state.dest_alpha_blend_factor = MTLBlendFactorZero;
267  this->pipeline_state.dest_rgb_blend_factor = MTLBlendFactorZero;
268  this->pipeline_state.src_alpha_blend_factor = MTLBlendFactorOne;
269  this->pipeline_state.src_rgb_blend_factor = MTLBlendFactorOne;
270 
271  /* Viewport and scissor. */
274  this->pipeline_state.viewport_width = 0;
276  this->pipeline_state.scissor_x = 0;
277  this->pipeline_state.scissor_y = 0;
278  this->pipeline_state.scissor_width = 0;
279  this->pipeline_state.scissor_height = 0;
280  this->pipeline_state.scissor_enabled = false;
281 
282  /* Culling State. */
283  this->pipeline_state.culling_enabled = false;
286 
287  /* DATA and IMAGE access state. */
289 
290  /* Depth State. */
295  this->pipeline_state.depth_stencil_state.depth_function = MTLCompareFunctionAlways;
301 
302  /* Stencil State. */
307  this->pipeline_state.depth_stencil_state.stencil_func = MTLCompareFunctionAlways;
308  this->pipeline_state.depth_stencil_state.stencil_op_front_stencil_fail = MTLStencilOperationKeep;
309  this->pipeline_state.depth_stencil_state.stencil_op_front_depth_fail = MTLStencilOperationKeep;
311  MTLStencilOperationKeep;
312  this->pipeline_state.depth_stencil_state.stencil_op_back_stencil_fail = MTLStencilOperationKeep;
313  this->pipeline_state.depth_stencil_state.stencil_op_back_depth_fail = MTLStencilOperationKeep;
315  MTLStencilOperationKeep;
316 }
317 
318 void MTLContext::set_viewport(int origin_x, int origin_y, int width, int height)
319 {
320  BLI_assert(this);
321  BLI_assert(width > 0);
322  BLI_assert(height > 0);
323  BLI_assert(origin_x >= 0);
324  BLI_assert(origin_y >= 0);
325  bool changed = (this->pipeline_state.viewport_offset_x != origin_x) ||
326  (this->pipeline_state.viewport_offset_y != origin_y) ||
327  (this->pipeline_state.viewport_width != width) ||
328  (this->pipeline_state.viewport_height != height);
329  this->pipeline_state.viewport_offset_x = origin_x;
330  this->pipeline_state.viewport_offset_y = origin_y;
333  if (changed) {
336  }
337 }
338 
339 void MTLContext::set_scissor(int scissor_x, int scissor_y, int scissor_width, int scissor_height)
340 {
341  BLI_assert(this);
342  bool changed = (this->pipeline_state.scissor_x != scissor_x) ||
343  (this->pipeline_state.scissor_y != scissor_y) ||
344  (this->pipeline_state.scissor_width != scissor_width) ||
345  (this->pipeline_state.scissor_height != scissor_height) ||
346  (this->pipeline_state.scissor_enabled != true);
347  this->pipeline_state.scissor_x = scissor_x;
348  this->pipeline_state.scissor_y = scissor_y;
349  this->pipeline_state.scissor_width = scissor_width;
350  this->pipeline_state.scissor_height = scissor_height;
351  this->pipeline_state.scissor_enabled = (scissor_width > 0 && scissor_height > 0);
352 
353  if (changed) {
356  }
357 }
358 
359 void MTLContext::set_scissor_enabled(bool scissor_enabled)
360 {
361  /* Only turn on Scissor if requested scissor region is valid */
362  scissor_enabled = scissor_enabled && (this->pipeline_state.scissor_width > 0 &&
363  this->pipeline_state.scissor_height > 0);
364 
365  bool changed = (this->pipeline_state.scissor_enabled != scissor_enabled);
366  this->pipeline_state.scissor_enabled = scissor_enabled;
367  if (changed) {
370  }
371 }
372 
375 /* -------------------------------------------------------------------- */
380 {
381  /* Flag visibility buffer as dirty if the buffer being used for visibility has changed --
382  * This is required by the render pass, and we will break the pass if the results destination
383  * buffer is modified. */
384  if (buffer) {
385  visibility_is_dirty_ = (buffer != visibility_buffer_) || visibility_is_dirty_;
386  visibility_buffer_ = buffer;
387  visibility_buffer_->debug_ensure_used();
388  }
389  else {
390  /* If buffer is null, reset visibility state, mark dirty to break render pass if results are no
391  * longer needed. */
392  visibility_is_dirty_ = (visibility_buffer_ != nullptr) || visibility_is_dirty_;
393  visibility_buffer_ = nullptr;
394  }
395 }
396 
398 {
399  return visibility_buffer_;
400 }
401 
403 {
404  visibility_is_dirty_ = false;
405 }
406 
408 {
409  return visibility_is_dirty_;
410 }
411 
414 /* -------------------------------------------------------------------- */
418 void MTLContext::texture_bind(gpu::MTLTexture *mtl_texture, uint texture_unit)
419 {
420  BLI_assert(this);
421  BLI_assert(mtl_texture);
422 
423  if (texture_unit < 0 || texture_unit >= GPU_max_textures() ||
424  texture_unit >= MTL_MAX_TEXTURE_SLOTS) {
425  MTL_LOG_WARNING("Attempting to bind texture '%s' to invalid texture unit %d\n",
426  mtl_texture->get_name(),
427  texture_unit);
428  BLI_assert(false);
429  return;
430  }
431 
432  /* Bind new texture. */
433  this->pipeline_state.texture_bindings[texture_unit].texture_resource = mtl_texture;
434  this->pipeline_state.texture_bindings[texture_unit].used = true;
435  mtl_texture->is_bound_ = true;
436 }
437 
438 void MTLContext::sampler_bind(MTLSamplerState sampler_state, uint sampler_unit)
439 {
440  BLI_assert(this);
441  if (sampler_unit < 0 || sampler_unit >= GPU_max_textures() ||
442  sampler_unit >= MTL_MAX_SAMPLER_SLOTS) {
443  MTL_LOG_WARNING("Attempting to bind sampler to invalid sampler unit %d\n", sampler_unit);
444  BLI_assert(false);
445  return;
446  }
447 
448  /* Apply binding. */
449  this->pipeline_state.sampler_bindings[sampler_unit] = {true, sampler_state};
450 }
451 
453 {
454  BLI_assert(mtl_texture);
455 
456  /* Iterate through textures in state and unbind. */
457  for (int i = 0; i < min_uu(GPU_max_textures(), MTL_MAX_TEXTURE_SLOTS); i++) {
458  if (this->pipeline_state.texture_bindings[i].texture_resource == mtl_texture) {
460  this->pipeline_state.texture_bindings[i].used = false;
461  }
462  }
463 
464  /* Locally unbind texture. */
465  mtl_texture->is_bound_ = false;
466 }
467 
469 {
470  /* Iterate through context's bound textures. */
471  for (int t = 0; t < min_uu(GPU_max_textures(), MTL_MAX_TEXTURE_SLOTS); t++) {
472  if (this->pipeline_state.texture_bindings[t].used &&
473  this->pipeline_state.texture_bindings[t].texture_resource) {
474 
475  this->pipeline_state.texture_bindings[t].used = false;
477  }
478  }
479 }
480 
481 id<MTLSamplerState> MTLContext::get_sampler_from_state(MTLSamplerState sampler_state)
482 {
483  BLI_assert((uint)sampler_state >= 0 && ((uint)sampler_state) < GPU_SAMPLER_MAX);
484  return sampler_state_cache_[(uint)sampler_state];
485 }
486 
488 {
489  /* Check if sampler already exists for given state. */
490  id<MTLSamplerState> st = sampler_state_cache_[(uint)sampler_state];
491  if (st != nil) {
492  return st;
493  }
494  else {
495  MTLSamplerDescriptor *descriptor = [[MTLSamplerDescriptor alloc] init];
496  descriptor.normalizedCoordinates = true;
497 
498  MTLSamplerAddressMode clamp_type = (sampler_state.state & GPU_SAMPLER_CLAMP_BORDER) ?
499  MTLSamplerAddressModeClampToBorderColor :
500  MTLSamplerAddressModeClampToEdge;
501  descriptor.rAddressMode = (sampler_state.state & GPU_SAMPLER_REPEAT_R) ?
502  MTLSamplerAddressModeRepeat :
503  clamp_type;
504  descriptor.sAddressMode = (sampler_state.state & GPU_SAMPLER_REPEAT_S) ?
505  MTLSamplerAddressModeRepeat :
506  clamp_type;
507  descriptor.tAddressMode = (sampler_state.state & GPU_SAMPLER_REPEAT_T) ?
508  MTLSamplerAddressModeRepeat :
509  clamp_type;
510  descriptor.borderColor = MTLSamplerBorderColorTransparentBlack;
511  descriptor.minFilter = (sampler_state.state & GPU_SAMPLER_FILTER) ?
512  MTLSamplerMinMagFilterLinear :
513  MTLSamplerMinMagFilterNearest;
514  descriptor.magFilter = (sampler_state.state & GPU_SAMPLER_FILTER) ?
515  MTLSamplerMinMagFilterLinear :
516  MTLSamplerMinMagFilterNearest;
517  descriptor.mipFilter = (sampler_state.state & GPU_SAMPLER_MIPMAP) ?
518  MTLSamplerMipFilterLinear :
519  MTLSamplerMipFilterNotMipmapped;
520  descriptor.lodMinClamp = -1000;
521  descriptor.lodMaxClamp = 1000;
522  float aniso_filter = max_ff(16, U.anisotropic_filter);
523  descriptor.maxAnisotropy = (sampler_state.state & GPU_SAMPLER_MIPMAP) ? aniso_filter : 1;
524  descriptor.compareFunction = (sampler_state.state & GPU_SAMPLER_COMPARE) ?
525  MTLCompareFunctionLessEqual :
526  MTLCompareFunctionAlways;
527  descriptor.supportArgumentBuffers = true;
528 
529  id<MTLSamplerState> state = [this->device newSamplerStateWithDescriptor:descriptor];
530  sampler_state_cache_[(uint)sampler_state] = state;
531 
532  BLI_assert(state != nil);
533  [descriptor autorelease];
534  return state;
535  }
536 }
537 
539 {
540  if (default_sampler_state_ == nil) {
541  default_sampler_state_ = this->get_sampler_from_state(DEFAULT_SAMPLER_STATE);
542  }
543  return default_sampler_state_;
544 }
545 
548 } // blender::gpu
#define BLI_assert(a)
Definition: BLI_assert.h:46
MINLINE uint min_uu(uint a, uint b)
MINLINE float max_ff(float a, float b)
unsigned int uint
Definition: BLI_sys_types.h:67
int GPU_max_textures(void)
@ GPU_COUNTERCLOCKWISE
GPUContext * GPU_context_active_get(void)
Definition: gpu_context.cc:142
_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
_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 GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
@ GPU_CULL_NONE
Definition: GPU_state.h:108
eGPUSamplerState
Definition: GPU_texture.h:25
@ GPU_SAMPLER_REPEAT_S
Definition: GPU_texture.h:29
@ GPU_SAMPLER_MIPMAP
Definition: GPU_texture.h:28
@ GPU_SAMPLER_FILTER
Definition: GPU_texture.h:27
@ GPU_SAMPLER_COMPARE
Definition: GPU_texture.h:33
@ GPU_SAMPLER_REPEAT_T
Definition: GPU_texture.h:30
@ GPU_SAMPLER_CLAMP_BORDER
Definition: GPU_texture.h:32
@ GPU_SAMPLER_REPEAT_R
Definition: GPU_texture.h:31
static const int GPU_SAMPLER_MAX
Definition: GPU_texture.h:52
unsigned int U
Definition: btGjkEpa3.h:78
static MTLBackend * get()
Definition: mtl_backend.hh:49
void init(id< MTLDevice > device)
Definition: mtl_memory.mm:19
void prepare(bool supports_render=true)
id< MTLRenderCommandEncoder > ensure_begin_render_command_encoder(MTLFrameBuffer *ctx_framebuffer, bool force_begin, bool *new_pass)
id< MTLRenderCommandEncoder > get_active_render_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
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
void flush() override
Definition: mtl_context.mm:134
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
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
MTLContextTextureUtils & get_texture_utils()
Definition: mtl_context.hh:688
MTLContext(void *ghost_window)
Definition: mtl_context.mm:27
const char * get_name()
Definition: mtl_texture.hh:254
ccl_global float * buffer
const int state
descriptor
Definition: logImageCore.h:144
#define MTL_MAX_SAMPLER_SLOTS
#define MTL_MAX_TEXTURE_SLOTS
#define MTL_MAX_UNIFORM_BUFFER_BINDINGS
#define MTL_LOG_WARNING(info,...)
Definition: mtl_debug.hh:36
#define MTL_LOG_ERROR(info,...)
Definition: mtl_debug.hh:24
const MTLSamplerState DEFAULT_SAMPLER_STATE
Definition: mtl_texture.hh:150
@ MTL_PIPELINE_STATE_SCISSOR_FLAG
Definition: mtl_context.hh:361
@ MTL_PIPELINE_STATE_VIEWPORT_FLAG
Definition: mtl_context.hh:359
@ MTL_PIPELINE_STATE_ALL_FLAG
Definition: mtl_context.hh:371
static const pxr::TfToken st("st", pxr::TfToken::Immortal)
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
MTLSamplerState mtl_sampler_flags[MTL_MAX_TEXTURE_SLOTS]
Definition: mtl_context.hh:333
id< MTLSamplerState > mtl_sampler[MTL_MAX_TEXTURE_SLOTS]
Definition: mtl_context.hh:334
gpu::MTLTexture * texture_resource
Definition: mtl_context.hh:45