2019-04-27 21:23:57 +08:00
|
|
|
|
#include"VKShaderModule.h"
|
2019-04-28 16:06:53 +08:00
|
|
|
|
#include"VKVertexAttributeBinding.h"
|
|
|
|
|
#include"VKShaderParse.h"
|
2019-04-27 21:23:57 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-04-28 16:06:53 +08:00
|
|
|
|
ShaderModule::ShaderModule(int id,VkPipelineShaderStageCreateInfo *sci,const ShaderParse *sp)
|
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
|
|
|
|
|
|
|
|
|
ParseUBO(sp);
|
2019-04-27 21:23:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShaderModule::~ShaderModule()
|
|
|
|
|
{
|
|
|
|
|
delete stage_create_info;
|
|
|
|
|
}
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
|
|
|
|
void ShaderModule::ParseUBO(const ShaderParse *parse)
|
|
|
|
|
{
|
|
|
|
|
for(const auto &ubo:parse->GetUBO())
|
|
|
|
|
{
|
|
|
|
|
const UTF8String & name =parse->GetName(ubo);
|
|
|
|
|
const uint binding =parse->GetBinding(ubo);
|
|
|
|
|
|
|
|
|
|
ubo_map.Add(name,binding);
|
|
|
|
|
ubo_list.Add(binding);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VertexShaderModule::ParseVertexInput(const ShaderParse *parse)
|
|
|
|
|
{
|
|
|
|
|
const auto &stage_inputs=parse->GetStageInput();
|
|
|
|
|
|
|
|
|
|
attr_count=stage_inputs.size();
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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
|