2019-05-06 21:01:28 +08:00
|
|
|
|
#ifndef HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
|
2019-04-27 21:23:57 +08:00
|
|
|
|
#define HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
|
|
|
|
|
|
2020-06-09 19:40:08 +08:00
|
|
|
|
#include<hgl/graph/shader/ShaderResource.h>
|
|
|
|
|
#include<hgl/type/Set.h>
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
2019-04-27 21:23:57 +08:00
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
2019-04-27 21:23:57 +08:00
|
|
|
|
/**
|
2019-05-06 21:01:28 +08:00
|
|
|
|
* Shader模块<br>
|
|
|
|
|
* 该模块提供的是原始的shader数据和信息,不可被修改,只能通过ShaderModuleManage创建和删除
|
2019-04-27 21:23:57 +08:00
|
|
|
|
*/
|
|
|
|
|
class ShaderModule
|
|
|
|
|
{
|
2019-05-05 21:30:55 +08:00
|
|
|
|
VkDevice device;
|
2019-04-27 21:23:57 +08:00
|
|
|
|
int shader_id;
|
|
|
|
|
int ref_count;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
VkPipelineShaderStageCreateInfo *stage_create_info;
|
|
|
|
|
|
2020-06-09 19:40:08 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
ShaderResource *shader_resource;
|
2019-04-27 21:23:57 +08:00
|
|
|
|
|
|
|
|
|
public:
|
2019-05-05 14:22:58 +08:00
|
|
|
|
|
2020-06-09 19:40:08 +08:00
|
|
|
|
ShaderModule(VkDevice dev,int id,VkPipelineShaderStageCreateInfo *pssci,ShaderResource *);
|
2019-04-28 16:06:53 +08:00
|
|
|
|
virtual ~ShaderModule();
|
2019-04-27 21:23:57 +08:00
|
|
|
|
|
|
|
|
|
const int GetID()const{return shader_id;}
|
|
|
|
|
|
|
|
|
|
const int IncRef(){return ++ref_count;}
|
|
|
|
|
const int DecRef(){return --ref_count;}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
const VkShaderStageFlagBits GetStage ()const{return stage_create_info->stage;}
|
|
|
|
|
const VkPipelineShaderStageCreateInfo * GetCreateInfo ()const{return stage_create_info;}
|
|
|
|
|
|
2020-07-07 19:16:23 +08:00
|
|
|
|
const int GetBinding (VkDescriptorType desc_type,const AnsiString &name)const
|
2019-04-27 21:23:57 +08:00
|
|
|
|
{
|
2020-06-09 19:40:08 +08:00
|
|
|
|
return shader_resource->GetBinding(desc_type,name);
|
2019-04-27 21:23:57 +08:00
|
|
|
|
}
|
2020-06-09 19:40:08 +08:00
|
|
|
|
|
|
|
|
|
const ShaderDescriptorList * GetDescriptorList()const{return shader_resource->GetDescriptorList();}
|
2019-04-28 16:06:53 +08:00
|
|
|
|
};//class ShaderModule
|
|
|
|
|
|
|
|
|
|
class VertexAttributeBinding;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-05-06 21:01:28 +08:00
|
|
|
|
* 顶点Shader模块<br>
|
|
|
|
|
* 由于顶点shader在最前方执行,所以它比其它shader多了VertexInput的数据
|
2019-04-28 16:06:53 +08:00
|
|
|
|
*/
|
|
|
|
|
class VertexShaderModule:public ShaderModule
|
|
|
|
|
{
|
|
|
|
|
uint32_t attr_count;
|
|
|
|
|
VkVertexInputBindingDescription *binding_list;
|
|
|
|
|
VkVertexInputAttributeDescription *attribute_list;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
Set<VertexAttributeBinding *> vab_sets;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2020-06-09 19:40:08 +08:00
|
|
|
|
VertexShaderModule(VkDevice dev,int id,VkPipelineShaderStageCreateInfo *pssci,ShaderResource *sr);
|
2019-04-28 16:06:53 +08:00
|
|
|
|
virtual ~VertexShaderModule();
|
2019-04-27 21:23:57 +08:00
|
|
|
|
|
2019-05-06 21:01:28 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取输入流绑定点,需要注意的时,这里获取的binding并非是shader中的binding/location,而是绑定顺序的序列号。对应vkCmdBindVertexBuffer的缓冲区序列号
|
|
|
|
|
*/
|
2020-07-07 19:16:23 +08:00
|
|
|
|
const int GetStageInputBinding(const AnsiString &name)const{return shader_resource->GetStageInputBinding(name);}
|
2020-07-09 20:37:34 +08:00
|
|
|
|
const ShaderStage * GetStage(const AnsiString &name)const{return shader_resource->GetStage(name);}
|
2019-04-27 21:23:57 +08:00
|
|
|
|
|
2019-04-28 16:06:53 +08:00
|
|
|
|
const uint32_t GetAttrCount()const{return attr_count;}
|
|
|
|
|
|
2019-04-27 21:23:57 +08:00
|
|
|
|
const VkVertexInputBindingDescription * GetDescList ()const{return binding_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 VkVertexInputAttributeDescription * GetAttr (const uint32_t index)const{return (index>=attr_count?nullptr:attribute_list+index);}
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
VertexAttributeBinding * CreateVertexAttributeBinding();
|
|
|
|
|
bool Release(VertexAttributeBinding *);
|
|
|
|
|
const uint32_t GetInstanceCount()const{return vab_sets.GetCount();}
|
|
|
|
|
};//class VertexShaderModule:public ShaderModule
|
2019-04-27 21:23:57 +08:00
|
|
|
|
VK_NAMESPACE_END
|
|
|
|
|
#endif//HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
|