diff --git a/CMCore b/CMCore index f52b7ac9..91d408d1 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit f52b7ac971305bc1e3e987a7de919e891fdc4d6e +Subproject commit 91d408d10cb6f934522f6c544ae05694315b90fe diff --git a/CMPlatform b/CMPlatform index ea2aaf31..2d5c094b 160000 --- a/CMPlatform +++ b/CMPlatform @@ -1 +1 @@ -Subproject commit ea2aaf3126ad6d64a4999c9b493c7dd560f79bc0 +Subproject commit 2d5c094bbfb69841512007e1eb88c0c6bc1b5c28 diff --git a/example/Vulkan/DeferredModel.cpp b/example/Vulkan/DeferredModel.cpp index 5073f306..5fa9b388 100644 --- a/example/Vulkan/DeferredModel.cpp +++ b/example/Vulkan/DeferredModel.cpp @@ -182,7 +182,7 @@ private: VK_SAMPLER_ADDRESS_MODE_REPEAT, 0.0f, VK_TRUE, - device->GetGPUPhysicalDevice()->GetMaxSamplerAnisotropy(), + device->GetPhysicalDevice()->GetMaxSamplerAnisotropy(), false, VK_COMPARE_OP_NEVER, 0.0f, diff --git a/example/Vulkan/InlineGeometryScene.cpp b/example/Vulkan/InlineGeometryScene.cpp index 91db362e..ff58cfb7 100644 --- a/example/Vulkan/InlineGeometryScene.cpp +++ b/example/Vulkan/InlineGeometryScene.cpp @@ -106,7 +106,7 @@ private: VK_SAMPLER_ADDRESS_MODE_REPEAT, 0.0f, VK_TRUE, - device->GetGPUPhysicalDevice()->GetMaxSamplerAnisotropy(), + device->GetPhysicalDevice()->GetMaxSamplerAnisotropy(), false, VK_COMPARE_OP_NEVER, 0.0f, diff --git a/inc/hgl/graph/VKArrayBuffer.h b/inc/hgl/graph/VKArrayBuffer.h index 50cd5fee..39e6c581 100644 --- a/inc/hgl/graph/VKArrayBuffer.h +++ b/inc/hgl/graph/VKArrayBuffer.h @@ -1,38 +1,39 @@ -#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE +#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE #define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE #include +#include namespace hgl { namespace graph { /** - * GPUл
- * ڴͬʽݣڶȾinstance + * GPU数据阵列缓冲区
+ * 它用于储存多份相同格式的数据,常用于多物件渲染,instance等 */ class GPUArrayBuffer { protected: - uint32_t item_size; ///<ݳ - uint32_t alloc_count; ///<ܼƷݸ - uint32_t count; ///<ʵʹõݸ + GPUDevice * device; - GPUBuffer * buf_gpu; ///<ʵGPU + uint32_t item_size; ///<单个数据长度 + uint32_t alloc_count; ///<总计分配的数据个数 + uint32_t count; ///<实际使用的数据个数 + uint32_t total_bytes; ///<总字节数 + + GPUBuffer * buf_gpu; ///<实际数据GPU缓冲区 uint8 * buf_cpu; - uint32_t * offset; ///<ƫƵַ + uint32_t * offset; ///<数据偏移地址 public: - /** - * ๹캯 - * @param s ݳ - * @param c ݸ - */ - GPUArrayBuffer(const uint32_t s=0,const uint32_t c=0); + GPUArrayBuffer(GPUDevice *,const uint32_t s=0,const uint32_t c=0); virtual ~GPUArrayBuffer(); - void Clear(); ///<ջ + void Clear(); ///<清空缓冲区 + + bool Init(const uint32_t); ///<初始化并分配空间 };//class GPUArrayBuffer }//namespace graph }//namespace hgl diff --git a/inc/hgl/graph/VKDevice.h b/inc/hgl/graph/VKDevice.h index 55b71808..15621070 100644 --- a/inc/hgl/graph/VKDevice.h +++ b/inc/hgl/graph/VKDevice.h @@ -1,5 +1,5 @@ -#ifndef HGL_GRAPH_RENDER_SURFACE_INCLUDE -#define HGL_GRAPH_RENDER_SURFACE_INCLUDE +#ifndef HGL_GRAPH_VULKAN_DEVICE_INCLUDE +#define HGL_GRAPH_VULKAN_DEVICE_INCLUDE #include #include @@ -30,7 +30,7 @@ class GPUDevice { GPUDeviceAttribute *attr; - GPUQueue *textureSQ; + GPUQueue *texture_queue; TextureCmdBuffer *texture_cmd_buf; Swapchain *swapchain; @@ -60,7 +60,7 @@ public: VkSurfaceKHR GetSurface () {return attr->surface;} VkDevice GetDevice ()const {return attr->device;} - const GPUPhysicalDevice * GetGPUPhysicalDevice()const {return attr->physical_device;} + const GPUPhysicalDevice * GetPhysicalDevice ()const {return attr->physical_device;} VkDescriptorPool GetDescriptorPool () {return attr->desc_pool;} VkPipelineCache GetPipelineCache () {return attr->pipeline_cache;} @@ -253,4 +253,4 @@ bool CreateAttachmentDescription( List &color_output_de GPUDevice *CreateRenderDevice(VulkanInstance *inst,Window *win,const GPUPhysicalDevice *physical_device=nullptr); VK_NAMESPACE_END -#endif//HGL_GRAPH_RENDER_SURFACE_INCLUDE +#endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE diff --git a/inc/hgl/graph/VKMemoryAllocator.h b/inc/hgl/graph/VKMemoryAllocator.h new file mode 100644 index 00000000..4b46a0db --- /dev/null +++ b/inc/hgl/graph/VKMemoryAllocator.h @@ -0,0 +1,34 @@ +#ifndef HGL_GRAPH_VULKAN_MEMORY_ALLOCATOR_INCLUDE +#define HGL_GRAPH_VULKAN_MEMORY_ALLOCATOR_INCLUDE + +#include +#include + +VK_NAMESPACE_BEGIN +class VKMemoryAllocator:public AbstractMemoryAllocator +{ + GPUDevice *device; + + uint32_t buffer_usage_flag_bits; + + GPUBuffer *gpu_buffer; + +protected: + + bool Alloc() override; + +public: + + const bool CanRealloc ()const override{return false;} + + const uint32_t GetBufferUsageFlagBits ()const{return buffer_usage_flag_bits;} + +public: + + VKMemoryAllocator(GPUDevice *,const uint32_t); + ~VKMemoryAllocator(); + + void Free() override {/* DON'T RUN ANY OPERATION.*/} +};//class VKMemoryAllocator:public AbstractMemoryAllocator +VK_NAMESPACE_END +#endif//HGL_GRAPH_VULKAN_MEMORY_ALLOCATOR_INCLUDE diff --git a/inc/hgl/graph/VKPhysicalDevice.h b/inc/hgl/graph/VKPhysicalDevice.h index 34a7b4f1..7d387027 100644 --- a/inc/hgl/graph/VKPhysicalDevice.h +++ b/inc/hgl/graph/VKPhysicalDevice.h @@ -37,7 +37,9 @@ public: public: - const uint32_t GetConstantSize()const{return properties.limits.maxPushConstantsSize;} + const uint32_t GetUBORange ()const{return properties.limits.maxUniformBufferRange;} + const uint32_t GetSSBORange ()const{return properties.limits.maxStorageBufferRange;} + const uint32_t GetConstantSize ()const{return properties.limits.maxPushConstantsSize;} public: diff --git a/src/SceneGraph/Vulkan/VKArrayBuffer.cpp b/src/SceneGraph/Vulkan/VKArrayBuffer.cpp index f35c5c05..fa286e73 100644 --- a/src/SceneGraph/Vulkan/VKArrayBuffer.cpp +++ b/src/SceneGraph/Vulkan/VKArrayBuffer.cpp @@ -1,16 +1,19 @@ -#include +#include namespace hgl { namespace graph { /** - * ๹캯 - * @param s ݳ - * @param c ݸ + * 本类构造函数 + * @param d 设备指针 + * @param s 单个数据长度 + * @param c 数据个数 */ - GPUArrayBuffer::GPUArrayBuffer(const uint32_t s,const uint32_t c) + GPUArrayBuffer::GPUArrayBuffer(GPUDevice *d,const uint32_t s,const uint32_t c) { + device=d; + item_size=s; count=c; alloc_count=power_to_2(c); @@ -22,6 +25,7 @@ namespace hgl GPUArrayBuffer::~GPUArrayBuffer() { + SAFE_CLEAR_ARRAY(offset); SAFE_CLEAR(buf_gpu); } @@ -30,6 +34,27 @@ namespace hgl count=0; } + bool GPUArrayBuffer::Init(const uint32_t c) + { + if(c<=0)return(false); + if(!buf_gpu) + { + count=c; + alloc_count=power_to_2(count); + + total_bytes=item_size*alloc_count; + + if(total_bytes<=0)return(false); + + buf_gpu=device->CreateUBO(total_bytes); + buf_cpu=(uint8 *)(buf_gpu->Map()); + + offset=new uint32_t[alloc_count]; + } + else + { + } + } }//namespace graph }//namespace hgl diff --git a/src/SceneGraph/Vulkan/VKDevice.cpp b/src/SceneGraph/Vulkan/VKDevice.cpp index 9f3d0908..d69d0d2a 100644 --- a/src/SceneGraph/Vulkan/VKDevice.cpp +++ b/src/SceneGraph/Vulkan/VKDevice.cpp @@ -15,7 +15,7 @@ GPUDevice::GPUDevice(GPUDeviceAttribute *da) { attr=da; - textureSQ=nullptr; + texture_queue=nullptr; texture_cmd_buf=nullptr; swapchain=nullptr; @@ -28,7 +28,7 @@ GPUDevice::~GPUDevice() SAFE_CLEAR(swapchainRT); SAFE_CLEAR(swapchain); - SAFE_CLEAR(textureSQ); + SAFE_CLEAR(texture_queue); SAFE_CLEAR(texture_cmd_buf); delete attr; @@ -39,7 +39,7 @@ bool GPUDevice::Resize(const VkExtent2D &extent) SAFE_CLEAR(swapchainRT); SAFE_CLEAR(swapchain); - SAFE_CLEAR(textureSQ); + SAFE_CLEAR(texture_queue); SAFE_CLEAR(texture_cmd_buf); attr->Refresh(); @@ -48,7 +48,7 @@ bool GPUDevice::Resize(const VkExtent2D &extent) return(false); texture_cmd_buf=CreateTextureCommandBuffer(); - textureSQ=new GPUQueue(this,attr->graphics_queue,1); + texture_queue=new GPUQueue(this,attr->graphics_queue,1); swapchainRT=new SwapchainRenderTarget(this,swapchain); diff --git a/src/SceneGraph/Vulkan/VKDeviceTexture.cpp b/src/SceneGraph/Vulkan/VKDeviceTexture.cpp index 73fa60dc..d9fd3f4b 100644 --- a/src/SceneGraph/Vulkan/VKDeviceTexture.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceTexture.cpp @@ -426,9 +426,9 @@ bool GPUDevice::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t cou if(!cmd_bufs||count<=0) return(false); - textureSQ->Submit(cmd_bufs,count,nullptr,nullptr); -// textureSQ->WaitQueue(); - textureSQ->WaitFence(); + texture_queue->Submit(cmd_bufs,count,nullptr,nullptr); +// texture_queue->WaitQueue(); + texture_queue->WaitFence(); return(true); } diff --git a/src/SceneGraph/Vulkan/VKMemoryAllocator.cpp b/src/SceneGraph/Vulkan/VKMemoryAllocator.cpp new file mode 100644 index 00000000..0413257e --- /dev/null +++ b/src/SceneGraph/Vulkan/VKMemoryAllocator.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +VK_NAMESPACE_BEGIN +VKMemoryAllocator::VKMemoryAllocator(GPUDevice *d,const uint32_t flags) +{ + device=d; + buffer_usage_flag_bits=flags; + gpu_buffer=nullptr; + + const GPUPhysicalDevice *pd=device->GetPhysicalDevice(); + + SetAllocUnitSize(pd->GetConstantSize()); //˵push constantGPUСʵλ +} + +VKMemoryAllocator::~VKMemoryAllocator() +{ + SAFE_CLEAR(gpu_buffer); +} + +bool VKMemoryAllocator::Alloc() +{ + if(gpu_buffer) + delete gpu_buffer; + + gpu_buffer=device->CreateBuffer(buffer_usage_flag_bits,alloc_size); + + if(!gpu_buffer) + { + memory_block=nullptr; + return(false); + } + + memory_block=gpu_buffer->Map(); + + return(true); +} +VK_NAMESPACE_END