From b4ca17e44bcc97e6ab9f3fa6b382f149fe11bc13 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 25 Aug 2020 18:12:42 +0800 Subject: [PATCH] support new VertexAttribType instead spirv_cross::SPIRType::BaseType --- CMCMakeModule | 2 +- CMCore | 2 +- CMPlatform | 2 +- CMSceneGraph | 2 +- inc/hgl/graph/VertexAttribData.h | 8 ++++---- inc/hgl/graph/shader/ShaderResource.h | 16 ++++++---------- src/SceneGraph/RenderableCreater.cpp | 4 ++-- src/SceneGraph/VertexAttribData.cpp | 11 +++++------ src/SceneGraph/shader/ShaderResource.cpp | 11 ++++++++--- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/CMCMakeModule b/CMCMakeModule index c4343466..0cb79161 160000 --- a/CMCMakeModule +++ b/CMCMakeModule @@ -1 +1 @@ -Subproject commit c4343466aac0bb49f36ea5a4c568baf95a3ee006 +Subproject commit 0cb791614f905ecaaa26b251f01b4c9f4ea5e274 diff --git a/CMCore b/CMCore index 73b9fc26..80d1e17d 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 73b9fc265c3ab70b47fe1def8a34b66ac6c5e090 +Subproject commit 80d1e17dcb28bba754a826044462bf08ab81de32 diff --git a/CMPlatform b/CMPlatform index f5117f0a..12590b9c 160000 --- a/CMPlatform +++ b/CMPlatform @@ -1 +1 @@ -Subproject commit f5117f0a84958defd11c337e512bd0a32bc9efca +Subproject commit 12590b9c6420114154696d23dab0ca14e0baae21 diff --git a/CMSceneGraph b/CMSceneGraph index 81c18490..762124c1 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit 81c18490a375fbeaa1ea99340916e44833ef6a74 +Subproject commit 762124c15723d71fd9d2b056d91ff4bf7737fd59 diff --git a/inc/hgl/graph/VertexAttribData.h b/inc/hgl/graph/VertexAttribData.h index bc233542..589434d1 100644 --- a/inc/hgl/graph/VertexAttribData.h +++ b/inc/hgl/graph/VertexAttribData.h @@ -36,7 +36,7 @@ namespace hgl protected: - const uint32_t dc_num; ///<每个数据成员数(比如二维坐标为2、三维坐标为3) + const uint32_t vec_size; ///<每个数据成员数(比如二维坐标为2、三维坐标为3) uint32_t count; ///<数据个数 const uint32_t stride; ///<每组数据字节数 @@ -46,7 +46,7 @@ namespace hgl public: - VertexAttribData(uint32_t c,uint32_t dc,uint32_t cs,VkFormat fmt):count(c),dc_num(dc),stride(cs),total_bytes(cs*c),vk_format(fmt) + VertexAttribData(uint32_t c,uint32_t dc,uint32_t cs,VkFormat fmt):count(c),vec_size(dc),stride(cs),total_bytes(cs*c),vk_format(fmt) { mem_data = hgl_malloc(total_bytes); //在很多情况下,hgl_malloc分配的内存是对齐的,这样有效率上的提升 } @@ -58,7 +58,7 @@ namespace hgl } const VkFormat GetVulkanFormat ()const{return vk_format;} ///<取得数据类型 - const uint32_t GetComponent ()const{return dc_num;} ///<取数缓冲区元数据数量 + const uint32_t GetVecSize ()const{return vec_size;} ///<取数缓冲区元数据成份数量 const uint32_t GetCount ()const{return count;} ///<取得数据数量 const uint32_t GetStride ()const{return stride;} ///<取得每一组数据字节数 void * GetData ()const{return mem_data;} ///<取得数据指针 @@ -73,7 +73,7 @@ namespace hgl * @param vecsize vec数量 * @param vertex_count 顶点数量 */ - VAD *CreateVertexAttribData(const vulkan::BaseType base_type,const uint32_t vecsize,const uint32_t vertex_count); + VAD *CreateVertexAttribData(const VertexAttribType *,const uint32_t vertex_count); //这个函数比较重要,就不搞成CreateVAD的简写了 }//namespace graph }//namespace hgl diff --git a/inc/hgl/graph/shader/ShaderResource.h b/inc/hgl/graph/shader/ShaderResource.h index 57a88cc6..32a66c1b 100644 --- a/inc/hgl/graph/shader/ShaderResource.h +++ b/inc/hgl/graph/shader/ShaderResource.h @@ -7,17 +7,13 @@ VK_NAMESPACE_BEGIN struct ShaderStage { - AnsiString name; - uint location; + AnsiString name; + uint location; - BaseType base_type; ///<基本类型(如vec4中的vec) - uint component; ///<成份数量(如vec4中的4) + VertexAttribType type; ///<成份数量(如vec4中的4) + VkFormat format; ///<对应的Vulkan格式(如vec4对应的FMT_RGBA32F) - VkFormat format; ///<对应的Vulkan格式(如vec4对应的FMT_RGBA32F) - - uint32_t stride; ///<对应Vulkan格式的每数据字节数 - - uint binding; + uint binding; };//struct ShaderStage using ShaderStageList =ObjectList; @@ -89,7 +85,7 @@ VK_NAMESPACE_BEGIN ShaderDescriptorList &GetSSBO (){return descriptor_list[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER];} ShaderDescriptorList &GetSampler(){return descriptor_list[VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER];} - const int GetBinding (VkDescriptorType desc_type,const AnsiString &name)const; + const int GetBinding (VkDescriptorType desc_type,const AnsiString &name)const; const DescriptorBindingList * GetBindingList (VkDescriptorType desc_type)const { if(desc_typedata =hgl::graph::CreateVertexAttribData(ss->base_type,ss->component,vertices_number); + ssb->data =hgl::graph::CreateVertexAttribData(&(ss->type),vertices_number); ssb->name =name; ssb->binding=ss->binding; @@ -76,7 +76,7 @@ namespace hgl if(!ss) return(nullptr); - if(ss->stride*vertices_number!=bytes) + if(ss->type.GetStride()*vertices_number!=bytes) return(nullptr); ssb=new ShaderStageBind; diff --git a/src/SceneGraph/VertexAttribData.cpp b/src/SceneGraph/VertexAttribData.cpp index fbd25658..3d4fc79d 100644 --- a/src/SceneGraph/VertexAttribData.cpp +++ b/src/SceneGraph/VertexAttribData.cpp @@ -4,15 +4,14 @@ namespace hgl { namespace graph { - VAD *CreateVertexAttribData(const vulkan::BaseType base_type,const uint32_t vecsize,const uint32_t vertex_count) + VAD *CreateVertexAttribData(const VertexAttribType *type,const uint32_t vertex_count) { - VkFormat fmt; - uint32_t stride; - - if(!vulkan::GetVulkanFormatStride(fmt,stride,base_type,vecsize)) + if(!type||!type->Check()) return(nullptr); - return(new VertexAttribData(vertex_count,vecsize,stride,fmt)); + VkFormat fmt=vulkan::GetVulkanFormat(type); + + return(new VertexAttribData(vertex_count,type->vec_size,type->GetStride(),fmt)); } }//namespace graph }//namespace hgl diff --git a/src/SceneGraph/shader/ShaderResource.cpp b/src/SceneGraph/shader/ShaderResource.cpp index c7cdc615..fb40277c 100644 --- a/src/SceneGraph/shader/ShaderResource.cpp +++ b/src/SceneGraph/shader/ShaderResource.cpp @@ -36,10 +36,10 @@ VK_NAMESPACE_BEGIN ss=new ShaderStage; ss->location=*data++; - ss->base_type=(VK_NAMESPACE::BaseType)*data++; - ss->component=*data++; + ss->type.basetype=(VertexAttribBaseType)*data++; + ss->type.vec_size=*data++; - VK_NAMESPACE::GetVulkanFormatStride(ss->format,ss->stride,ss->base_type,ss->component); + ss->format=VK_NAMESPACE::GetVulkanFormat(&(ss->type)); str_len=*data++; ss->name.SetString((char *)data,str_len); @@ -61,10 +61,15 @@ VK_NAMESPACE_BEGIN uint str_len; + sd_list->binding_list.PreMalloc(count); + sd_list->set_list.PreMalloc(count); + for(uint i=0;i=1) sd_list->set_list.Add(*data++); + else + sd_list->set_list.Add(0); sd_list->binding_list.Add(*data++); str_len=*data++;