2021-09-13 20:39:25 +08:00
|
|
|
#include<hgl/graph/VKShaderResource.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
#include<hgl/graph/VKFormat.h>
|
2021-09-13 20:39:25 +08:00
|
|
|
#include<hgl/filesystem/FileSystem.h>
|
2020-09-19 23:49:32 +08:00
|
|
|
#include<hgl/type/Map.h>
|
2023-02-23 19:01:01 +08:00
|
|
|
#include<hgl/io/ConstBufferReader.h>
|
2020-06-06 19:45:38 +08:00
|
|
|
|
2020-06-09 19:40:08 +08:00
|
|
|
VK_NAMESPACE_BEGIN
|
2020-06-08 19:12:29 +08:00
|
|
|
|
2020-06-09 19:40:08 +08:00
|
|
|
namespace
|
|
|
|
{
|
2023-02-13 11:48:53 +08:00
|
|
|
ObjectMap<OSString,ShaderResource> shader_resource_by_filename;
|
2020-09-19 23:49:32 +08:00
|
|
|
|
2023-03-18 21:07:21 +08:00
|
|
|
const bool LoadShaderStageAttributes(ShaderAttributeArray &sa_array,io::ConstBufferReader &cbr)
|
2020-06-09 19:40:08 +08:00
|
|
|
{
|
2023-02-23 19:01:01 +08:00
|
|
|
uint count;
|
2020-06-08 19:12:29 +08:00
|
|
|
|
2023-02-23 19:01:01 +08:00
|
|
|
cbr.CastRead<uint8>(count);
|
2020-06-08 19:12:29 +08:00
|
|
|
|
2023-02-23 19:01:01 +08:00
|
|
|
if(count<=0)
|
|
|
|
return(false);
|
2020-06-08 19:12:29 +08:00
|
|
|
|
2023-03-18 21:07:21 +08:00
|
|
|
Init(&sa_array,count);
|
2023-03-17 21:06:05 +08:00
|
|
|
|
2023-03-18 21:07:21 +08:00
|
|
|
ShaderAttribute *ss=sa_array.items;
|
2020-06-08 19:12:29 +08:00
|
|
|
|
2020-06-09 19:40:08 +08:00
|
|
|
for(uint i=0;i<count;i++)
|
|
|
|
{
|
2023-02-23 19:01:01 +08:00
|
|
|
cbr.Read(ss->location);
|
2023-03-02 20:19:25 +08:00
|
|
|
cbr.CastRead<uint8>(ss->basetype);
|
|
|
|
cbr.CastRead<uint8>(ss->vec_size);
|
2020-06-08 19:12:29 +08:00
|
|
|
|
2023-02-23 19:01:01 +08:00
|
|
|
cbr.ReadTinyString(ss->name);
|
2020-06-08 19:12:29 +08:00
|
|
|
|
2023-03-17 21:06:05 +08:00
|
|
|
++ss;
|
2020-06-09 19:40:08 +08:00
|
|
|
}
|
2020-06-08 19:12:29 +08:00
|
|
|
|
2023-02-23 19:01:01 +08:00
|
|
|
return true;
|
2020-06-09 19:40:08 +08:00
|
|
|
}
|
|
|
|
}//namespcae
|
|
|
|
|
2020-09-17 21:49:23 +08:00
|
|
|
ShaderResource::ShaderResource(const VkShaderStageFlagBits &flag,const void *sd,const uint32 size)
|
2020-06-09 19:40:08 +08:00
|
|
|
{
|
|
|
|
stage_flag=flag;
|
|
|
|
spv_data=sd;
|
2023-03-17 21:06:05 +08:00
|
|
|
spv_size=size;
|
|
|
|
|
|
|
|
Init(stage_io);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderResource::~ShaderResource()
|
|
|
|
{
|
|
|
|
Clear(stage_io);
|
2020-06-09 19:40:08 +08:00
|
|
|
}
|
|
|
|
|
2023-03-17 16:21:12 +08:00
|
|
|
const ShaderAttribute *ShaderResource::GetInput(const AnsiString &name) const
|
2020-07-09 20:37:34 +08:00
|
|
|
{
|
2023-03-17 21:06:05 +08:00
|
|
|
if(stage_io.input.count<=0)return(nullptr);
|
2020-07-09 20:37:34 +08:00
|
|
|
|
2023-03-17 21:06:05 +08:00
|
|
|
const ShaderAttribute *ss=stage_io.input.items;
|
|
|
|
|
|
|
|
for(uint i=0;i<stage_io.input.count;i++)
|
2020-07-09 20:37:34 +08:00
|
|
|
{
|
2023-03-17 21:06:05 +08:00
|
|
|
if(name==ss->name)
|
|
|
|
return ss;
|
2020-07-09 20:37:34 +08:00
|
|
|
|
|
|
|
++ss;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-03-17 16:21:12 +08:00
|
|
|
const int ShaderResource::GetInputBinding(const AnsiString &name) const
|
2020-06-09 19:40:08 +08:00
|
|
|
{
|
2023-03-17 21:06:05 +08:00
|
|
|
if(stage_io.input.count<=0)return(-1);
|
|
|
|
|
|
|
|
const ShaderAttribute *ss=stage_io.input.items;
|
2020-06-09 14:05:20 +08:00
|
|
|
|
2023-03-17 21:06:05 +08:00
|
|
|
for(uint i=0;i<stage_io.input.count;i++)
|
2020-06-09 14:05:20 +08:00
|
|
|
{
|
2023-03-17 21:06:05 +08:00
|
|
|
if(name==ss->name)
|
2020-06-10 17:11:24 +08:00
|
|
|
return i;
|
2020-06-09 19:40:08 +08:00
|
|
|
|
|
|
|
++ss;
|
2020-06-09 14:05:20 +08:00
|
|
|
}
|
|
|
|
|
2020-06-09 19:40:08 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2020-06-08 19:12:29 +08:00
|
|
|
|
2023-02-23 19:01:01 +08:00
|
|
|
ShaderResource *LoadShaderResource(io::ConstBufferReader &cbr)
|
2020-06-09 19:40:08 +08:00
|
|
|
{
|
|
|
|
VkShaderStageFlagBits flag;
|
|
|
|
uint32 spv_size;
|
2020-06-08 19:12:29 +08:00
|
|
|
|
2023-02-23 19:01:01 +08:00
|
|
|
cbr.CastRead<uint32>(flag);
|
|
|
|
cbr.Read(spv_size);
|
2020-06-09 19:40:08 +08:00
|
|
|
|
2023-02-23 19:01:01 +08:00
|
|
|
ShaderResource *sr=new ShaderResource(flag,cbr.CurPointer(),spv_size);
|
2020-06-09 19:40:08 +08:00
|
|
|
|
2023-02-23 19:01:01 +08:00
|
|
|
cbr.Skip(spv_size);
|
2020-06-09 19:40:08 +08:00
|
|
|
|
2023-03-17 16:21:12 +08:00
|
|
|
LoadShaderStageAttributes(sr->GetInputs(),cbr);
|
|
|
|
// LoadShaderStageAttributes(sr->GetStageOutputs(),cbr);
|
2020-06-09 19:40:08 +08:00
|
|
|
|
2020-09-19 23:49:32 +08:00
|
|
|
return sr;
|
2020-09-17 21:49:23 +08:00
|
|
|
}
|
2020-09-11 17:11:32 +08:00
|
|
|
VK_NAMESPACE_END
|