2019-04-30 16:42:59 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKShaderModule.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKVertexAttributeBinding.h>
|
2019-05-05 21:42:15 +08:00
|
|
|
|
#include"VKShaderParse.h"
|
2019-04-27 21:23:57 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-05-06 22:33:21 +08:00
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
void EnumShaderResource(const ShaderParse *parse,ShaderResourceList &sr,const spirv_cross::SmallVector<spirv_cross::Resource> &res)
|
|
|
|
|
{
|
|
|
|
|
for(const auto &obj:res)
|
|
|
|
|
{
|
|
|
|
|
const UTF8String & name =parse->GetName(obj);
|
|
|
|
|
const uint binding =parse->GetBinding(obj);
|
|
|
|
|
|
|
|
|
|
sr.binding_by_name.Add(name,binding);
|
|
|
|
|
sr.binding_list.Add(binding);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}//namespace
|
|
|
|
|
|
2019-05-05 21:30:55 +08:00
|
|
|
|
ShaderModule::ShaderModule(VkDevice dev,int id,VkPipelineShaderStageCreateInfo *sci,const ShaderParse *sp)
|
2019-04-27 21:23:57 +08:00
|
|
|
|
{
|
2019-05-05 21:30:55 +08:00
|
|
|
|
device=dev;
|
2019-04-27 21:23:57 +08:00
|
|
|
|
shader_id=id;
|
|
|
|
|
ref_count=0;
|
|
|
|
|
|
|
|
|
|
stage_create_info=sci;
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
2019-05-06 22:33:21 +08:00
|
|
|
|
EnumShaderResource(sp,resource[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER],sp->GetUBO());
|
|
|
|
|
EnumShaderResource(sp,resource[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER],sp->GetSSBO());
|
2019-05-19 13:02:35 +08:00
|
|
|
|
EnumShaderResource(sp,resource[VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE],sp->GetSampler());
|
2019-04-27 21:23:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShaderModule::~ShaderModule()
|
|
|
|
|
{
|
2019-05-05 21:30:55 +08:00
|
|
|
|
vkDestroyShaderModule(device,stage_create_info->module,nullptr);
|
2019-04-27 21:23:57 +08:00
|
|
|
|
delete stage_create_info;
|
|
|
|
|
}
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
2019-05-05 21:30:55 +08:00
|
|
|
|
VertexShaderModule::VertexShaderModule(VkDevice dev,int id,VkPipelineShaderStageCreateInfo *pssci,const ShaderParse *parse):ShaderModule(dev,id,pssci,parse)
|
2019-04-28 16:06:53 +08:00
|
|
|
|
{
|
2019-05-06 22:33:21 +08:00
|
|
|
|
const auto &stage_inputs=parse->GetStageInputs();
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
2019-05-05 21:30:55 +08:00
|
|
|
|
attr_count=(uint32_t)stage_inputs.size();
|
2019-04-28 16:06:53 +08:00
|
|
|
|
binding_list=new VkVertexInputBindingDescription[attr_count];
|
|
|
|
|
attribute_list=new VkVertexInputAttributeDescription[attr_count];
|
|
|
|
|
|
|
|
|
|
VkVertexInputBindingDescription *bind=binding_list;
|
|
|
|
|
VkVertexInputAttributeDescription *attr=attribute_list;
|
|
|
|
|
|
|
|
|
|
uint32_t binding_index=0;
|
|
|
|
|
|
|
|
|
|
for(const auto &si:stage_inputs)
|
|
|
|
|
{
|
|
|
|
|
const VkFormat format =parse->GetFormat(si); //ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>п<EFBFBD><D0BF>ܻ<EFBFBD><DCBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>ʽ)
|
|
|
|
|
const UTF8String & name =parse->GetName(si);
|
|
|
|
|
|
|
|
|
|
bind->binding =binding_index; //binding<6E><67>Ӧ<EFBFBD><D3A6>vkCmdBindVertexBuffer<65><72><EFBFBD><EFBFBD><EFBFBD>õĻ<C3B5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>кţ<D0BA><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD><D2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
|
|
|
|
|
//<2F><>VertexInput<75><74><EFBFBD>У<EFBFBD>buf_list<73><74>Ҫ<EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD><EFBFBD>ձ<EFBFBD><D5B1><EFBFBD>bindingΪ<67><CEAA><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
bind->stride =GetStrideByFormat(format);
|
|
|
|
|
bind->inputRate =VK_VERTEX_INPUT_RATE_VERTEX;
|
|
|
|
|
|
|
|
|
|
//binding<6E><67>Ӧ<EFBFBD><D3A6><EFBFBD>ǵڼ<C7B5><DABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//ʵ<><CAB5>ʹ<EFBFBD><CAB9>һ<EFBFBD><D2BB>binding<6E><67><EFBFBD><D4B0><F3B6A8B6><EFBFBD>attrib
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>{pos,color}<7D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>attrib
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD>֧<EFBFBD><D6A7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>attrib
|
|
|
|
|
|
|
|
|
|
attr->binding =binding_index;
|
|
|
|
|
attr->location =parse->GetLocation(si); //<2F><>ֵ<EFBFBD><D6B5>Ӧshader<65>е<EFBFBD>layout(location=
|
|
|
|
|
attr->format =format;
|
|
|
|
|
attr->offset =0;
|
|
|
|
|
|
|
|
|
|
stage_input_locations.Add(name,attr);
|
|
|
|
|
|
|
|
|
|
++attr;
|
|
|
|
|
++bind;
|
|
|
|
|
++binding_index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VertexShaderModule::~VertexShaderModule()
|
|
|
|
|
{
|
|
|
|
|
if(vab_sets.GetCount()>0)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õģ<C3B5><C4A3><EFBFBD><EFBFBD>Ǹ<EFBFBD><C7B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SAFE_CLEAR_ARRAY(binding_list);
|
|
|
|
|
SAFE_CLEAR_ARRAY(attribute_list);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 21:01:28 +08:00
|
|
|
|
const int VertexShaderModule::GetStageInputBinding(const UTF8String &name)const
|
2019-04-28 16:06:53 +08:00
|
|
|
|
{
|
|
|
|
|
if(name.IsEmpty())return -1;
|
|
|
|
|
|
|
|
|
|
VkVertexInputAttributeDescription *attr;
|
|
|
|
|
|
|
|
|
|
if(!stage_input_locations.Get(name,attr))
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return attr->binding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VertexAttributeBinding *VertexShaderModule::CreateVertexAttributeBinding()
|
|
|
|
|
{
|
|
|
|
|
VertexAttributeBinding *vab=new VertexAttributeBinding(this);
|
|
|
|
|
|
|
|
|
|
vab_sets.Add(vab);
|
|
|
|
|
|
|
|
|
|
return(vab);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VertexShaderModule::Release(VertexAttributeBinding *vab)
|
|
|
|
|
{
|
|
|
|
|
return vab_sets.Delete(vab);
|
|
|
|
|
}
|
2019-04-27 21:23:57 +08:00
|
|
|
|
VK_NAMESPACE_END
|