From 08bc2ab6df01c0bf0a5461c39fe3e8f75e16040e Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 6 May 2019 21:01:28 +0800 Subject: [PATCH] =?UTF-8?q?VertexShaderModule=E5=88=A0=E9=99=A4GetLocation?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8CGetBinding=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E6=94=B9=E5=90=8D=E4=B8=BAGetStageInputBinding=E5=B9=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A=E4=BB=A5=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E8=AF=AF=E4=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/indices_rect.cpp | 2 +- example/Vulkan/main.cpp | 4 ++-- inc/hgl/graph/vulkan/VKMaterial.h | 3 ++- inc/hgl/graph/vulkan/VKShaderModule.h | 20 ++++++++++--------- .../graph/vulkan/VKVertexAttributeBinding.h | 10 +++++----- src/RenderDevice/Vulkan/VKMaterial.cpp | 13 ++++++------ src/RenderDevice/Vulkan/VKRenderable.cpp | 2 +- src/RenderDevice/Vulkan/VKShaderModule.cpp | 14 +------------ .../Vulkan/VKVertexAttributeBinding.cpp | 4 ++-- 9 files changed, 32 insertions(+), 40 deletions(-) diff --git a/example/Vulkan/indices_rect.cpp b/example/Vulkan/indices_rect.cpp index 45f134dd..f8bf14e5 100644 --- a/example/Vulkan/indices_rect.cpp +++ b/example/Vulkan/indices_rect.cpp @@ -12,7 +12,7 @@ constexpr uint32_t SCREEN_HEIGHT=128; struct WorldConfig { - Matrix4f mvp; + Matrix4f mvp; }world; constexpr uint32_t VERTEX_COUNT=4; diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index e73a1c62..4e564aa8 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -9,8 +9,8 @@ using namespace hgl::graph; //void SaveToTOML(const OSString &filename,const VkGraphicsPipelineCreateInfo *info); -constexpr uint32_t SCREEN_WIDTH=1280; -constexpr uint32_t SCREEN_HEIGHT=720; +constexpr uint32_t SCREEN_WIDTH=128; +constexpr uint32_t SCREEN_HEIGHT=128; struct WorldConfig { diff --git a/inc/hgl/graph/vulkan/VKMaterial.h b/inc/hgl/graph/vulkan/VKMaterial.h index 3843e0e2..1df6f985 100644 --- a/inc/hgl/graph/vulkan/VKMaterial.h +++ b/inc/hgl/graph/vulkan/VKMaterial.h @@ -38,7 +38,8 @@ public: ~Material(); const int GetUBOBinding(const UTF8String &)const; - const int GetVBOBinding(const UTF8String &)const; +// const int GetSSBOBinding(const UTF8String &)const; +// const int GetINBOBinding(const UTF8String &)const; const uint32_t GetStageCount ()const{return shader_stage_list->GetCount();} const VkPipelineShaderStageCreateInfo * GetStages ()const{return shader_stage_list->GetData();} diff --git a/inc/hgl/graph/vulkan/VKShaderModule.h b/inc/hgl/graph/vulkan/VKShaderModule.h index e96781e8..091c92dc 100644 --- a/inc/hgl/graph/vulkan/VKShaderModule.h +++ b/inc/hgl/graph/vulkan/VKShaderModule.h @@ -1,4 +1,4 @@ -#ifndef HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE +#ifndef HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE #define HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE #include"VK.h" @@ -7,13 +7,13 @@ VK_NAMESPACE_BEGIN -using ShaderBindingList=List; ///; /// - * ģṩԭʼshaderݺϢɱ޸ģֻͨShaderModuleManageɾ + * Shader模块
+ * 该模块提供的是原始的shader数据和信息,不可被修改,只能通过ShaderModuleManage创建和删除 */ class ShaderModule { @@ -57,14 +57,14 @@ public: return -1; } - const ShaderBindingList & GetUBOBindingList()const{return ubo_list;} ///<ȡUBO󶨵б + const ShaderBindingList & GetUBOBindingList()const{return ubo_list;} ///<取得UBO绑定点列表 };//class ShaderModule class VertexAttributeBinding; /** - * Shaderģ
- * ڶshaderǰִУshaderVertexInput + * 顶点Shader模块
+ * 由于顶点shader在最前方执行,所以它比其它shader多了VertexInput的数据 */ class VertexShaderModule:public ShaderModule { @@ -83,8 +83,10 @@ public: VertexShaderModule(VkDevice dev,int id,VkPipelineShaderStageCreateInfo *pssci,const ShaderParse *parse); virtual ~VertexShaderModule(); - const int GetLocation (const UTF8String &)const; - const int GetBinding (const UTF8String &)const; + /** + * 获取输入流绑定点,需要注意的时,这里获取的binding并非是shader中的binding/location,而是绑定顺序的序列号。对应vkCmdBindVertexBuffer的缓冲区序列号 + */ + const int GetStageInputBinding(const UTF8String &)const; const uint32_t GetAttrCount()const{return attr_count;} diff --git a/inc/hgl/graph/vulkan/VKVertexAttributeBinding.h b/inc/hgl/graph/vulkan/VKVertexAttributeBinding.h index 50270ca4..5f7ae60e 100644 --- a/inc/hgl/graph/vulkan/VKVertexAttributeBinding.h +++ b/inc/hgl/graph/vulkan/VKVertexAttributeBinding.h @@ -29,17 +29,17 @@ public: ~VertexAttributeBinding(); - const uint GetBinding(const UTF8String &name); ///<取得一个变量的绑定点 + const uint GetStageInputBinding(const UTF8String &name); ///<取得一个变量的绑定点 bool SetInstance(const uint binding,bool instance); bool SetStride (const uint binding,const uint32_t & stride); bool SetFormat (const uint binding,const VkFormat & format); bool SetOffset (const uint binding,const uint32_t offset); - bool SetInstance(const UTF8String &name,bool instance){return SetInstance(GetBinding(name),instance);} - bool SetStride (const UTF8String &name,const uint32_t &stride ){return SetStride (GetBinding(name),stride);} - bool SetFormat (const UTF8String &name,const VkFormat &format ){return SetFormat (GetBinding(name),format);} - bool SetOffset (const UTF8String &name,const uint32_t offset ){return SetOffset (GetBinding(name),offset);} + bool SetInstance(const UTF8String &name,bool instance){return SetInstance(GetStageInputBinding(name),instance);} + bool SetStride (const UTF8String &name,const uint32_t &stride ){return SetStride (GetStageInputBinding(name),stride);} + bool SetFormat (const UTF8String &name,const VkFormat &format ){return SetFormat (GetStageInputBinding(name),format);} + bool SetOffset (const UTF8String &name,const uint32_t offset ){return SetOffset (GetStageInputBinding(name),offset);} void Write(VkPipelineVertexInputStateCreateInfo &vis)const; };//class VertexAttributeBinding diff --git a/src/RenderDevice/Vulkan/VKMaterial.cpp b/src/RenderDevice/Vulkan/VKMaterial.cpp index f90925aa..fc3b7450 100644 --- a/src/RenderDevice/Vulkan/VKMaterial.cpp +++ b/src/RenderDevice/Vulkan/VKMaterial.cpp @@ -98,12 +98,13 @@ const int Material::GetUBOBinding(const UTF8String &name)const return(-1); } -const int Material::GetVBOBinding(const UTF8String &name)const -{ - if(!vertex_sm)return(-1); - - return vertex_sm->GetBinding(name); -} +//const int Material::GetSSBOBinding(const UTF8String &name)const +//{ +//} +// +//const int Material::GetINBOBinding(const UTF8String &name)const +//{ +//} const VkPipelineLayout Material::GetPipelineLayout()const { diff --git a/src/RenderDevice/Vulkan/VKRenderable.cpp b/src/RenderDevice/Vulkan/VKRenderable.cpp index fdba4b37..ebcb4e27 100644 --- a/src/RenderDevice/Vulkan/VKRenderable.cpp +++ b/src/RenderDevice/Vulkan/VKRenderable.cpp @@ -39,6 +39,6 @@ bool Renderable::Set(const int binding,VertexBuffer *vbo,VkDeviceSize offset) bool Renderable::Set(const UTF8String &name,VertexBuffer *vbo,VkDeviceSize offset) { - return Set(vertex_sm->GetBinding(name),vbo,offset); + return Set(vertex_sm->GetStageInputBinding(name),vbo,offset); } VK_NAMESPACE_END diff --git a/src/RenderDevice/Vulkan/VKShaderModule.cpp b/src/RenderDevice/Vulkan/VKShaderModule.cpp index 59631310..6c462262 100644 --- a/src/RenderDevice/Vulkan/VKShaderModule.cpp +++ b/src/RenderDevice/Vulkan/VKShaderModule.cpp @@ -84,19 +84,7 @@ VertexShaderModule::~VertexShaderModule() SAFE_CLEAR_ARRAY(attribute_list); } -const int VertexShaderModule::GetLocation(const UTF8String &name)const -{ - if(name.IsEmpty())return -1; - - VkVertexInputAttributeDescription *attr; - - if(!stage_input_locations.Get(name,attr)) - return -1; - - return attr->location; -} - -const int VertexShaderModule::GetBinding(const UTF8String &name)const +const int VertexShaderModule::GetStageInputBinding(const UTF8String &name)const { if(name.IsEmpty())return -1; diff --git a/src/RenderDevice/Vulkan/VKVertexAttributeBinding.cpp b/src/RenderDevice/Vulkan/VKVertexAttributeBinding.cpp index adbc75f4..5e2e383e 100644 --- a/src/RenderDevice/Vulkan/VKVertexAttributeBinding.cpp +++ b/src/RenderDevice/Vulkan/VKVertexAttributeBinding.cpp @@ -27,9 +27,9 @@ VertexAttributeBinding::~VertexAttributeBinding() vsm->Release(this); } -const uint VertexAttributeBinding::GetBinding(const UTF8String &name) +const uint VertexAttributeBinding::GetStageInputBinding(const UTF8String &name) { - return vsm->GetBinding(name); + return vsm->GetStageInputBinding(name); } bool VertexAttributeBinding::SetInstance(const uint index,bool instance)