45 if (vbo_ !=
nullptr) {
57 ssbo_wrapper_ =
nullptr;
92 [enc insertDebugSignpost:
@"VertexBufferDuplicate"];
94 [enc copyFromBuffer:src_buffer
101 if (dest_buffer.storageMode == MTLStorageModeManaged) {
102 [enc synchronizeResource:dest_buffer];
106 [enc insertDebugSignpost:
@"VertexBufferDuplicateEnd"];
114 if (
data_ !=
nullptr) {
132 if (required_size_raw == 0) {
146 bool requires_reallocation = (vbo_ !=
nullptr) && (alloc_size_ != required_size);
152 if (vbo_ !=
nullptr) {
153 if (requires_reallocation || (new_data_ready && contents_in_flight_)) {
163 if (requires_reallocation) {
164 this->
flag &= ~GPU_VERTBUF_DATA_UPLOADED;
170 if (vbo_ ==
nullptr) {
178 alloc_size_ = required_size;
179 contents_in_flight_ =
false;
183 if (new_data_ready) {
194 memcpy((
uint8_t *)dst_data, this->
data_, required_size_raw);
204 this->
flag &= ~GPU_VERTBUF_DATA_DIRTY;
207 else if (requires_reallocation) {
226 [enc copyFromBuffer:copy_prev_buffer
228 toBuffer:copy_new_buffer
230 size:
min_ulul([copy_new_buffer length], [copy_prev_buffer length])];
234 if (copy_new_buffer.storageMode == MTLStorageModeManaged) {
235 [enc synchronizeResource:copy_new_buffer];
252 if (prev_vbo !=
nullptr) {
275 memcpy(scratch_allocation.
data, data,
len);
278 id<MTLBuffer> data_buffer = scratch_allocation.
metal_buffer;
281 BLI_assert(vbo_ !=
nullptr && data !=
nullptr);
289 [enc copyFromBuffer:data_buffer
290 sourceOffset:data_buffer_offset
292 destinationOffset:start
296 if (dst_buffer.storageMode == MTLStorageModeManaged) {
297 [enc synchronizeResource:dst_buffer];
309 if (ssbo_wrapper_ ==
nullptr) {
312 ssbo_wrapper_->
bind(binding);
322 id<MTLBuffer> buf = this->get_metal_buffer();
323 if (buffer_texture_ !=
nullptr) {
325 unwrap(this->buffer_texture_));
327 if (tex_buf != buf) {
329 buffer_texture_ =
nullptr;
334 if (buffer_texture_ ==
nullptr) {
355 if (source_buffer.storageMode == MTLStorageModeManaged) {
357 [enc synchronizeResource:source_buffer];
365 memcpy(data, host_ptr, alloc_size_);
379 [enc copyFromBuffer:source_buffer
383 size:
min_ulul([dest_buffer length], [dest_buffer length])];
387 if (dest_buffer.storageMode == MTLStorageModeManaged) {
388 [enc synchronizeResource:dest_buffer];
396 memcpy(data, host_ptr, alloc_size_);
397 dst_tmp_vbo_->
free();
407 id<MTLBuffer> buffer =
reinterpret_cast<id<MTLBuffer>
>((
void *)handle);
418 contents_in_flight_ =
true;
MINLINE uint ceil_to_multiple_u(uint a, uint b)
void GPU_texture_bind(GPUTexture *texture, int unit)
GPUTexture * GPU_texture_create_from_vertbuf(const char *name, blender::gpu::VertBuf *vertex_buf)
#define GPU_TEXTURE_FREE_SAFE(texture)
@ GPU_VERTBUF_DATA_UPLOADED
#define MEM_reallocN(vmemh, len)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
gpu::MTLBuffer * allocate(uint64_t size, bool cpu_visible)
uint64_t get_size() const
void * get_host_ptr() const
void flush_range(uint64_t offset, uint64_t length)
void set_label(NSString *str)
id< MTLBuffer > get_metal_buffer() const
id< MTLBlitCommandEncoder > ensure_begin_blit_encoder()
static MTLContext * get()
MTLCommandBufferManager main_command_buffer
MTLScratchBufferManager & get_scratchbuffer_manager()
static MTLBufferPool * get_global_memory_manager()
MTLTemporaryBuffer scratch_buffer_allocate_range_aligned(uint64_t alloc_size, uint alignment)
void bind(int slot) override
id< MTLBuffer > get_vertex_buffer() const
void duplicate_data(VertBuf *dst) override
void resize_data() override
void wrap_handle(uint64_t handle) override
void bind_as_ssbo(uint binding) override
void upload_data() override
friend class MTLStorageBuf
void update_sub(uint start, uint len, const void *data) override
void read(void *data) const override
void bind_as_texture(uint binding) override
void acquire_data() override
void release_data() override
size_t size_used_get() const
size_t size_alloc_get() const
GPUUsageType get_usage_type() const
void *(* MEM_mallocN)(size_t len, const char *str)
void *(* MEM_dupallocN)(const void *vmemh)
MINLINE unsigned long long min_ulul(unsigned long long a, unsigned long long b)
MINLINE unsigned long long max_ulul(unsigned long long a, unsigned long long b)
#define MTL_LOG_INFO(info,...)
static Context * unwrap(GPUContext *ctx)
unsigned __int64 uint64_t
id< MTLBuffer > metal_buffer