From 419e0e257448b48ea71eedd6f5c40e49fbc530b2 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 23 May 2024 13:59:48 +0800 Subject: [PATCH] override Map/Flush/Write functions in IndexBuffer/VAB --- inc/hgl/graph/VKBuffer.h | 8 ++++---- inc/hgl/graph/VKIndexBuffer.h | 9 +++++++++ inc/hgl/graph/VKVertexAttribBuffer.h | 9 +++++++++ src/SceneGraph/RenderAssignBuffer.cpp | 4 ++-- src/SceneGraph/Vulkan/VKMemory.cpp | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/inc/hgl/graph/VKBuffer.h b/inc/hgl/graph/VKBuffer.h index 032f5d89..2ce5ebf5 100644 --- a/inc/hgl/graph/VKBuffer.h +++ b/inc/hgl/graph/VKBuffer.h @@ -42,11 +42,11 @@ public: void * Map () {return buf.memory->Map();} virtual void * Map (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Map(start,size);} void Unmap () {return buf.memory->Unmap();} - void Flush (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Flush(start,size);} - void Flush (VkDeviceSize size) {return buf.memory->Flush(size);} + virtual void Flush (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Flush(start,size);} + virtual void Flush (VkDeviceSize size) {return buf.memory->Flush(size);} - bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);} - bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);} + virtual bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);} + virtual bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);} bool Write (const void *ptr) {return buf.memory->Write(ptr);} };//class DeviceBuffer VK_NAMESPACE_END diff --git a/inc/hgl/graph/VKIndexBuffer.h b/inc/hgl/graph/VKIndexBuffer.h index 5c01dca7..77b24196 100644 --- a/inc/hgl/graph/VKIndexBuffer.h +++ b/inc/hgl/graph/VKIndexBuffer.h @@ -35,6 +35,15 @@ namespace hgl const IndexType GetType ()const{return index_type;} const uint GetStride ()const{return stride;} const uint32 GetCount ()const{return count;} + + public: + + void * Map (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Map(start*stride,size*stride);} + void Flush (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Flush(start*stride,size*stride); } + void Flush (VkDeviceSize size) override {return DeviceBuffer::Flush(size*stride);} + + bool Write (const void *ptr,uint32_t start,uint32_t size) override {return DeviceBuffer::Write(ptr,start*stride,size*stride);} + bool Write (const void *ptr,uint32_t size) override {return DeviceBuffer::Write(ptr,0,size*stride);} };//class IndexBuffer:public DeviceBuffer }//namespace graph }//namespace hgl diff --git a/inc/hgl/graph/VKVertexAttribBuffer.h b/inc/hgl/graph/VKVertexAttribBuffer.h index 2958e8f3..8a2c914d 100644 --- a/inc/hgl/graph/VKVertexAttribBuffer.h +++ b/inc/hgl/graph/VKVertexAttribBuffer.h @@ -33,6 +33,15 @@ namespace hgl const uint32_t GetCount ()const { return count; } const VkDeviceSize GetBytes()const { return stride*count; } + + public: + + void * Map (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Map(start*stride,size*stride);} + void Flush (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Flush(start*stride,size*stride); } + void Flush (VkDeviceSize size) override {return DeviceBuffer::Flush(size*stride);} + + bool Write (const void *ptr,uint32_t start,uint32_t size) override {return DeviceBuffer::Write(ptr,start*stride,size*stride);} + bool Write (const void *ptr,uint32_t size) override {return DeviceBuffer::Write(ptr,0,size*stride);} };//class VertexAttribBuffer:public DeviceBuffer using VAB=VertexAttribBuffer; diff --git a/src/SceneGraph/RenderAssignBuffer.cpp b/src/SceneGraph/RenderAssignBuffer.cpp index 41d800cd..8c19caba 100644 --- a/src/SceneGraph/RenderAssignBuffer.cpp +++ b/src/SceneGraph/RenderAssignBuffer.cpp @@ -84,7 +84,7 @@ void RenderL2WBuffer::WriteNode(RenderNode *render_node,const uint count) for(uint col=0;col<4;col++) { - tp=(glm::vec4 *)(l2w_vbo[col]->Map()); + tp=(glm::vec4 *)(l2w_vbo[col]->DeviceBuffer::Map()); rn=render_node; @@ -172,7 +172,7 @@ void RenderMIBuffer::WriteNode(RenderNode *render_node,const uint count,const Ma mi_data_buffer->Unmap(); - uint16 *idp=(uint16 *)(mi_vab->Map()); + uint16 *idp=(uint16 *)(mi_vab->DeviceBuffer::Map()); { rn=render_node; diff --git a/src/SceneGraph/Vulkan/VKMemory.cpp b/src/SceneGraph/Vulkan/VKMemory.cpp index acc41eaf..02360462 100644 --- a/src/SceneGraph/Vulkan/VKMemory.cpp +++ b/src/SceneGraph/Vulkan/VKMemory.cpp @@ -51,7 +51,7 @@ void *DeviceMemory::Map() void *DeviceMemory::Map(const VkDeviceSize offset,const VkDeviceSize size) { - if(offset<0||offset+size>=req.size) + if(offset<0||offset+size>req.size) return(nullptr); void *result;