36 is_inside_frame_ =
false;
37 current_frame_index_ = 0;
47 MTLBackend::platform_init(
this);
48 MTLBackend::capabilities_init(
this);
91 if (sampler_state_cache_[i] != nil) {
92 [sampler_state_cache_[i] release];
93 sampler_state_cache_[i] = nil;
106 is_inside_frame_ =
true;
117 is_inside_frame_ =
false;
175 BLI_assert(
false &&
"No framebuffer is bound!");
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()) {
196 MTL_LOG_WARNING(
"Framebuffer validation failed, falling back to default framebuffer\n");
200 MTL_LOG_ERROR(
"CRITICAL: DEFAULT FRAMEBUFFER FAIL VALIDATION!!\n");
205 bool new_render_pass =
false;
206 id<MTLRenderCommandEncoder> new_enc =
209 if (new_render_pass) {
262 MTLColorWriteMaskBlue | MTLColorWriteMaskAlpha;
311 MTLStencilOperationKeep;
315 MTLStencilOperationKeep;
385 visibility_is_dirty_ = (
buffer != visibility_buffer_) || visibility_is_dirty_;
386 visibility_buffer_ =
buffer;
392 visibility_is_dirty_ = (visibility_buffer_ !=
nullptr) || visibility_is_dirty_;
393 visibility_buffer_ =
nullptr;
399 return visibility_buffer_;
404 visibility_is_dirty_ =
false;
409 return visibility_is_dirty_;
425 MTL_LOG_WARNING(
"Attempting to bind texture '%s' to invalid texture unit %d\n",
435 mtl_texture->is_bound_ =
true;
443 MTL_LOG_WARNING(
"Attempting to bind sampler to invalid sampler unit %d\n", sampler_unit);
465 mtl_texture->is_bound_ =
false;
473 this->pipeline_state.texture_bindings[
t].texture_resource) {
484 return sampler_state_cache_[(
uint)sampler_state];
490 id<MTLSamplerState>
st = sampler_state_cache_[(
uint)sampler_state];
495 MTLSamplerDescriptor *
descriptor = [[MTLSamplerDescriptor alloc]
init];
499 MTLSamplerAddressModeClampToBorderColor :
500 MTLSamplerAddressModeClampToEdge;
502 MTLSamplerAddressModeRepeat :
505 MTLSamplerAddressModeRepeat :
508 MTLSamplerAddressModeRepeat :
510 descriptor.borderColor = MTLSamplerBorderColorTransparentBlack;
512 MTLSamplerMinMagFilterLinear :
513 MTLSamplerMinMagFilterNearest;
515 MTLSamplerMinMagFilterLinear :
516 MTLSamplerMinMagFilterNearest;
518 MTLSamplerMipFilterLinear :
519 MTLSamplerMipFilterNotMipmapped;
522 float aniso_filter =
max_ff(16,
U.anisotropic_filter);
525 MTLCompareFunctionLessEqual :
526 MTLCompareFunctionAlways;
530 sampler_state_cache_[(
uint)sampler_state] =
state;
540 if (default_sampler_state_ == nil) {
543 return default_sampler_state_;
MINLINE uint min_uu(uint a, uint b)
MINLINE float max_ff(float a, float b)
int GPU_max_textures(void)
GPUContext * GPU_context_active_get(void)
_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_SAMPLER_CLAMP_BORDER
static const int GPU_SAMPLER_MAX
StateManager * state_manager
static MTLBackend * get()
void init(id< MTLDevice > device)
MTLFrameBuffer * get_active_framebuffer()
bool do_break_submission()
void prepare(bool supports_render=true)
bool is_inside_render_pass()
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()
MTLFrameBuffer * get_default_framebuffer()
void clear_visibility_dirty()
id< MTLSamplerState > get_sampler_from_state(MTLSamplerState state)
void deactivate() override
gpu::MTLBuffer * get_visibility_buffer() const
void set_visibility_buffer(gpu::MTLBuffer *buffer)
void set_scissor_enabled(bool scissor_enabled)
void framebuffer_bind(MTLFrameBuffer *framebuffer)
id< MTLRenderCommandEncoder > ensure_begin_render_pass()
void texture_bind(gpu::MTLTexture *mtl_texture, uint texture_unit)
id< MTLSamplerState > generate_sampler_from_state(MTLSamplerState state)
MTLScratchBufferManager memory_manager
void pipeline_state_init()
void texture_unbind_all()
MTLContextGlobalShaderPipelineState pipeline_state
void texture_unbind(gpu::MTLTexture *mtl_texture)
void end_frame() override
static MTLBufferPool global_memory_manager
void set_viewport(int origin_x, int origin_y, int width, int height)
void sampler_bind(MTLSamplerState, uint sampler_unit)
void begin_frame() override
void framebuffer_restore()
static void check_error(const char *info)
void set_scissor(int scissor_x, int scissor_y, int scissor_width, int scissor_height)
MTLCommandBufferManager main_command_buffer
id< MTLSamplerState > get_default_sampler_state()
bool is_visibility_dirty() const
void memory_statistics_get(int *total_mem, int *free_mem) override
MTLContextTextureUtils & get_texture_utils()
MTLContext(void *ghost_window)
ccl_global float * buffer
#define MTL_MAX_SAMPLER_SLOTS
#define MTL_MAX_TEXTURE_SLOTS
#define MTL_MAX_UNIFORM_BUFFER_BINDINGS
#define MTL_LOG_WARNING(info,...)
#define MTL_LOG_ERROR(info,...)
const MTLSamplerState DEFAULT_SAMPLER_STATE
@ MTL_PIPELINE_STATE_SCISSOR_FLAG
@ MTL_PIPELINE_STATE_VIEWPORT_FLAG
@ MTL_PIPELINE_STATE_ALL_FLAG
static const pxr::TfToken st("st", pxr::TfToken::Immortal)
bool depth_bias_enabled_for_lines
MTLCompareFunction depth_function
MTLStencilOperation stencil_op_back_depthstencil_pass
MTLCompareFunction stencil_func
MTLStencilOperation stencil_op_back_stencil_fail
MTLStencilOperation stencil_op_front_stencil_fail
bool depth_bias_enabled_for_tris
MTLStencilOperation stencil_op_front_depthstencil_pass
MTLStencilOperation stencil_op_front_depth_fail
MTLStencilOperation stencil_op_back_depth_fail
bool depth_bias_enabled_for_points
bool stencil_test_enabled
MTLColorWriteMask color_write_mask
MTLBlendFactor src_rgb_blend_factor
MTLBlendOperation alpha_blend_op
MTLBlendFactor src_alpha_blend_factor
MTLTextureBinding texture_bindings[MTL_MAX_TEXTURE_SLOTS]
MTLShader * active_shader
MTLPipelineStateDirtyFlag dirty_flags
MTLBlendFactor dest_alpha_blend_factor
MTLContextDepthStencilState depth_stencil_state
MTLSamplerBinding sampler_bindings[MTL_MAX_SAMPLER_SLOTS]
MTLBlendOperation rgb_blend_op
MTLBlendFactor dest_rgb_blend_factor
eGPUFaceCullTest cull_mode
MTLUniformBufferBinding ubo_bindings[MTL_MAX_UNIFORM_BUFFER_BINDINGS]
MTLSamplerState mtl_sampler_flags[MTL_MAX_TEXTURE_SLOTS]
id< MTLSamplerState > mtl_sampler[MTL_MAX_TEXTURE_SLOTS]
gpu::MTLTexture * texture_resource