将顶点输入流最终格式绑定放在MaterialInstance中,并改动相关类。
This commit is contained in:
parent
424b4b8a6f
commit
f55186a9c8
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit 021df224d02430159428c51c01883ce23ab4f03e
|
Subproject commit 463eb1dd7eb84ba9e3ed2e4cb1180a7c10186a7d
|
@ -1 +1 @@
|
|||||||
Subproject commit 4a244cf3f7aed607e6332ccd32bed3f465a667e9
|
Subproject commit 41b0c430ed3cc09384a59f3d29e6d6405b8a045d
|
@ -23,7 +23,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
};//struct ShaderStageBind
|
};//struct ShaderStageBind
|
||||||
|
|
||||||
using VADMaps=MapObject<AnsiString,ShaderStageBind>;
|
using ShaderStageBindMap=MapObject<AnsiString,ShaderStageBind>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可渲染对象创建器
|
* 可渲染对象创建器
|
||||||
@ -35,22 +35,18 @@ namespace hgl
|
|||||||
RenderResource *db;
|
RenderResource *db;
|
||||||
Material *mtl;
|
Material *mtl;
|
||||||
|
|
||||||
const VertexShaderModule *vsm;
|
const VAB *vab;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
uint32 vertices_number;
|
uint32 vertices_number;
|
||||||
|
|
||||||
IndexBuffer * ibo;
|
IndexBuffer * ibo;
|
||||||
VADMaps vab_maps;
|
ShaderStageBindMap ssb_map;
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
virtual VAD *CreateVAD(const AnsiString &name,const ShaderStage *ss); ///<创建一个顶点属性缓冲区
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RenderableCreater(RenderResource *sdb,Material *m);
|
RenderableCreater(RenderResource *sdb,const VAB *);
|
||||||
virtual ~RenderableCreater()=default;
|
virtual ~RenderableCreater()=default;
|
||||||
|
|
||||||
virtual bool Init(const uint32 count); ///<初始化,参数为顶点数量
|
virtual bool Init(const uint32 count); ///<初始化,参数为顶点数量
|
||||||
@ -60,12 +56,9 @@ namespace hgl
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
T * CreateVADA(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
|
T * CreateVADA(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
|
||||||
{
|
{
|
||||||
const ShaderStage *ss=vsm->GetStageInput(name);
|
const VkFormat format=vab->GetFormat(name);
|
||||||
|
|
||||||
if(!ss)
|
if(format!=T::GetVulkanFormat())
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
if(ss->format!=T::GetVulkanFormat())
|
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
VAD *vad=this->CreateVAD(name);
|
VAD *vad=this->CreateVAD(name);
|
||||||
|
@ -115,6 +115,18 @@ struct PipelineData;
|
|||||||
enum class InlinePipeline;
|
enum class InlinePipeline;
|
||||||
class Pipeline;
|
class Pipeline;
|
||||||
|
|
||||||
|
struct VAConfig
|
||||||
|
{
|
||||||
|
VkFormat format;
|
||||||
|
bool instance;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
CompOperatorMemcmp(const VAConfig &);
|
||||||
|
};
|
||||||
|
|
||||||
|
using VABConfigInfo=Map<AnsiString,VAConfig>;
|
||||||
|
|
||||||
class VertexAttributeBinding;
|
class VertexAttributeBinding;
|
||||||
using VAB=VertexAttributeBinding;
|
using VAB=VertexAttributeBinding;
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ public: //shader & material
|
|||||||
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
|
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
|
||||||
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *geometry_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
|
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *geometry_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
|
||||||
|
|
||||||
MaterialInstance *CreateMI(Material *);
|
MaterialInstance *CreateMI(Material *,const VABConfigInfo *vab_cfg=nullptr);
|
||||||
|
|
||||||
public: //Command Buffer 相关
|
public: //Command Buffer 相关
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include<hgl/type/Map.h>
|
#include<hgl/type/Map.h>
|
||||||
#include<hgl/type/String.h>
|
#include<hgl/type/String.h>
|
||||||
#include<hgl/graph/VKShaderModuleMap.h>
|
#include<hgl/graph/VKShaderModuleMap.h>
|
||||||
#include<hgl/graph/VKVertexAttributeBinding.h>
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
using ShaderStageCreateInfoList=List<VkPipelineShaderStageCreateInfo>;
|
using ShaderStageCreateInfoList=List<VkPipelineShaderStageCreateInfo>;
|
||||||
|
|
||||||
@ -17,7 +16,6 @@ struct MaterialData
|
|||||||
MaterialDescriptorSets *mds;
|
MaterialDescriptorSets *mds;
|
||||||
|
|
||||||
VertexShaderModule *vertex_sm;
|
VertexShaderModule *vertex_sm;
|
||||||
VertexAttributeBinding *vab;
|
|
||||||
|
|
||||||
ShaderStageCreateInfoList shader_stage_list;
|
ShaderStageCreateInfoList shader_stage_list;
|
||||||
|
|
||||||
@ -56,7 +54,7 @@ public:
|
|||||||
|
|
||||||
const UTF8String & GetName ()const{return data->name;}
|
const UTF8String & GetName ()const{return data->name;}
|
||||||
|
|
||||||
const VertexShaderModule * GetVertexShaderModule ()const{return data->vertex_sm;}
|
VertexShaderModule * GetVertexShaderModule () {return data->vertex_sm;}
|
||||||
|
|
||||||
const ShaderStageCreateInfoList & GetStageList ()const{return data->shader_stage_list;}
|
const ShaderStageCreateInfoList & GetStageList ()const{return data->shader_stage_list;}
|
||||||
|
|
||||||
@ -64,8 +62,6 @@ public:
|
|||||||
const VkPipelineLayout GetPipelineLayout ()const;
|
const VkPipelineLayout GetPipelineLayout ()const;
|
||||||
const PipelineLayoutData * GetPipelineLayoutData ()const{return data->pipeline_layout_data;}
|
const PipelineLayoutData * GetPipelineLayoutData ()const{return data->pipeline_layout_data;}
|
||||||
|
|
||||||
const VertexAttributeBinding * GetVAB ()const{return data->vab;}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MaterialParameters * GetMP (const DescriptorSetsType &type)
|
MaterialParameters * GetMP (const DescriptorSetsType &type)
|
||||||
|
@ -8,13 +8,15 @@ class MaterialInstance
|
|||||||
{
|
{
|
||||||
Material *material;
|
Material *material;
|
||||||
|
|
||||||
|
VAB *vab;
|
||||||
|
|
||||||
MaterialParameters *mp_value;
|
MaterialParameters *mp_value;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend class GPUDevice;
|
friend class GPUDevice;
|
||||||
|
|
||||||
MaterialInstance(Material *,MaterialParameters *);
|
MaterialInstance(Material *,VAB *,MaterialParameters *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -22,6 +24,7 @@ public:
|
|||||||
|
|
||||||
Material *GetMaterial(){return material;}
|
Material *GetMaterial(){return material;}
|
||||||
|
|
||||||
|
const VAB *GetVAB()const{return vab;}
|
||||||
MaterialParameters *GetMP(){return mp_value;}
|
MaterialParameters *GetMP(){return mp_value;}
|
||||||
MaterialParameters *GetMP(const DescriptorSetsType &type);
|
MaterialParameters *GetMP(const DescriptorSetsType &type);
|
||||||
};//class MaterialInstance
|
};//class MaterialInstance
|
||||||
|
@ -35,6 +35,8 @@ public:
|
|||||||
|
|
||||||
operator VkPipeline(){return pipeline;}
|
operator VkPipeline(){return pipeline;}
|
||||||
|
|
||||||
|
const VAB *GetVAB()const{return data->GetVAB();}
|
||||||
|
|
||||||
const bool IsAlphaTest()const{return data->alpha_test>0;}
|
const bool IsAlphaTest()const{return data->alpha_test>0;}
|
||||||
const bool IsAlphaBlend()const{return data->alpha_blend;}
|
const bool IsAlphaBlend()const{return data->alpha_blend;}
|
||||||
};//class GraphicsPipeline
|
};//class GraphicsPipeline
|
||||||
|
@ -52,16 +52,13 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Pipeline *CreatePipeline(const Material *, PipelineData *);
|
Pipeline *CreatePipeline(MaterialInstance *, PipelineData *);
|
||||||
Pipeline *CreatePipeline(const Material *,const InlinePipeline &);
|
Pipeline *CreatePipeline(MaterialInstance *,const InlinePipeline &);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Pipeline *CreatePipeline(Material *, const InlinePipeline &, const Prim &prim,const bool prim_restart=false);
|
|
||||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &prim,const bool prim_restart=false);
|
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &prim,const bool prim_restart=false);
|
||||||
Pipeline *CreatePipeline(Material *, PipelineData *, const Prim &prim,const bool prim_restart=false);
|
|
||||||
Pipeline *CreatePipeline(MaterialInstance *, PipelineData *, const Prim &prim,const bool prim_restart=false);
|
Pipeline *CreatePipeline(MaterialInstance *, PipelineData *, const Prim &prim,const bool prim_restart=false);
|
||||||
Pipeline *CreatePipeline(Material *, const OSString &, const Prim &prim,const bool prim_restart=false);
|
|
||||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &prim,const bool prim_restart=false);
|
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &prim,const bool prim_restart=false);
|
||||||
};//class RenderPass
|
};//class RenderPass
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -14,17 +14,17 @@ VK_NAMESPACE_BEGIN
|
|||||||
*/
|
*/
|
||||||
class Renderable
|
class Renderable
|
||||||
{
|
{
|
||||||
struct VABData
|
struct VBOData
|
||||||
{
|
{
|
||||||
VBO *buf;
|
VBO *buf;
|
||||||
VkDeviceSize offset;
|
VkDeviceSize offset;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CompOperatorMemcmp(const VABData &);
|
CompOperatorMemcmp(const VBOData &);
|
||||||
};
|
};
|
||||||
|
|
||||||
Map<UTF8String,VABData> buffer_list;
|
Map<AnsiString,VBOData> buffer_list;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public:
|
|||||||
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
|
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
|
||||||
const AABB &GetBoundingBox()const {return BoundingBox;}
|
const AABB &GetBoundingBox()const {return BoundingBox;}
|
||||||
|
|
||||||
bool Set(const UTF8String &name,VBO *vb,VkDeviceSize offset=0);
|
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
|
||||||
|
|
||||||
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
|
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
|
||||||
{
|
{
|
||||||
@ -78,8 +78,8 @@ public:
|
|||||||
return draw_count;
|
return draw_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
VBO * GetVBO (const UTF8String &,VkDeviceSize *);
|
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
|
||||||
VkBuffer GetBuffer (const UTF8String &,VkDeviceSize *);
|
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
|
||||||
const int GetBufferCount ()const {return buffer_list.GetCount();}
|
const int GetBufferCount ()const {return buffer_list.GetCount();}
|
||||||
|
|
||||||
IndexBuffer * GetIndexBuffer () {return indices_buffer;}
|
IndexBuffer * GetIndexBuffer () {return indices_buffer;}
|
||||||
|
@ -47,8 +47,6 @@ public:
|
|||||||
const VkPipelineShaderStageCreateInfo * GetCreateInfo ()const{return stage_create_info;}
|
const VkPipelineShaderStageCreateInfo * GetCreateInfo ()const{return stage_create_info;}
|
||||||
};//class ShaderModule
|
};//class ShaderModule
|
||||||
|
|
||||||
class VertexAttributeBinding;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 顶点Shader模块<br>
|
* 顶点Shader模块<br>
|
||||||
* 由于顶点shader在最前方执行,所以它比其它shader多了VertexInput的数据
|
* 由于顶点shader在最前方执行,所以它比其它shader多了VertexInput的数据
|
||||||
@ -56,12 +54,13 @@ class VertexAttributeBinding;
|
|||||||
class VertexShaderModule:public ShaderModule
|
class VertexShaderModule:public ShaderModule
|
||||||
{
|
{
|
||||||
uint32_t attr_count;
|
uint32_t attr_count;
|
||||||
VkVertexInputBindingDescription *binding_list;
|
VertexAttribType *type_list;
|
||||||
VkVertexInputAttributeDescription *attribute_list;
|
const AnsiString **name_list;
|
||||||
|
ShaderStage **ssi_list;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Sets<VertexAttributeBinding *> vab_sets;
|
Sets<VAB *> vab_sets;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -76,17 +75,17 @@ public:
|
|||||||
const uint GetStageInputCount () const{return shader_resource->GetStageInputCount();}
|
const uint GetStageInputCount () const{return shader_resource->GetStageInputCount();}
|
||||||
const ShaderStageList & GetStageInputs () const{return shader_resource->GetStageInputs();}
|
const ShaderStageList & GetStageInputs () const{return shader_resource->GetStageInputs();}
|
||||||
|
|
||||||
const uint32_t GetAttrCount()const{return attr_count;}
|
//const uint32_t GetAttrCount()const{return attr_count;}
|
||||||
|
|
||||||
const VkVertexInputBindingDescription * GetDescList ()const{return binding_list;}
|
//const VkVertexInputBindingDescription * GetDescList ()const{return binding_list;}
|
||||||
const VkVertexInputAttributeDescription * GetAttrList ()const{return attribute_list;}
|
//const VkVertexInputAttributeDescription * GetAttrList ()const{return attribute_list;}
|
||||||
|
|
||||||
const VkVertexInputBindingDescription * GetDesc (const uint32_t index)const{return (index>=attr_count?nullptr:binding_list+index);}
|
//const VkVertexInputBindingDescription * GetDesc (const uint32_t index)const{return (index>=attr_count?nullptr:binding_list+index);}
|
||||||
const VkVertexInputAttributeDescription * GetAttr (const uint32_t index)const{return (index>=attr_count?nullptr:attribute_list+index);}
|
//const VkVertexInputAttributeDescription * GetAttr (const uint32_t index)const{return (index>=attr_count?nullptr:attribute_list+index);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VAB * CreateVAB();
|
VAB * CreateVAB(const VABConfigInfo *format_map=nullptr);
|
||||||
bool Release(VAB *);
|
bool Release(VAB *);
|
||||||
const uint32_t GetInstanceCount()const{return vab_sets.GetCount();}
|
const uint32_t GetInstanceCount()const{return vab_sets.GetCount();}
|
||||||
};//class VertexShaderModule:public ShaderModule
|
};//class VertexShaderModule:public ShaderModule
|
||||||
|
@ -14,7 +14,6 @@ struct ShaderStage
|
|||||||
uint location;
|
uint location;
|
||||||
|
|
||||||
VertexAttribType type; ///<成份数量(如vec4中的4)
|
VertexAttribType type; ///<成份数量(如vec4中的4)
|
||||||
VkFormat format; ///<对应的Vulkan格式(如vec4对应的FMT_RGBA32F)
|
|
||||||
|
|
||||||
uint binding;
|
uint binding;
|
||||||
|
|
||||||
|
@ -69,11 +69,12 @@ namespace hgl
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据格式要求,创建对应的顶点属性数据区(VAD)
|
* 根据格式要求,创建对应的顶点属性数据区(VAD)
|
||||||
* @param base_type 基础格式
|
|
||||||
* @param vecsize vec数量
|
|
||||||
* @param vertex_count 顶点数量
|
* @param vertex_count 顶点数量
|
||||||
|
* @param fmt Vulkan格式
|
||||||
|
* @param vec_size vec数量
|
||||||
|
* @param stride 单个数据字节数
|
||||||
*/
|
*/
|
||||||
VAD *CreateVertexAttribData(const VertexAttribType *,const uint32_t vertex_count);
|
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VkFormat fmt,const int vec_size,const uint stride);
|
||||||
//这个函数比较重要,就不搞成CreateVAD的简写了
|
//这个函数比较重要,就不搞成CreateVAD的简写了
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -5,11 +5,10 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
RenderableCreater::RenderableCreater(RenderResource *sdb,Material *m)
|
RenderableCreater::RenderableCreater(RenderResource *sdb,const VAB *v)
|
||||||
{
|
{
|
||||||
db =sdb;
|
db =sdb;
|
||||||
mtl =m;
|
vab =v;
|
||||||
vsm =mtl->GetVertexShaderModule();
|
|
||||||
|
|
||||||
vertices_number =0;
|
vertices_number =0;
|
||||||
ibo =nullptr;
|
ibo =nullptr;
|
||||||
@ -24,70 +23,64 @@ namespace hgl
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
VAD *RenderableCreater::CreateVAD(const AnsiString &name,const ShaderStage *ss)
|
VAD *RenderableCreater::CreateVAD(const AnsiString &name)
|
||||||
{
|
{
|
||||||
if(!ss)return(nullptr);
|
if(!vab)return(nullptr);
|
||||||
|
if(name.IsEmpty())return(nullptr);
|
||||||
|
|
||||||
|
const auto *va=vab->GetVertexAttribute(name);
|
||||||
|
|
||||||
|
if(!va)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
ShaderStageBind *ssb;
|
ShaderStageBind *ssb;
|
||||||
|
|
||||||
if(vab_maps.Get(name,ssb))
|
if(ssb_map.Get(name,ssb))
|
||||||
return ssb->data;
|
return ssb->data;
|
||||||
|
|
||||||
ssb=new ShaderStageBind;
|
ssb=new ShaderStageBind;
|
||||||
|
|
||||||
ssb->data =hgl::graph::CreateVertexAttribData(&(ss->type),vertices_number);
|
ssb->data =hgl::graph::CreateVertexAttribData(vertices_number,va->format,va->vec_size,va->stride);
|
||||||
ssb->name =name;
|
ssb->name =name;
|
||||||
ssb->binding=ss->binding;
|
ssb->binding=va->binding;
|
||||||
|
|
||||||
ssb->vbo =nullptr;
|
ssb->vbo =nullptr;
|
||||||
|
|
||||||
vab_maps.Add(name,ssb);
|
ssb_map.Add(name,ssb);
|
||||||
|
|
||||||
return ssb->data;
|
return ssb->data;
|
||||||
}
|
|
||||||
|
|
||||||
VAD *RenderableCreater::CreateVAD(const AnsiString &name)
|
|
||||||
{
|
|
||||||
if(!vsm)return(nullptr);
|
|
||||||
if(name.IsEmpty())return(nullptr);
|
|
||||||
|
|
||||||
const ShaderStage *ss=vsm->GetStageInput(name);
|
|
||||||
|
|
||||||
if(!ss)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
return this->CreateVAD(name,ss);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderableCreater::WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes)
|
bool RenderableCreater::WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes)
|
||||||
{
|
{
|
||||||
if(!vsm)return(false);
|
if(!vab)return(false);
|
||||||
if(name.IsEmpty())return(false);
|
if(name.IsEmpty())return(false);
|
||||||
if(!data)return(false);
|
if(!data)return(false);
|
||||||
if(!bytes)return(false);
|
if(!bytes)return(false);
|
||||||
|
|
||||||
ShaderStageBind *ssb;
|
ShaderStageBind *ssb;
|
||||||
|
|
||||||
if(vab_maps.Get(name,ssb))
|
if(ssb_map.Get(name,ssb))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const ShaderStage *ss=vsm->GetStageInput(name);
|
const auto *va=vab->GetVertexAttribute(name);
|
||||||
|
|
||||||
if(!ss)
|
if(!va)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(ss->type.GetStride()*vertices_number!=bytes)
|
if(va->stride*vertices_number!=bytes)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
ssb=new ShaderStageBind;
|
ssb=new ShaderStageBind;
|
||||||
|
|
||||||
ssb->data =nullptr;
|
ssb->data =nullptr;
|
||||||
ssb->name =name;
|
ssb->name =name;
|
||||||
ssb->binding=ss->binding;
|
ssb->binding=va->binding;
|
||||||
|
|
||||||
ssb->vbo =db->CreateVBO(ss->format,vertices_number,data);
|
ssb->vbo =db->CreateVBO(va->format,vertices_number,data);
|
||||||
|
|
||||||
vab_maps.Add(name,ssb);
|
ssb_map.Add(name,ssb);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -110,14 +103,14 @@ namespace hgl
|
|||||||
|
|
||||||
Renderable *RenderableCreater::Finish()
|
Renderable *RenderableCreater::Finish()
|
||||||
{
|
{
|
||||||
const uint si_count=vsm->GetStageInputCount();
|
const uint si_count=vab->GetVertexAttrCount();
|
||||||
|
|
||||||
if(vab_maps.GetCount()!=si_count)
|
if(ssb_map.GetCount()!=si_count)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
Renderable *render_obj=db->CreateRenderable(vertices_number);
|
Renderable *render_obj=db->CreateRenderable(vertices_number);
|
||||||
|
|
||||||
const auto *sp=vab_maps.GetDataList();
|
const auto *sp=ssb_map.GetDataList();
|
||||||
for(uint i=0;i<si_count;i++)
|
for(uint i=0;i<si_count;i++)
|
||||||
{
|
{
|
||||||
if((*sp)->right->vbo)
|
if((*sp)->right->vbo)
|
||||||
|
@ -4,14 +4,15 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
VAD *CreateVertexAttribData(const VertexAttribType *type,const uint32_t vertex_count)
|
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VkFormat fmt,const int vec_size,const uint stride)
|
||||||
{
|
{
|
||||||
if(!type||!type->Check())
|
if(!vertex_count<=0
|
||||||
|
||vec_size<1||vec_size>4
|
||||||
|
||stride<1||stride>8*4
|
||||||
|
||CheckVulkanFormat(fmt))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
VkFormat fmt=GetVulkanFormat(type);
|
return(new VertexAttribData(vertex_count,vec_size,stride,fmt));
|
||||||
|
|
||||||
return(new VertexAttribData(vertex_count,type->vec_size,type->GetStride(),fmt));
|
|
||||||
}
|
}
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -104,7 +104,6 @@ Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *
|
|||||||
data->shader_maps =shader_maps;
|
data->shader_maps =shader_maps;
|
||||||
data->mds =mds;
|
data->mds =mds;
|
||||||
data->vertex_sm =(VertexShaderModule *)vsm;
|
data->vertex_sm =(VertexShaderModule *)vsm;
|
||||||
data->vab =data->vertex_sm->CreateVAB();
|
|
||||||
|
|
||||||
CreateShaderStageList(data->shader_stage_list,shader_maps);
|
CreateShaderStageList(data->shader_stage_list,shader_maps);
|
||||||
|
|
||||||
|
@ -9,12 +9,6 @@ MaterialData::~MaterialData()
|
|||||||
SAFE_CLEAR(mp.r);
|
SAFE_CLEAR(mp.r);
|
||||||
SAFE_CLEAR(mp.g);
|
SAFE_CLEAR(mp.g);
|
||||||
|
|
||||||
if(vab)
|
|
||||||
{
|
|
||||||
vertex_sm->Release(vab);
|
|
||||||
delete vab;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete shader_maps;
|
delete shader_maps;
|
||||||
SAFE_CLEAR(mds);
|
SAFE_CLEAR(mds);
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,36 @@
|
|||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialInstance.h>
|
||||||
#include<hgl/graph/VKMaterial.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
#include<hgl/graph/VKMaterialParameters.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
|
#include<hgl/graph/VKShaderModule.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
MaterialInstance *GPUDevice::CreateMI(Material *mtl)
|
MaterialInstance *GPUDevice::CreateMI(Material *mtl,const VABConfigInfo *vab_cfg)
|
||||||
{
|
{
|
||||||
if(!mtl)return(nullptr);
|
if(!mtl)return(nullptr);
|
||||||
|
|
||||||
|
VertexShaderModule *vsm=mtl->GetVertexShaderModule();
|
||||||
|
|
||||||
|
VAB *vab=vsm->CreateVAB(vab_cfg);
|
||||||
|
|
||||||
|
if(!vab)return(nullptr);
|
||||||
|
|
||||||
MaterialParameters *mp=CreateMP(mtl,DescriptorSetsType::Value);
|
MaterialParameters *mp=CreateMP(mtl,DescriptorSetsType::Value);
|
||||||
|
|
||||||
return(new MaterialInstance(mtl,mp));
|
if(!mp)
|
||||||
|
{
|
||||||
|
delete vab;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(new MaterialInstance(mtl,vab,mp));
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialInstance::MaterialInstance(Material *mtl,MaterialParameters *p)
|
MaterialInstance::MaterialInstance(Material *mtl,VAB *v,MaterialParameters *p)
|
||||||
{
|
{
|
||||||
material=mtl;
|
material=mtl;
|
||||||
|
|
||||||
|
vab=v;
|
||||||
|
|
||||||
mp_value=p;
|
mp_value=p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,16 +23,18 @@ RenderPass::~RenderPass()
|
|||||||
vkDestroyRenderPass(device,render_pass,nullptr);
|
vkDestroyRenderPass(device,render_pass,nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pipeline *RenderPass::CreatePipeline(const Material *material,PipelineData *data)
|
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,PipelineData *data)
|
||||||
{
|
{
|
||||||
VkPipeline graphicsPipeline;
|
VkPipeline graphicsPipeline;
|
||||||
|
|
||||||
data->InitShaderStage(material->GetStageList());
|
Material *mtl=mi->GetMaterial();
|
||||||
data->InitVertexInputState(material->GetVAB());
|
|
||||||
|
data->InitShaderStage(mtl->GetStageList());
|
||||||
|
data->InitVertexInputState(mi->GetVAB());
|
||||||
|
|
||||||
data->SetColorAttachments(color_formats.GetCount());
|
data->SetColorAttachments(color_formats.GetCount());
|
||||||
|
|
||||||
data->pipeline_info.layout = material->GetPipelineLayout();
|
data->pipeline_info.layout = mtl->GetPipelineLayout();
|
||||||
|
|
||||||
{
|
{
|
||||||
data->pipeline_info.renderPass = render_pass;
|
data->pipeline_info.renderPass = render_pass;
|
||||||
@ -49,24 +51,24 @@ Pipeline *RenderPass::CreatePipeline(const Material *material,PipelineData *data
|
|||||||
return(new Pipeline(device,graphicsPipeline,data));
|
return(new Pipeline(device,graphicsPipeline,data));
|
||||||
}
|
}
|
||||||
|
|
||||||
Pipeline *RenderPass::CreatePipeline(const Material *mtl,const InlinePipeline &ip)
|
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const InlinePipeline &ip)
|
||||||
{
|
{
|
||||||
PipelineData *pd=GetPipelineData(ip);
|
PipelineData *pd=GetPipelineData(ip);
|
||||||
|
|
||||||
if(!pd)return(nullptr);
|
if(!pd)return(nullptr);
|
||||||
|
|
||||||
return CreatePipeline(mtl,pd);
|
return CreatePipeline(mi,pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pipeline *RenderPass::CreatePipeline(Material *mtl,const InlinePipeline &ip,const Prim &prim,const bool prim_restart)
|
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const InlinePipeline &ip,const Prim &prim,const bool prim_restart)
|
||||||
{
|
{
|
||||||
if(!mtl)return(nullptr);
|
if(!mi)return(nullptr);
|
||||||
|
|
||||||
PipelineData *pd=GetPipelineData(ip);
|
PipelineData *pd=GetPipelineData(ip);
|
||||||
|
|
||||||
pd->Set(prim,prim_restart);
|
pd->Set(prim,prim_restart);
|
||||||
|
|
||||||
Pipeline *p=CreatePipeline(mtl,pd);
|
Pipeline *p=CreatePipeline(mi,pd);
|
||||||
|
|
||||||
if(p)
|
if(p)
|
||||||
pipeline_list.Add(p);
|
pipeline_list.Add(p);
|
||||||
@ -74,18 +76,11 @@ Pipeline *RenderPass::CreatePipeline(Material *mtl,const InlinePipeline &ip,cons
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const InlinePipeline &ip,const Prim &prim,const bool prim_restart)
|
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,PipelineData *pd,const Prim &prim,const bool prim_restart)
|
||||||
{
|
|
||||||
if(!mi)return(nullptr);
|
|
||||||
|
|
||||||
return CreatePipeline(mi->GetMaterial(),ip,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *RenderPass::CreatePipeline(Material *mtl,PipelineData *pd,const Prim &prim,const bool prim_restart)
|
|
||||||
{
|
{
|
||||||
pd->Set(prim,prim_restart);
|
pd->Set(prim,prim_restart);
|
||||||
|
|
||||||
Pipeline *p=CreatePipeline(mtl,pd);
|
Pipeline *p=CreatePipeline(mi,pd);
|
||||||
|
|
||||||
if(p)
|
if(p)
|
||||||
pipeline_list.Add(p);
|
pipeline_list.Add(p);
|
||||||
@ -93,22 +88,12 @@ Pipeline *RenderPass::CreatePipeline(Material *mtl,PipelineData *pd,const Prim &
|
|||||||
return(p);
|
return(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,PipelineData *pd,const Prim &prim,const bool prim_restart)
|
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const OSString &pipeline_filename,const Prim &prim,const bool prim_restart)
|
||||||
{
|
|
||||||
return CreatePipeline(mi->GetMaterial(),pd,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *RenderPass::CreatePipeline(Material *mtl,const OSString &pipeline_filename,const Prim &prim,const bool prim_restart)
|
|
||||||
{
|
{
|
||||||
PipelineData *pd=GetPipelineData(pipeline_filename);
|
PipelineData *pd=GetPipelineData(pipeline_filename);
|
||||||
|
|
||||||
if(!pd)return(nullptr);
|
if(!pd)return(nullptr);
|
||||||
|
|
||||||
return CreatePipeline(mtl,pd,prim,prim_restart);
|
return CreatePipeline(mi,pd,prim,prim_restart);
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const OSString &filename,const Prim &prim,const bool prim_restart)
|
|
||||||
{
|
|
||||||
return CreatePipeline(mi->GetMaterial(),filename,prim,prim_restart);
|
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -22,12 +22,12 @@ VK_NAMESPACE_BEGIN
|
|||||||
// return(true);
|
// return(true);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
bool Renderable::Set(const UTF8String &name,VBO *vbo,VkDeviceSize offset)
|
bool Renderable::Set(const AnsiString &name,VBO *vbo,VkDeviceSize offset)
|
||||||
{
|
{
|
||||||
if(!vbo)return(false);
|
if(!vbo)return(false);
|
||||||
if(buffer_list.KeyExist(name))return(false);
|
if(buffer_list.KeyExist(name))return(false);
|
||||||
|
|
||||||
VABData bd;
|
VBOData bd;
|
||||||
|
|
||||||
bd.buf=vbo;
|
bd.buf=vbo;
|
||||||
bd.offset=offset;
|
bd.offset=offset;
|
||||||
@ -36,12 +36,12 @@ bool Renderable::Set(const UTF8String &name,VBO *vbo,VkDeviceSize offset)
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
VBO *Renderable::GetVBO(const UTF8String &name,VkDeviceSize *offset)
|
VBO *Renderable::GetVBO(const AnsiString &name,VkDeviceSize *offset)
|
||||||
{
|
{
|
||||||
if(!offset)return(nullptr);
|
if(!offset)return(nullptr);
|
||||||
if(name.IsEmpty())return(nullptr);
|
if(name.IsEmpty())return(nullptr);
|
||||||
|
|
||||||
VABData bd;
|
VBOData bd;
|
||||||
|
|
||||||
if(buffer_list.Get(name,bd))
|
if(buffer_list.Get(name,bd))
|
||||||
{
|
{
|
||||||
@ -52,7 +52,7 @@ VBO *Renderable::GetVBO(const UTF8String &name,VkDeviceSize *offset)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
VkBuffer Renderable::GetBuffer(const UTF8String &name,VkDeviceSize *offset)
|
VkBuffer Renderable::GetBuffer(const AnsiString &name,VkDeviceSize *offset)
|
||||||
{
|
{
|
||||||
VBO *vbo=GetVBO(name,offset);
|
VBO *vbo=GetVBO(name,offset);
|
||||||
|
|
||||||
|
@ -34,19 +34,15 @@ RenderableInstance::~RenderableInstance()
|
|||||||
|
|
||||||
RenderableInstance *CreateRenderableInstance(Renderable *r,MaterialInstance *mi,Pipeline *p)
|
RenderableInstance *CreateRenderableInstance(Renderable *r,MaterialInstance *mi,Pipeline *p)
|
||||||
{
|
{
|
||||||
if(!r||!mi||!p)return(nullptr);
|
if(!r||!p)return(nullptr);
|
||||||
|
|
||||||
const Material *mtl=mi->GetMaterial();
|
const VAB *vab=p->GetVAB();
|
||||||
|
const int input_count=vab->GetVertexAttrCount();
|
||||||
if(!mtl)return(nullptr);
|
const UTF8String &mtl_name=mi->GetMaterial()->GetName();
|
||||||
|
|
||||||
const VertexShaderModule *vsm=mtl->GetVertexShaderModule();
|
|
||||||
const ShaderStageList &ssl=vsm->GetStageInputs();
|
|
||||||
const int input_count=ssl.GetCount();
|
|
||||||
|
|
||||||
if(r->GetBufferCount()<input_count) //小于材质要求的数量?那自然是不行的
|
if(r->GetBufferCount()<input_count) //小于材质要求的数量?那自然是不行的
|
||||||
{
|
{
|
||||||
LOG_ERROR("[FATAL ERROR] input buffer count of Renderable lesser than Material, Material name: "+mtl->GetName());
|
LOG_ERROR("[FATAL ERROR] input buffer count of Renderable lesser than Material, Material name: "+mtl_name);
|
||||||
|
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
@ -54,40 +50,36 @@ RenderableInstance *CreateRenderableInstance(Renderable *r,MaterialInstance *mi,
|
|||||||
AutoDeleteArray<VkBuffer> buffer_list(input_count);
|
AutoDeleteArray<VkBuffer> buffer_list(input_count);
|
||||||
AutoDeleteArray<VkDeviceSize> buffer_size(input_count);
|
AutoDeleteArray<VkDeviceSize> buffer_size(input_count);
|
||||||
|
|
||||||
ShaderStage **ss=ssl.GetData();
|
|
||||||
|
|
||||||
VBO *vbo;
|
VBO *vbo;
|
||||||
const VkVertexInputBindingDescription *desc;
|
const AnsiString ** name_list=vab->GetVertexNameList();
|
||||||
const VkVertexInputAttributeDescription *attr;
|
const VkVertexInputBindingDescription * bind_list=vab->GetVertexBindingList();
|
||||||
|
const VkVertexInputAttributeDescription * attr_list=vab->GetVertexAttributeList();
|
||||||
|
|
||||||
for(int i=0;i<input_count;i++)
|
for(int i=0;i<input_count;i++)
|
||||||
{
|
{
|
||||||
desc=vsm->GetDesc(i);
|
vbo=r->GetVBO(**name_list,buffer_size+i);
|
||||||
attr=vsm->GetAttr(i);
|
|
||||||
|
|
||||||
vbo=r->GetVBO((*ss)->name,buffer_size+i);
|
|
||||||
|
|
||||||
if(!vbo)
|
if(!vbo)
|
||||||
{
|
{
|
||||||
LOG_ERROR("[FATAL ERROR] can't find VBO \""+(*ss)->name+"\" in Material: "+mtl->GetName());
|
LOG_ERROR("[FATAL ERROR] can't find VBO \""+**name_list+"\" in Material: "+mtl_name);
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(vbo->GetFormat()!=attr->format)
|
if(vbo->GetFormat()!=attr_list->format)
|
||||||
{
|
{
|
||||||
LOG_ERROR( "[FATAL ERROR] VBO \""+(*ss)->name+
|
LOG_ERROR( "[FATAL ERROR] VBO \""+**name_list+
|
||||||
UTF8String("\" format can't match Renderable, Material(")+mtl->GetName()+
|
UTF8String("\" format can't match Renderable, Material(")+mtl_name+
|
||||||
UTF8String(") Format(")+GetVulkanFormatName(attr->format)+
|
UTF8String(") Format(")+GetVulkanFormatName(attr_list->format)+
|
||||||
UTF8String("), VBO Format(")+GetVulkanFormatName(vbo->GetFormat())+
|
UTF8String("), VBO Format(")+GetVulkanFormatName(vbo->GetFormat())+
|
||||||
")");
|
")");
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(vbo->GetStride()!=desc->stride)
|
if(vbo->GetStride()!=bind_list->stride)
|
||||||
{
|
{
|
||||||
LOG_ERROR( "[FATAL ERROR] VBO \""+(*ss)->name+
|
LOG_ERROR( "[FATAL ERROR] VBO \""+**name_list+
|
||||||
UTF8String("\" stride can't match Renderable, Material(")+mtl->GetName()+
|
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
|
||||||
UTF8String(") stride(")+UTF8String::valueOf(desc->stride)+
|
UTF8String(") stride(")+UTF8String::valueOf(bind_list->stride)+
|
||||||
UTF8String("), VBO stride(")+UTF8String::valueOf(vbo->GetStride())+
|
UTF8String("), VBO stride(")+UTF8String::valueOf(vbo->GetStride())+
|
||||||
")");
|
")");
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
@ -95,7 +87,9 @@ RenderableInstance *CreateRenderableInstance(Renderable *r,MaterialInstance *mi,
|
|||||||
|
|
||||||
buffer_list[i]=vbo->GetBuffer();
|
buffer_list[i]=vbo->GetBuffer();
|
||||||
|
|
||||||
++ss;
|
++name_list;
|
||||||
|
++bind_list;
|
||||||
|
++attr_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderableInstance *ri=new RenderableInstance(r,mi,p,input_count,buffer_list,buffer_size);
|
RenderableInstance *ri=new RenderableInstance(r,mi,p,input_count,buffer_list,buffer_size);
|
||||||
|
@ -38,42 +38,23 @@ ShaderModule::~ShaderModule()
|
|||||||
{
|
{
|
||||||
vkDestroyShaderModule(device,stage_create_info->module,nullptr);
|
vkDestroyShaderModule(device,stage_create_info->module,nullptr);
|
||||||
//这里不用删除stage_create_info,材质中会删除的
|
//这里不用删除stage_create_info,材质中会删除的
|
||||||
|
|
||||||
|
SAFE_CLEAR(shader_resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexShaderModule::VertexShaderModule(VkDevice dev,VkPipelineShaderStageCreateInfo *pssci,ShaderResource *sr):ShaderModule(dev,pssci,sr)
|
VertexShaderModule::VertexShaderModule(VkDevice dev,VkPipelineShaderStageCreateInfo *pssci,ShaderResource *sr):ShaderModule(dev,pssci,sr)
|
||||||
{
|
{
|
||||||
const ShaderStageList &stage_inputs=sr->GetStageInputs();
|
const ShaderStageList &stage_input_list=sr->GetStageInputs();
|
||||||
|
|
||||||
attr_count=stage_inputs.GetCount();
|
attr_count=stage_input_list.GetCount();
|
||||||
binding_list=new VkVertexInputBindingDescription[attr_count];
|
ssi_list=stage_input_list.GetData();
|
||||||
attribute_list=new VkVertexInputAttributeDescription[attr_count];
|
name_list=new const AnsiString *[attr_count];
|
||||||
|
type_list=new VertexAttribType[attr_count];
|
||||||
VkVertexInputBindingDescription *bind=binding_list;
|
|
||||||
VkVertexInputAttributeDescription *attr=attribute_list;
|
|
||||||
|
|
||||||
ShaderStage **si=stage_inputs.GetData();
|
|
||||||
|
|
||||||
for(uint i=0;i<attr_count;i++)
|
for(uint i=0;i<attr_count;i++)
|
||||||
{
|
{
|
||||||
bind->binding =i; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号,所以这个数字必须从0开始,而且紧密排列。
|
name_list[i]=&(ssi_list[i]->name);
|
||||||
//在VertexInput类中,buf_list需要严格按照本此binding为序列号排列
|
type_list[i]= ssi_list[i]->type;
|
||||||
bind->stride =GetStrideByFormat((*si)->format);
|
|
||||||
bind->inputRate =VK_VERTEX_INPUT_RATE_VERTEX;
|
|
||||||
|
|
||||||
//binding对应的是第几个数据输入流
|
|
||||||
//实际使用一个binding可以绑定多个attrib
|
|
||||||
//比如在一个流中传递{pos,color}这样两个数据,就需要两个attrib
|
|
||||||
//但在我们的设计中,仅支持一个流传递一个attrib
|
|
||||||
|
|
||||||
attr->binding =i;
|
|
||||||
attr->location =(*si)->location; //此值对应shader中的layout(location=
|
|
||||||
attr->format =(*si)->format;
|
|
||||||
attr->offset =0;
|
|
||||||
|
|
||||||
++attr;
|
|
||||||
++bind;
|
|
||||||
|
|
||||||
++si;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,13 +65,56 @@ VertexShaderModule::~VertexShaderModule()
|
|||||||
//还有在用的,这是个错误
|
//还有在用的,这是个错误
|
||||||
}
|
}
|
||||||
|
|
||||||
SAFE_CLEAR_ARRAY(binding_list);
|
delete[] type_list;
|
||||||
SAFE_CLEAR_ARRAY(attribute_list);
|
delete[] name_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
VAB *VertexShaderModule::CreateVAB()
|
VAB *VertexShaderModule::CreateVAB(const VABConfigInfo *cfg)
|
||||||
{
|
{
|
||||||
VAB *vab=new VAB(attr_count,binding_list,attribute_list);
|
VkVertexInputBindingDescription *binding_list=new VkVertexInputBindingDescription[attr_count];
|
||||||
|
VkVertexInputAttributeDescription *attribute_list=new VkVertexInputAttributeDescription[attr_count];
|
||||||
|
|
||||||
|
VkVertexInputBindingDescription *bind=binding_list;
|
||||||
|
VkVertexInputAttributeDescription *attr=attribute_list;
|
||||||
|
|
||||||
|
ShaderStage **si=ssi_list;
|
||||||
|
VAConfig vac;
|
||||||
|
|
||||||
|
for(uint i=0;i<attr_count;i++)
|
||||||
|
{
|
||||||
|
//binding对应的是第几个数据输入流
|
||||||
|
//实际使用一个binding可以绑定多个attrib
|
||||||
|
//比如在一个流中传递{pos,color}这样两个数据,就需要两个attrib
|
||||||
|
//但在我们的设计中,仅支持一个流传递一个attrib
|
||||||
|
|
||||||
|
attr->binding =i;
|
||||||
|
attr->location =(*si)->location; //此值对应shader中的layout(location=
|
||||||
|
|
||||||
|
attr->offset =0;
|
||||||
|
|
||||||
|
bind->binding =i; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号,所以这个数字必须从0开始,而且紧密排列。
|
||||||
|
//在RenderableInstance类中,buffer_list必需严格按照本此binding为序列号排列
|
||||||
|
|
||||||
|
if(!cfg||!cfg->Get((*si)->name,vac))
|
||||||
|
{
|
||||||
|
attr->format =VK_NAMESPACE::GetVulkanFormat(&((*si)->type));
|
||||||
|
bind->inputRate =VK_VERTEX_INPUT_RATE_VERTEX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
attr->format =vac.format;
|
||||||
|
bind->inputRate =vac.instance?VK_VERTEX_INPUT_RATE_INSTANCE:VK_VERTEX_INPUT_RATE_VERTEX;
|
||||||
|
}
|
||||||
|
|
||||||
|
bind->stride =GetStrideByFormat(attr->format);
|
||||||
|
|
||||||
|
++attr;
|
||||||
|
++bind;
|
||||||
|
|
||||||
|
++si;
|
||||||
|
}
|
||||||
|
|
||||||
|
VAB *vab=new VAB(attr_count,name_list,type_list,binding_list,attribute_list);
|
||||||
|
|
||||||
vab_sets.Add(vab);
|
vab_sets.Add(vab);
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ VK_NAMESPACE_BEGIN
|
|||||||
ss->type.basetype =(VertexAttribBaseType)*data++;
|
ss->type.basetype =(VertexAttribBaseType)*data++;
|
||||||
ss->type.vec_size =*data++;
|
ss->type.vec_size =*data++;
|
||||||
|
|
||||||
ss->format =VK_NAMESPACE::GetVulkanFormat(&(ss->type));
|
// ss->format =VK_NAMESPACE::GetVulkanFormat(&(ss->type));
|
||||||
|
|
||||||
str_len=*data++;
|
str_len=*data++;
|
||||||
ss->name.SetString((char *)data,str_len);
|
ss->name.SetString((char *)data,str_len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user