Vulkan: Push constants #104880
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#include "vk_descriptor_set.hh"
|
||||
#include "vk_index_buffer.hh"
|
||||
#include "vk_storage_buffer.hh"
|
||||
#include "vk_vertex_buffer.hh"
|
||||
|
||||
|
@ -44,6 +45,14 @@ void VKDescriptorSet::bind_as_ssbo(VKVertexBuffer &buffer, int location)
|
|||
binding.buffer_size = buffer.size_used_get();
|
||||
}
|
||||
|
||||
void VKDescriptorSet::bind_as_ssbo(VKIndexBuffer &buffer, int location)
|
||||
{
|
||||
Binding &binding = ensure_location(location);
|
||||
binding.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
|
||||
binding.vk_buffer = buffer.vk_handle();
|
||||
binding.buffer_size = buffer.size_get();
|
||||
}
|
||||
|
||||
VKDescriptorSet::Binding &VKDescriptorSet::ensure_location(int location)
|
||||
{
|
||||
for (Binding &binding : bindings_) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
namespace blender::gpu {
|
||||
class VKStorageBuffer;
|
||||
class VKVertexBuffer;
|
||||
class VKIndexBuffer;
|
||||
|
||||
class VKDescriptorSet : NonCopyable {
|
||||
struct Binding {
|
||||
|
@ -60,6 +61,7 @@ class VKDescriptorSet : NonCopyable {
|
|||
}
|
||||
|
||||
void bind_as_ssbo(VKVertexBuffer &buffer, int location);
|
||||
void bind_as_ssbo(VKIndexBuffer &buffer, int location);
|
||||
void bind(VKStorageBuffer &buffer, int location);
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#include "vk_index_buffer.hh"
|
||||
#include "vk_shader.hh"
|
||||
|
||||
namespace blender::gpu {
|
||||
|
||||
|
@ -13,12 +14,28 @@ void VKIndexBuffer::upload_data()
|
|||
{
|
||||
}
|
||||
|
||||
void VKIndexBuffer::bind_as_ssbo(uint /*binding*/)
|
||||
void VKIndexBuffer::bind_as_ssbo(uint binding)
|
||||
{
|
||||
VKContext &context = *VKContext::get();
|
||||
if (!buffer_.is_allocated()) {
|
||||
allocate(context);
|
||||
}
|
||||
|
||||
VKShader *shader = static_cast<VKShader *>(context.shader);
|
||||
shader->pipeline_get().descriptor_set_get().bind_as_ssbo(*this, binding);
|
||||
}
|
||||
|
||||
void VKIndexBuffer::read(uint32_t * /*data*/) const
|
||||
void VKIndexBuffer::read(uint32_t *data) const
|
||||
{
|
||||
VKContext &context = *VKContext::get();
|
||||
VKCommandBuffer &command_buffer = context.command_buffer_get();
|
||||
command_buffer.submit();
|
||||
|
||||
void *mapped_memory;
|
||||
if (buffer_.map(context, &mapped_memory)) {
|
||||
memcpy(data, mapped_memory, size_get());
|
||||
buffer_.unmap(context);
|
||||
}
|
||||
}
|
||||
|
||||
void VKIndexBuffer::update_sub(uint /*start*/, uint /*len*/, const void * /*data*/)
|
||||
|
@ -29,4 +46,14 @@ void VKIndexBuffer::strip_restart_indices()
|
|||
{
|
||||
}
|
||||
|
||||
void VKIndexBuffer::allocate(VKContext &context)
|
||||
{
|
||||
GPUUsageType usage = data_ == nullptr ? GPU_USAGE_DEVICE_ONLY : GPU_USAGE_STATIC;
|
||||
buffer_.create(context,
|
||||
size_get(),
|
||||
usage,
|
||||
static_cast<VkBufferUsageFlagBits>(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT));
|
||||
}
|
||||
|
||||
} // namespace blender::gpu
|
||||
|
|
|
@ -9,9 +9,13 @@
|
|||
|
||||
#include "gpu_index_buffer_private.hh"
|
||||
|
||||
#include "vk_buffer.hh"
|
||||
|
||||
namespace blender::gpu {
|
||||
|
||||
class VKIndexBuffer : public IndexBuf {
|
||||
VKBuffer buffer_;
|
||||
|
||||
public:
|
||||
void upload_data() override;
|
||||
|
||||
|
@ -21,8 +25,14 @@ class VKIndexBuffer : public IndexBuf {
|
|||
|
||||
void update_sub(uint start, uint len, const void *data) override;
|
||||
|
||||
VkBuffer vk_handle()
|
||||
{
|
||||
return buffer_.vk_handle();
|
||||
}
|
||||
|
||||
private:
|
||||
void strip_restart_indices() override;
|
||||
void allocate(VKContext &context);
|
||||
};
|
||||
|
||||
} // namespace blender::gpu
|
||||
|
|
Loading…
Reference in New Issue