forked from blender/blender
me-main #1
@ -89,13 +89,11 @@ void GPU_indexbuf_create_subrange_in_place(GPUIndexBuf *elem,
|
|||||||
uint length);
|
uint length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Download and) return a pointer containing the data of an index buffer.
|
* (Download and) fill data with the contents of the index buffer.
|
||||||
*
|
*
|
||||||
* Note that the returned pointer is still owned by the driver. To get an
|
* NOTE: caller is responsible to reserve enough memory.
|
||||||
* local copy, use `GPU_indexbuf_unmap` after calling `GPU_indexbuf_read`.
|
|
||||||
*/
|
*/
|
||||||
const uint32_t *GPU_indexbuf_read(GPUIndexBuf *elem);
|
void GPU_indexbuf_read(GPUIndexBuf *elem, uint32_t *data);
|
||||||
uint32_t *GPU_indexbuf_unmap(const GPUIndexBuf *elem, const uint32_t *mapped_buffer);
|
|
||||||
|
|
||||||
void GPU_indexbuf_discard(GPUIndexBuf *elem);
|
void GPU_indexbuf_discard(GPUIndexBuf *elem);
|
||||||
|
|
||||||
|
@ -64,13 +64,10 @@ GPUVertBuf *GPU_vertbuf_create_with_format_ex(const GPUVertFormat *, GPUUsageTyp
|
|||||||
GPU_vertbuf_create_with_format_ex(format, GPU_USAGE_STATIC)
|
GPU_vertbuf_create_with_format_ex(format, GPU_USAGE_STATIC)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Download and) return a pointer containing the data of a vertex buffer.
|
* (Download and) fill data with the data from the vertex buffer.
|
||||||
*
|
* NOTE: caller is responsible to reserve enough memory of the data parameter.
|
||||||
* Note that the returned pointer is still owned by the driver. To get an
|
|
||||||
* local copy, use `GPU_vertbuf_unmap` after calling `GPU_vertbuf_read`.
|
|
||||||
*/
|
*/
|
||||||
const void *GPU_vertbuf_read(GPUVertBuf *verts);
|
void GPU_vertbuf_read(GPUVertBuf *verts, void *data);
|
||||||
void *GPU_vertbuf_unmap(const GPUVertBuf *verts, const void *mapped_data);
|
|
||||||
/** Same as discard but does not free. */
|
/** Same as discard but does not free. */
|
||||||
void GPU_vertbuf_clear(GPUVertBuf *verts);
|
void GPU_vertbuf_clear(GPUVertBuf *verts);
|
||||||
void GPU_vertbuf_discard(GPUVertBuf *);
|
void GPU_vertbuf_discard(GPUVertBuf *);
|
||||||
|
@ -399,14 +399,6 @@ void IndexBuf::squeeze_indices_short(uint min_idx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t *IndexBuf::unmap(const uint32_t *mapped_memory) const
|
|
||||||
{
|
|
||||||
size_t size = size_get();
|
|
||||||
uint32_t *result = static_cast<uint32_t *>(MEM_mallocN(size, __func__));
|
|
||||||
memcpy(result, mapped_memory, size);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace blender::gpu
|
} // namespace blender::gpu
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
@ -456,14 +448,9 @@ void GPU_indexbuf_create_subrange_in_place(GPUIndexBuf *elem,
|
|||||||
unwrap(elem)->init_subrange(unwrap(elem_src), start, length);
|
unwrap(elem)->init_subrange(unwrap(elem_src), start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t *GPU_indexbuf_read(GPUIndexBuf *elem)
|
void GPU_indexbuf_read(GPUIndexBuf *elem, uint32_t *data)
|
||||||
{
|
{
|
||||||
return unwrap(elem)->read();
|
return unwrap(elem)->read(data);
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t *GPU_indexbuf_unmap(const GPUIndexBuf *elem, const uint32_t *mapped_buffer)
|
|
||||||
{
|
|
||||||
return unwrap(elem)->unmap(mapped_buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU_indexbuf_discard(GPUIndexBuf *elem)
|
void GPU_indexbuf_discard(GPUIndexBuf *elem)
|
||||||
|
@ -98,8 +98,7 @@ class IndexBuf {
|
|||||||
|
|
||||||
virtual void bind_as_ssbo(uint binding) = 0;
|
virtual void bind_as_ssbo(uint binding) = 0;
|
||||||
|
|
||||||
virtual const uint32_t *read() const = 0;
|
virtual void read(uint32_t *data) const = 0;
|
||||||
uint32_t *unmap(const uint32_t *mapped_memory) const;
|
|
||||||
|
|
||||||
virtual void update_sub(uint start, uint len, const void *data) = 0;
|
virtual void update_sub(uint start, uint len, const void *data) = 0;
|
||||||
|
|
||||||
|
@ -153,14 +153,9 @@ GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts_)
|
|||||||
return wrap(unwrap(verts_)->duplicate());
|
return wrap(unwrap(verts_)->duplicate());
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *GPU_vertbuf_read(GPUVertBuf *verts)
|
void GPU_vertbuf_read(GPUVertBuf *verts, void *data)
|
||||||
{
|
{
|
||||||
return unwrap(verts)->read();
|
unwrap(verts)->read(data);
|
||||||
}
|
|
||||||
|
|
||||||
void *GPU_vertbuf_unmap(const GPUVertBuf *verts, const void *mapped_data)
|
|
||||||
{
|
|
||||||
return unwrap(verts)->unmap(mapped_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU_vertbuf_clear(GPUVertBuf *verts)
|
void GPU_vertbuf_clear(GPUVertBuf *verts)
|
||||||
|
@ -94,8 +94,7 @@ class VertBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void update_sub(uint start, uint len, const void *data) = 0;
|
virtual void update_sub(uint start, uint len, const void *data) = 0;
|
||||||
virtual const void *read() const = 0;
|
virtual void read(void *data) const = 0;
|
||||||
virtual void *unmap(const void *mapped_data) const = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void acquire_data() = 0;
|
virtual void acquire_data() = 0;
|
||||||
|
@ -48,7 +48,7 @@ class MTLIndexBuf : public IndexBuf {
|
|||||||
~MTLIndexBuf();
|
~MTLIndexBuf();
|
||||||
|
|
||||||
void bind_as_ssbo(uint32_t binding) override;
|
void bind_as_ssbo(uint32_t binding) override;
|
||||||
const uint32_t *read() const override;
|
void read(uint32_t *data) const override;
|
||||||
|
|
||||||
void upload_data() override;
|
void upload_data() override;
|
||||||
void update_sub(uint32_t start, uint32_t len, const void *data) override;
|
void update_sub(uint32_t start, uint32_t len, const void *data) override;
|
||||||
|
@ -46,16 +46,13 @@ void MTLIndexBuf::bind_as_ssbo(uint32_t binding)
|
|||||||
MTL_LOG_WARNING("MTLIndexBuf::bind_as_ssbo not yet implemented!\n");
|
MTL_LOG_WARNING("MTLIndexBuf::bind_as_ssbo not yet implemented!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t *MTLIndexBuf::read() const
|
void MTLIndexBuf::read(uint32_t *data) const
|
||||||
{
|
{
|
||||||
if (ibo_ != nullptr) {
|
if (ibo_ != nullptr) {
|
||||||
|
void *host_ptr = ibo_->get_host_ptr();
|
||||||
/* Return host pointer. */
|
memcpy(data, host_ptr, size_get());
|
||||||
void *data = ibo_->get_host_ptr();
|
|
||||||
return static_cast<uint32_t *>(data);
|
|
||||||
}
|
}
|
||||||
BLI_assert(false && "Index buffer not ready to be read.");
|
BLI_assert(false && "Index buffer not ready to be read.");
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MTLIndexBuf::upload_data()
|
void MTLIndexBuf::upload_data()
|
||||||
|
@ -56,8 +56,7 @@ class MTLVertBuf : public VertBuf {
|
|||||||
|
|
||||||
void update_sub(uint start, uint len, const void *data) override;
|
void update_sub(uint start, uint len, const void *data) override;
|
||||||
|
|
||||||
const void *read() const override;
|
void read(void *data) const override;
|
||||||
void *unmap(const void *mapped_data) const override;
|
|
||||||
|
|
||||||
void wrap_handle(uint64_t handle) override;
|
void wrap_handle(uint64_t handle) override;
|
||||||
|
|
||||||
|
@ -328,21 +328,12 @@ void MTLVertBuf::bind_as_texture(uint binding)
|
|||||||
GPU_texture_bind(buffer_texture_, binding);
|
GPU_texture_bind(buffer_texture_, binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *MTLVertBuf::read() const
|
void MTLVertBuf::read(void *data) const
|
||||||
{
|
{
|
||||||
BLI_assert(vbo_ != nullptr);
|
BLI_assert(vbo_ != nullptr);
|
||||||
BLI_assert(usage_ != GPU_USAGE_DEVICE_ONLY);
|
BLI_assert(usage_ != GPU_USAGE_DEVICE_ONLY);
|
||||||
void *return_ptr = vbo_->get_host_ptr();
|
void *host_ptr = vbo_->get_host_ptr();
|
||||||
BLI_assert(return_ptr != nullptr);
|
memcpy(data, host_ptr, alloc_size_);
|
||||||
|
|
||||||
return return_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *MTLVertBuf::unmap(const void *mapped_data) const
|
|
||||||
{
|
|
||||||
void *result = MEM_mallocN(alloc_size_, __func__);
|
|
||||||
memcpy(result, mapped_data, alloc_size_);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MTLVertBuf::wrap_handle(uint64_t handle)
|
void MTLVertBuf::wrap_handle(uint64_t handle)
|
||||||
|
@ -46,12 +46,12 @@ void GLIndexBuf::bind_as_ssbo(uint binding)
|
|||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, binding, ibo_id_);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, binding, ibo_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t *GLIndexBuf::read() const
|
void GLIndexBuf::read(uint32_t *data) const
|
||||||
{
|
{
|
||||||
BLI_assert(is_active());
|
BLI_assert(is_active());
|
||||||
void *data = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY);
|
void *buffer = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY);
|
||||||
uint32_t *result = static_cast<uint32_t *>(data);
|
memcpy(data, buffer, size_get());
|
||||||
return result;
|
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLIndexBuf::is_active() const
|
bool GLIndexBuf::is_active() const
|
||||||
|
@ -29,7 +29,7 @@ class GLIndexBuf : public IndexBuf {
|
|||||||
void bind();
|
void bind();
|
||||||
void bind_as_ssbo(uint binding) override;
|
void bind_as_ssbo(uint binding) override;
|
||||||
|
|
||||||
const uint32_t *read() const override;
|
void read(uint32_t *data) const override;
|
||||||
|
|
||||||
void *offset_ptr(uint additional_vertex_offset) const
|
void *offset_ptr(uint additional_vertex_offset) const
|
||||||
{
|
{
|
||||||
|
@ -125,18 +125,12 @@ void GLVertBuf::bind_as_texture(uint binding)
|
|||||||
GPU_texture_bind(buffer_texture_, binding);
|
GPU_texture_bind(buffer_texture_, binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *GLVertBuf::read() const
|
void GLVertBuf::read(void *data) const
|
||||||
{
|
{
|
||||||
BLI_assert(is_active());
|
BLI_assert(is_active());
|
||||||
void *result = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
|
void *result = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
|
||||||
return result;
|
memcpy(data, result, size_used_get());
|
||||||
}
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||||
|
|
||||||
void *GLVertBuf::unmap(const void *mapped_data) const
|
|
||||||
{
|
|
||||||
void *result = MEM_mallocN(vbo_size_, __func__);
|
|
||||||
memcpy(result, mapped_data, vbo_size_);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLVertBuf::wrap_handle(uint64_t handle)
|
void GLVertBuf::wrap_handle(uint64_t handle)
|
||||||
|
@ -37,8 +37,7 @@ class GLVertBuf : public VertBuf {
|
|||||||
|
|
||||||
void update_sub(uint start, uint len, const void *data) override;
|
void update_sub(uint start, uint len, const void *data) override;
|
||||||
|
|
||||||
const void *read() const override;
|
void read(void *data) const override;
|
||||||
void *unmap(const void *mapped_data) const override;
|
|
||||||
|
|
||||||
void wrap_handle(uint64_t handle) override;
|
void wrap_handle(uint64_t handle) override;
|
||||||
|
|
||||||
|
@ -151,8 +151,8 @@ static void test_gpu_shader_compute_vbo()
|
|||||||
GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE);
|
GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE);
|
||||||
|
|
||||||
/* Download the vertex buffer. */
|
/* Download the vertex buffer. */
|
||||||
const float *data = static_cast<const float *>(GPU_vertbuf_read(vbo));
|
float data[SIZE * 4];
|
||||||
ASSERT_NE(data, nullptr);
|
GPU_vertbuf_read(vbo, data);
|
||||||
for (int index = 0; index < SIZE; index++) {
|
for (int index = 0; index < SIZE; index++) {
|
||||||
float expected_value = index;
|
float expected_value = index;
|
||||||
EXPECT_FLOAT_EQ(data[index * 4 + 0], expected_value);
|
EXPECT_FLOAT_EQ(data[index * 4 + 0], expected_value);
|
||||||
@ -195,8 +195,8 @@ static void test_gpu_shader_compute_ibo()
|
|||||||
GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE);
|
GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE);
|
||||||
|
|
||||||
/* Download the index buffer. */
|
/* Download the index buffer. */
|
||||||
const uint32_t *data = GPU_indexbuf_read(ibo);
|
uint32_t data[SIZE];
|
||||||
ASSERT_NE(data, nullptr);
|
GPU_indexbuf_read(ibo, data);
|
||||||
for (int index = 0; index < SIZE; index++) {
|
for (int index = 0; index < SIZE; index++) {
|
||||||
uint32_t expected = index;
|
uint32_t expected = index;
|
||||||
EXPECT_EQ(data[index], expected);
|
EXPECT_EQ(data[index], expected);
|
||||||
|
@ -17,9 +17,8 @@ void VKIndexBuffer::bind_as_ssbo(uint /*binding*/)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t *VKIndexBuffer::read() const
|
void VKIndexBuffer::read(uint32_t * /*data*/) const
|
||||||
{
|
{
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VKIndexBuffer::update_sub(uint /*start*/, uint /*len*/, const void * /*data*/)
|
void VKIndexBuffer::update_sub(uint /*start*/, uint /*len*/, const void * /*data*/)
|
||||||
|
@ -17,7 +17,7 @@ class VKIndexBuffer : public IndexBuf {
|
|||||||
|
|
||||||
void bind_as_ssbo(uint binding) override;
|
void bind_as_ssbo(uint binding) override;
|
||||||
|
|
||||||
const uint32_t *read() const override;
|
void read(uint32_t *data) const override;
|
||||||
|
|
||||||
void update_sub(uint start, uint len, const void *data) override;
|
void update_sub(uint start, uint len, const void *data) override;
|
||||||
|
|
||||||
|
@ -32,14 +32,8 @@ void VKVertexBuffer::update_sub(uint /*start*/, uint /*len*/, const void * /*dat
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *VKVertexBuffer::read() const
|
void VKVertexBuffer::read(void * /*data*/) const
|
||||||
{
|
{
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *VKVertexBuffer::unmap(const void * /*mapped_data*/) const
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VKVertexBuffer::acquire_data()
|
void VKVertexBuffer::acquire_data()
|
||||||
|
@ -20,8 +20,7 @@ class VKVertexBuffer : public VertBuf {
|
|||||||
void wrap_handle(uint64_t handle) override;
|
void wrap_handle(uint64_t handle) override;
|
||||||
|
|
||||||
void update_sub(uint start, uint len, const void *data) override;
|
void update_sub(uint start, uint len, const void *data) override;
|
||||||
const void *read() const override;
|
void read(void *data) const override;
|
||||||
void *unmap(const void *mapped_data) const override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void acquire_data() override;
|
void acquire_data() override;
|
||||||
|
Loading…
Reference in New Issue
Block a user