Metal setup merge (#1616)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Alex Cristici <alex.cristici@gmail.com> Co-authored-by: mwilsnd <mwilsnd@gmail.com> Co-authored-by: Stefan Karschti <stefan.karschti@gmail.com> Co-authored-by: Bart Louwers <bart@emeel.net> Co-authored-by: Alex Cristici <alex@skoon.energy> Co-authored-by: Bart Louwers <bart.louwers@gmail.com> Co-authored-by: Wei Chen <alanchenboy@gmail.com> Co-authored-by: Siarhei Fedartsou <siarhei.fedartsou@gmail.com> Co-authored-by: tdcosta100 <tdcosta100@gmail.com>
This commit is contained in:
44
src/mbgl/mtl/buffer_resource.cpp
Normal file
44
src/mbgl/mtl/buffer_resource.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <mbgl/mtl/buffer_resource.hpp>
|
||||
|
||||
#include <Metal/MTLDevice.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace mtl {
|
||||
|
||||
BufferResource::BufferResource(MTLDevicePtr device_, const void* data, std::size_t size, MTL::ResourceOptions usage_)
|
||||
: device(std::move(device_)),
|
||||
usage(usage_) {
|
||||
if (data && size) {
|
||||
buffer = NS::TransferPtr(device->newBuffer(data, static_cast<NS::UInteger>(size), usage));
|
||||
} else {
|
||||
buffer = NS::TransferPtr(device->newBuffer(static_cast<NS::UInteger>(size), usage));
|
||||
}
|
||||
}
|
||||
|
||||
BufferResource::BufferResource(const BufferResource& other)
|
||||
: device(other.device),
|
||||
usage(other.usage) {
|
||||
if (other.buffer) {
|
||||
buffer = NS::TransferPtr(device->newBuffer(other.buffer->contents(), other.buffer->length(), other.usage));
|
||||
}
|
||||
}
|
||||
|
||||
BufferResource::BufferResource(BufferResource&& other)
|
||||
: device(std::move(other.device)),
|
||||
buffer(std::move(other.buffer)),
|
||||
usage(other.usage) {}
|
||||
|
||||
void BufferResource::update(const void* data, std::size_t size, std::size_t offset) {
|
||||
assert(buffer && (data || size == 0));
|
||||
if (buffer && data && size > 0) {
|
||||
assert(buffer->contents());
|
||||
if (void* content = buffer->contents()) {
|
||||
const auto size_ = std::min(size, static_cast<std::size_t>(buffer->length()) - offset);
|
||||
assert(size == size_);
|
||||
std::memcpy(static_cast<uint8_t*>(content) + offset, data, size_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mtl
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user