MCPcopy Create free account
hub / github.com/a2flo/floor / compute_buffer

Method compute_buffer

compute/compute_buffer.cpp:31–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29#endif
30
31compute_buffer::compute_buffer(const compute_queue& cqueue,
32 const size_t& size_,
33 std::span<uint8_t> host_data_,
34 const COMPUTE_MEMORY_FLAG flags_,
35 const uint32_t opengl_type_,
36 const uint32_t external_gl_object_,
37 compute_buffer* shared_buffer_) :
38compute_memory(cqueue, host_data_, flags_, opengl_type_, external_gl_object_), size(align_size(size_)), shared_buffer(shared_buffer_) {
39 if (size == 0) {
40 throw std::runtime_error("can't allocate a buffer of size 0!");
41 }
42
43 if (host_data.data() != nullptr && host_data.size_bytes() != size) {
44 throw std::runtime_error("host data size " + std::to_string(host_data.size_bytes()) + " does not match buffer size " + std::to_string(size));
45 }
46
47 if (size_ != size) {
48 log_error("buffer size must always be a multiple of $! - using size of $ instead of $ now",
49 min_multiple(), size, size_);
50 }
51
52 if (size > 0xFFFF'FFFFu && has_flag<COMPUTE_MEMORY_FLAG::OPENGL_SHARING>(flags)) {
53 log_error("using a buffer larger than 4GiB is not supported when using OpenGL sharing!");
54 size = 0xFFFFFFFFu;
55 }
56
57 if (shared_buffer != nullptr) {
58 if (!has_flag<COMPUTE_MEMORY_FLAG::VULKAN_SHARING>(flags) && !has_flag<COMPUTE_MEMORY_FLAG::METAL_SHARING>(flags)) {
59 log_warn("provided a shared buffer, but no sharing flag is set");
60 }
61 }
62
63 // if there is host data, it must have at least the same size as the buffer
64 if (host_data.data() != nullptr && host_data.size_bytes() < size) {
65 throw std::runtime_error("image host data size " + std::to_string(host_data.size_bytes()) +
66 " is smaller than the expected buffer size " + std::to_string(size));
67 }
68}
69
70void compute_buffer::delete_gl_buffer() {
71 if(has_external_gl_object) return;

Callers

nothing calls this directly

Calls 2

to_stringFunction · 0.50
dataMethod · 0.45

Tested by

no test coverage detected