23 #include <Cocoa/Cocoa.h>
24 #include <Metal/Metal.h>
25 #include <QuartzCore/QuartzCore.h>
28 @class MTLCommandQueue;
29 @class MTLRenderPipelineState;
35 class MTLCommandBufferManager;
77 void set(MTLShader *shader,
uint pso_index)
129 bool use_argument_buffer_for_samplers,
132 bool use_argument_buffer_for_samplers,
187 bool stencil_state_equality =
true;
189 stencil_state_equality =
202 return depth_state_equality && stencil_state_equality;
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);
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);
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;
236 main_hash ^= (std::size_t)this->stencil_func << 16;
237 main_hash ^= stencilop_bitmask;
239 std::size_t final_hash = (main_hash << 8) | boolean_bitmask;
291 for (
typename blender::Map<
T, id<MTLComputePipelineState>>::MutableItem item :
map.items()) {
292 [item.value release];
341 return (memcmp(this->mtl_sampler_flags,
350 hash ^= (
uint32_t)this->mtl_sampler_flags[i] << (i % 3);
480 bool supports_render_ =
false;
483 id<MTLCommandBuffer> active_command_buffer_ = nil;
484 id<MTLCommandBuffer> last_submitted_command_buffer_ = nil;
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;
494 id<MTLRenderCommandEncoder> active_render_command_encoder_ = nil;
495 id<MTLBlitCommandEncoder> active_blit_command_encoder_ = nil;
496 id<MTLComputeCommandEncoder> active_compute_command_encoder_ = nil;
501 MTLRenderPassDescriptor *active_pass_descriptor_ =
nullptr;
505 int current_draw_call_count_ = 0;
506 int encoder_count_ = 0;
507 int vertex_submitted_count_ = 0;
513 void prepare(
bool supports_render =
true);
532 return render_pass_state_;
561 id<MTLCommandBuffer> ensure_begin();
563 void register_encoder_counters();
580 id<MTLSamplerState> default_sampler_state_ = nil;
591 bool is_inside_frame_ =
false;
592 uint current_frame_index_;
596 bool visibility_is_dirty_ =
false;
624 void flush()
override;
672 void set_scissor(
int scissor_x,
int scissor_y,
int scissor_width,
int scissor_height);
690 return texture_utils_;
700 return is_inside_frame_;
705 return current_frame_index_;
_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
void GPU_shader_free(GPUShader *shader)
static const int GPU_SAMPLER_MAX
Read Guarded memory(de)allocation.
MTLFrameBuffer * get_active_framebuffer()
id< MTLComputeCommandEncoder > get_active_compute_command_encoder()
MTLCommandBufferManager(MTLContext &context)
bool end_active_command_encoder()
bool do_break_submission()
void register_draw_counters(int vertex_submission)
void prepare(bool supports_render=true)
static uint64_t event_signal_val
bool is_inside_render_pass()
id< MTLRenderCommandEncoder > ensure_begin_render_command_encoder(MTLFrameBuffer *ctx_framebuffer, bool force_begin, bool *new_pass)
static id< MTLEvent > sync_event
id< MTLComputeCommandEncoder > ensure_begin_compute_encoder()
bool insert_memory_barrier(eGPUBarrier barrier_bits, eGPUStageBarrierBits before_stages, eGPUStageBarrierBits after_stages)
static int num_active_cmd_bufs
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()
id< MTLBlitCommandEncoder > get_active_blit_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
uint get_current_frame_index()
MTLShader * get_active_shader()
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()
MTLScratchBufferManager & get_scratchbuffer_manager()
void debug_group_begin(const char *name, int index) override
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
void debug_group_end() override
id< MTLSamplerState > get_default_sampler_state()
bool is_visibility_dirty() const
void memory_statistics_get(int *total_mem, int *free_mem) override
id< MTLCommandQueue > queue
MTLContextTextureUtils & get_texture_utils()
static MTLContext * get()
static MTLBufferPool & get_global_memory_manager()
MTLContext(void *ghost_window)
ccl_global float * buffer
#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)
MTLPipelineStateDirtyFlag
@ MTL_PIPELINE_STATE_CULLMODE_FLAG
@ MTL_PIPELINE_STATE_PSO_FLAG
@ MTL_PIPELINE_STATE_SCISSOR_FLAG
@ MTL_PIPELINE_STATE_FRONT_FACING_FLAG
@ MTL_PIPELINE_STATE_DEPTHSTENCIL_FLAG
@ MTL_PIPELINE_STATE_NULL_FLAG
@ MTL_PIPELINE_STATE_VIEWPORT_FLAG
@ MTL_PIPELINE_STATE_ALL_FLAG
T length(const vec_base< T, Size > &a)
SocketIndexByIdentifierMap * map
unsigned __int64 uint64_t
bool depth_bias_enabled_for_lines
MTLCompareFunction depth_function
bool operator==(const MTLContextDepthStencilState &other) const
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]
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_1d_array_read_compute_psos
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_cube_update_compute_psos
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_3d_update_compute_psos
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_1d_update_compute_psos
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_3d_read_compute_psos
GPUShader * fullscreen_blit_shader
void free_cached_pso_map(blender::Map< T, id< MTLComputePipelineState >> &map)
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_cube_read_compute_psos
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_1d_array_update_compute_psos
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_1d_read_compute_psos
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_buffer_read_compute_psos
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_2d_array_update_compute_psos
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_buffer_update_compute_psos
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_2d_array_read_compute_psos
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_2d_read_compute_psos
blender::Map< DepthTextureUpdateRoutineSpecialisation, GPUShader * > depth_2d_update_shaders
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_cube_array_update_compute_psos
blender::Map< TextureReadRoutineSpecialisation, id< MTLComputePipelineState > > texture_cube_array_read_compute_psos
blender::Map< TextureUpdateRoutineSpecialisation, id< MTLComputePipelineState > > texture_2d_update_compute_psos
id< MTLBuffer > metal_buffer
void set(MTLShader *shader, uint pso_index)
MTLSamplerState binding_state
bool is_arg_buffer_binding
id< MTLSamplerState > sampler_state
id< MTLTexture > metal_texture
MTLRenderPassState(MTLContext &context, MTLCommandBufferManager &command_buffer_manager)
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]
SamplerStateBindingCached cached_fragment_sampler_state_bindings[MTL_MAX_TEXTURE_SLOTS]
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]
void bind_vertex_buffer(id< MTLBuffer > buffer, uint buffer_offset, uint index)
id< MTLDepthStencilState > bound_ds_state
TextureBindingCached cached_vertex_texture_bindings[MTL_MAX_TEXTURE_SLOTS]
SamplerStateBindingCached cached_vertex_sampler_state_bindings[MTL_MAX_TEXTURE_SLOTS]
MTLScissorRect last_scissor_rect
uint last_used_stencil_ref_value
MTLCommandBufferManager & cmd
void bind_fragment_buffer(id< MTLBuffer > buffer, uint buffer_offset, uint index)
id< MTLRenderPipelineState > bound_pso
TextureBindingCached cached_fragment_texture_bindings[MTL_MAX_TEXTURE_SLOTS]
MTLBoundShaderState last_bound_shader_state
void bind_fragment_texture(id< MTLTexture > tex, uint slot)
MTLSamplerState mtl_sampler_flags[MTL_MAX_TEXTURE_SLOTS]
bool operator==(const MTLSamplerArray &other) const
id< MTLSamplerState > mtl_sampler[MTL_MAX_TEXTURE_SLOTS]
bool operator==(MTLSamplerBinding const &other) const
gpu::MTLTexture * texture_resource