From dd6b2f4fb3785aaaee19bb6b54e491f256a3af56 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 12 Mar 2024 23:28:23 +0800 Subject: [PATCH] add "hasInput(const char *name)" in ShaderDescriptorInfo and ShaderCreateInfoVertex classes. --- inc/hgl/shadergen/ShaderCreateInfoVertex.h | 2 ++ inc/hgl/shadergen/ShaderDescriptorInfo.h | 2 ++ src/ShaderGen/ShaderCreateInfoVertex.cpp | 5 +++++ src/ShaderGen/ShaderDescriptorInfo.cpp | 17 +++++++++++++---- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/inc/hgl/shadergen/ShaderCreateInfoVertex.h b/inc/hgl/shadergen/ShaderCreateInfoVertex.h index 978188dc..d4c80722 100644 --- a/inc/hgl/shadergen/ShaderCreateInfoVertex.h +++ b/inc/hgl/shadergen/ShaderCreateInfoVertex.h @@ -19,6 +19,8 @@ namespace hgl int AddInput(const graph::VAT &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic); int AddInput(const AnsiString &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic); + int hasInput(const char *); + void AddJoint(); void AddAssign(); };//class ShaderCreateInfoVertex:public ShaderCreateInfo diff --git a/inc/hgl/shadergen/ShaderDescriptorInfo.h b/inc/hgl/shadergen/ShaderDescriptorInfo.h index 68e4b4aa..73c387e2 100644 --- a/inc/hgl/shadergen/ShaderDescriptorInfo.h +++ b/inc/hgl/shadergen/ShaderDescriptorInfo.h @@ -59,6 +59,8 @@ public: bool AddInput(ShaderAttribute *); bool AddOutput(ShaderAttribute *); + bool hasInput(const char *)const; ///<是否有指定输入 + void AddStruct(const AnsiString &); bool AddUBO(DescriptorSetType type,const UBODescriptor *sd); bool AddSampler(DescriptorSetType type,const SamplerDescriptor *sd); diff --git a/src/ShaderGen/ShaderCreateInfoVertex.cpp b/src/ShaderGen/ShaderCreateInfoVertex.cpp index efcc12fb..178541e9 100644 --- a/src/ShaderGen/ShaderCreateInfoVertex.cpp +++ b/src/ShaderGen/ShaderCreateInfoVertex.cpp @@ -37,6 +37,11 @@ int ShaderCreateInfoVertex::AddInput(const AnsiString &type,const AnsiString &na return AddInput(vat,name,input_rate,group); } +int ShaderCreateInfoVertex::hasInput(const char *name) +{ + return sdm->hasInput(name); +} + void ShaderCreateInfoVertex::AddJoint() { AddInput(VAT_UVEC4, VAN::JointID, VK_VERTEX_INPUT_RATE_VERTEX,VertexInputGroup::JointID); diff --git a/src/ShaderGen/ShaderDescriptorInfo.cpp b/src/ShaderGen/ShaderDescriptorInfo.cpp index 7a590b64..d5790691 100644 --- a/src/ShaderGen/ShaderDescriptorInfo.cpp +++ b/src/ShaderGen/ShaderDescriptorInfo.cpp @@ -12,13 +12,13 @@ ShaderDescriptorInfo::ShaderDescriptorInfo(VkShaderStageFlagBits flag_bit) namespace { - bool Find(ShaderAttributeArray &sad,const ShaderAttribute *ss) + bool Find(const ShaderAttributeArray &sad,const char *name) { if(sad.count<=0) return(false); for(uint i=0;iname)==0) + if(hgl::strcmp(sad.items[i].name,name)==0) return(true); return(false); @@ -29,7 +29,7 @@ bool ShaderDescriptorInfo::AddInput(ShaderAttribute *ss) { if(!ss)return(false); - if(Find(stage_io.input,ss))return(false); + if(Find(stage_io.input,ss->name))return(false); ss->location=stage_io.input.count; @@ -37,11 +37,20 @@ bool ShaderDescriptorInfo::AddInput(ShaderAttribute *ss) return(true); } + +bool ShaderDescriptorInfo::hasInput(const char *name)const +{ + if(!name||!*name)return(false); + + return Find(stage_io.input,name); + +} + bool ShaderDescriptorInfo::AddOutput(ShaderAttribute *ss) { if(!ss)return(false); - if(Find(stage_io.output,ss))return(false); + if(Find(stage_io.output,ss->name))return(false); ss->location=stage_io.output.count;