From 5ba5a331a5119ca88d2eb9012df3951985d028e0 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 29 Oct 2024 23:40:32 +0800 Subject: [PATCH] moved Check()/Comp()/From() to .cpp from ShaderVariableType.h --- inc/hgl/graph/mtl/ShaderVariableType.h | 108 +------------------------ src/ShaderGen/ShaderVariableType.cpp | 108 +++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 105 deletions(-) diff --git a/inc/hgl/graph/mtl/ShaderVariableType.h b/inc/hgl/graph/mtl/ShaderVariableType.h index d4a99b19..329ab7b8 100644 --- a/inc/hgl/graph/mtl/ShaderVariableType.h +++ b/inc/hgl/graph/mtl/ShaderVariableType.h @@ -156,89 +156,9 @@ namespace hgl array_size=count; } - const bool Check()const - { - if(!RangeCheck(base_type))return(false); + const bool Check()const; - RANGE_CHECK_RETURN_FALSE(base_type) - - if(base_type==SVBaseType::Scalar) - return(true); - - if(base_type==SVBaseType::Vector) - { - if(vector.vec_size<2||vector.vec_size>4)return(false); - - return(true); - } - - if(base_type==SVBaseType::Matrix) - { - if(matrix.m==0) - { - if(matrix.n<2||matrix.n>4)return(false); - } - else - { - if(matrix.n<2||matrix.n>4)return(false); - if(matrix.m<2||matrix.m>4)return(false); - } - - return(true); - } - - if(base_type==SVBaseType::Sampler) - return RangeCheck(sampler.type); - - if(base_type==SVBaseType::Image) - return RangeCheck(image.type); - - return(true); - } - - int Comp(const ShaderVariableType &svt)const - { - int off=(int)base_type-(int)svt.base_type; - - if(off)return(off); - - if(base_type==SVBaseType::Scalar) - return int(scalar.type)-int(svt.scalar.type); - - if(base_type==SVBaseType::Vector) - { - off=int(vector.type)-int(svt.vector.type); - - if(off)return(off); - - off=vector.vec_size-svt.vector.vec_size; - - if(off)return(off); - - return int(vector.type)-int(svt.vector.type); - } - - if(base_type==SVBaseType::Matrix) - { - off=int(matrix.type)-int(svt.matrix.type); - - if(off)return(off); - - off=matrix.n-svt.matrix.n; - - if(off)return(off); - - return matrix.m-svt.matrix.m; - } - - if(base_type==SVBaseType::Sampler) - return int(sampler.type)-int(svt.sampler.type); - - if(base_type==SVBaseType::Image) - return int(image.type)-int(svt.image.type); - - return 0; - } + int Comp(const ShaderVariableType &svt)const; CompOperator(const ShaderVariableType &,Comp) @@ -254,29 +174,7 @@ namespace hgl return Check(); } - const bool From(const VAType &vat,const uint16 count=1) - { - array_size=count; - - if(vat.vec_size==1) - { - base_type=SVBaseType::Scalar; - scalar.type=vat.basetype; - - return(true); - } - else if(vat.vec_size<=4) - { - base_type=SVBaseType::Vector; - - vector.type=vat.basetype; - vector.vec_size=vat.vec_size; - - return(true); - } - - return(false); - } + const bool From(const VAType &vat,const uint16 count=1); static const ShaderVariableType Scalar(const VABaseType &vabt,const uint count=1) { diff --git a/src/ShaderGen/ShaderVariableType.cpp b/src/ShaderGen/ShaderVariableType.cpp index 49abfe95..652bb42c 100644 --- a/src/ShaderGen/ShaderVariableType.cpp +++ b/src/ShaderGen/ShaderVariableType.cpp @@ -45,6 +45,90 @@ namespace constexpr const char AtomicCounterTypename[]="atomic_uint"; }//namespace +const bool ShaderVariableType::Check()const +{ + if(!RangeCheck(base_type))return(false); + + RANGE_CHECK_RETURN_FALSE(base_type) + + if(base_type==SVBaseType::Scalar) + return(true); + + if(base_type==SVBaseType::Vector) + { + if(vector.vec_size<2||vector.vec_size>4)return(false); + + return(true); + } + + if(base_type==SVBaseType::Matrix) + { + if(matrix.m==0) + { + if(matrix.n<2||matrix.n>4)return(false); + } + else + { + if(matrix.n<2||matrix.n>4)return(false); + if(matrix.m<2||matrix.m>4)return(false); + } + + return(true); + } + + if(base_type==SVBaseType::Sampler) + return RangeCheck(sampler.type); + + if(base_type==SVBaseType::Image) + return RangeCheck(image.type); + + return(true); +} + +int ShaderVariableType::Comp(const ShaderVariableType &svt)const +{ + int off=(int)base_type-(int)svt.base_type; + + if(off)return(off); + + if(base_type==SVBaseType::Scalar) + return int(scalar.type)-int(svt.scalar.type); + + if(base_type==SVBaseType::Vector) + { + off=int(vector.type)-int(svt.vector.type); + + if(off)return(off); + + off=vector.vec_size-svt.vector.vec_size; + + if(off)return(off); + + return int(vector.type)-int(svt.vector.type); + } + + if(base_type==SVBaseType::Matrix) + { + off=int(matrix.type)-int(svt.matrix.type); + + if(off)return(off); + + off=matrix.n-svt.matrix.n; + + if(off)return(off); + + return matrix.m-svt.matrix.m; + } + + if(base_type==SVBaseType::Sampler) + return int(sampler.type)-int(svt.sampler.type); + + if(base_type==SVBaseType::Image) + return int(image.type)-int(svt.image.type); + + return 0; +} + const char *ShaderVariableType::GetTypename()const { if(base_type==SVBaseType::Scalar) @@ -268,4 +352,28 @@ bool ShaderVariableType::ParseTypeString(const char *str) return(false); } + +const bool ShaderVariableType::From(const VAType &vat,const uint16 count) +{ + array_size=count; + + if(vat.vec_size==1) + { + base_type=SVBaseType::Scalar; + scalar.type=vat.basetype; + + return(true); + } + else if(vat.vec_size<=4) + { + base_type=SVBaseType::Vector; + + vector.type=vat.basetype; + vector.vec_size=vat.vec_size; + + return(true); + } + + return(false); +} VK_NAMESPACE_END