35 storage_source_ = MTL_STORAGE_BUF_TYPE_DEFAULT;
43 storage_source_ = MTL_STORAGE_BUF_TYPE_UNIFORMBUF;
52 storage_source_ = MTL_STORAGE_BUF_TYPE_VERTBUF;
61 storage_source_ = MTL_STORAGE_BUF_TYPE_INDEXBUF;
70 storage_source_ = MTL_STORAGE_BUF_TYPE_TEXTURE;
77 if (storage_source_ == MTL_STORAGE_BUF_TYPE_DEFAULT) {
85 if (gpu_write_fence_ != nil) {
86 [gpu_write_fence_ release];
87 gpu_write_fence_ = nil;
114 if (storage_source_ != MTL_STORAGE_BUF_TYPE_DEFAULT) {
141 if (storage_source_ != MTL_STORAGE_BUF_TYPE_DEFAULT) {
148 bool do_upload_data = (data !=
nullptr);
152 if (!device_only && do_upload_data) {
165 if (do_upload_data) {
184 id<MTLBlitCommandEncoder> blit_encoder =
186 [blit_encoder copyFromBuffer:staging_buf_mtl
217 "Error: Trying to bind \"%s\" ssbo to slot %d which is above the reported limit of %d.\n",
229 if (
data_ !=
nullptr) {
239 ctx_ssbo_bind_slot.
ssbo =
this;
240 ctx_ssbo_bind_slot.
bound =
true;
256 if (bound_ctx_ !=
nullptr && bind_slot_ > -1) {
259 if (ctx_ssbo_bind_slot.
bound && ctx_ssbo_bind_slot.
ssbo ==
this) {
260 ctx_ssbo_bind_slot.
bound =
false;
261 ctx_ssbo_bind_slot.
ssbo =
nullptr;
268 bound_ctx_ =
nullptr;
275 BLI_assert_msg(ctx,
"Clears should always be performed while a valid context exists.");
283 uint clear_byte = clear_value & 0xFF;
284 bool clear_value_bytes_equal = (clear_byte == ((clear_value >> 8) & 0xFF)) &&
285 (clear_byte == ((clear_value >> 16) & 0xFF)) &&
286 (clear_byte == ((clear_value >> 24) & 0xFF));
287 if (clear_value_bytes_equal) {
288 id<MTLBlitCommandEncoder> blit_encoder =
297 id<MTLComputeCommandEncoder> compute_encoder =
305 threadsPerThreadgroup:MTLSizeMake(128, 1, 1)];
318 if (copy_size == 0) {
321 if (src->vbo_ ==
nullptr) {
336 [blit_encoder copyFromBuffer:src_buf
337 sourceOffset:src_offset
339 destinationOffset:dst_offset
347 "Storage buffers with usage GPU_USAGE_DEVICE_ONLY cannot have their data "
348 "synchronized to the host.");
356 if (gpu_write_fence_ == nil) {
357 gpu_write_fence_ = [ctx->
device newSharedEvent];
366 if (storage_buf_mtl.storageMode == MTLStorageModeManaged) {
368 [blit_encoder synchronizeResource:storage_buf_mtl];
379 if (data ==
nullptr) {
407 [blit_encoder copyFromBuffer:storage_buf_mtl
409 toBuffer:staging_buf_mtl
412 if (staging_buf_mtl.storageMode == MTLStorageModeManaged) {
413 [blit_encoder synchronizeResource:staging_buf_mtl];
419 "Device-only storage buffer being read. This will stall the GPU pipeline. Ensure this "
420 "path is only used in testing.");
430 if (gpu_write_fence_ != nil) {
432 while (gpu_write_fence_.signaledValue < host_read_signal_value_) {
447 id<MTLBlitCommandEncoder> blit_encoder =
461 switch (storage_source_) {
463 case MTL_STORAGE_BUF_TYPE_DEFAULT: {
469 "Storage Buffer backing resource does not yet exist. Ensure the resource is "
470 "bound with data before the calling code requires its underlying MTLBuffer.");
473 "Storage Buffer backing resource data has not yet been uploaded. Ensure the resource is "
474 "bound with data before the calling code requires its underlying MTLBuffer.");
478 case MTL_STORAGE_BUF_TYPE_UNIFORMBUF: {
482 case MTL_STORAGE_BUF_TYPE_VERTBUF: {
486 case MTL_STORAGE_BUF_TYPE_INDEXBUF: {
490 case MTL_STORAGE_BUF_TYPE_TEXTURE: {
493 id<MTLTexture>
tex =
texture_->get_metal_handle_base();
496 source_buffer =
texture_->backing_buffer_;
#define BLI_assert_msg(a, msg)
Platform independent time functions.
void BLI_time_sleep_ms(int ms)
#define UNUSED_VARS_NDEBUG(...)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
gpu::MTLBuffer * allocate(uint64_t size, bool cpu_visible)
void * get_host_ptr() const
void flush_range(uint64_t offset, uint64_t length)
void set_label(NSString *str)
MTLResourceOptions get_resource_options()
id< MTLBuffer > get_metal_buffer() const
void encode_signal_event(id< MTLEvent > event, uint64_t value)
id< MTLComputeCommandEncoder > ensure_begin_compute_encoder()
MTLComputeState & get_compute_state()
id< MTLBlitCommandEncoder > ensure_begin_blit_encoder()
void bind_compute_bytes(const void *bytes, uint64_t length, uint index)
void bind_compute_buffer(id< MTLBuffer > buffer, uint64_t buffer_offset, uint index)
void bind_pso(id< MTLComputePipelineState > pso)
id< MTLComputePipelineState > get_buffer_clear_pso()
MTLContextComputeUtils & get_compute_utils()
static MTLContext * get()
MTLContextGlobalShaderPipelineState pipeline_state
MTLCommandBufferManager main_command_buffer
static MTLBufferPool * get_global_memory_manager()
void async_flush_to_host() override
gpu::MTLTexture * texture_
void read(void *data) override
void clear(uint32_t clear_value) override
MTLIndexBuf * index_buffer_
void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) override
void update(const void *data) override
gpu::MTLBuffer * metal_buffer_
MTLStorageBuf(size_t size, GPUUsageType usage, const char *name)
id< MTLBuffer > get_metal_buffer()
MTLUniformBuf * uniform_buffer_
void bind(int slot) override
MTLVertBuf * vertex_buffer_
char name_[DEBUG_NAME_LEN]
local_group_size(16, 16) .push_constant(Type texture
flat(Type::VEC4, "color_and_coc1") .flat(Type no_perspective(Type::VEC2, "rect_uv1") .no_perspective(Type draw_view bokeh_lut_tx uniform_buf(6, "DepthOfFieldData", "dof_buf") .storage_buf(0
#define MTL_MAX_BUFFER_BINDINGS
#define MTL_LOG_WARNING(info,...)
MTLStorageBufferBinding ssbo_bindings[MTL_MAX_BUFFER_BINDINGS]