Added ShaderStage macro in ShaderGen

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-10-07 16:14:34 +08:00
parent 3393a90127
commit 19df201ab5
7 changed files with 52 additions and 37 deletions

2
CMCore

@ -1 +1 @@
Subproject commit ab0292d27e9825f1259688f78cf3bd02fbc9e785
Subproject commit a1d1f6721c733b509243b3063f4898ef23ae0f75

View File

@ -169,7 +169,7 @@ public:
return(true);
}
void BuildCommandBuffer(uint32 index)
void BuildCommandBuffer(uint32 index) override
{
const CameraInfo &ci=GetCameraInfo();
const ViewportInfo &vi=GetViewportInfo();

View File

@ -5,12 +5,21 @@
#define STD_MTL_NAMESPACE_USING using namespace hgl::graph::mtl;
#define STD_MTL_FUNC_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace mtl{namespace func{
#define STD_MTL_FUNC_NAMESPACE_END }}}}
#define STD_MTL_FUNC NAMESPACE_USING using namespace hgl::graph::mtl::func;
namespace hgl
{
namespace graph
{
namespace mtl
{
namespace func
{
}//namespace func
}//namespace mtl
}//namespace graph
}//namespace hgl

View File

@ -79,6 +79,10 @@ SOURCE_GROUP("Standard Material" FILES ${STD_MTL_SOURCE})
SOURCE_GROUP("Standard Material\\2D" FILES ${STD_MTL_2D_SOURCE_FILES})
SOURCE_GROUP("Standard Material\\3D" FILES ${STD_MTL_3D_SOURCE_FILES})
SET(SHADER_LIBRARY_FILES ShaderLibrary.cpp ShaderLibrary.h)
SOURCE_GROUP("Shader Library" FILES ${SHADER_LIBRARY_FILES})
add_cm_library(ULRE.ShaderGen "ULRE" ${DESC_INFO_HEADER_FILES}
${DESC_INFO_SOURCE_FILES}
${MATERIAL_CREATE_INFO_HEADER_FILES}
@ -87,6 +91,7 @@ add_cm_library(ULRE.ShaderGen "ULRE" ${DESC_INFO_HEADER_FILES}
${SHADER_CREATER_SOURCE_FILES}
${GLSL_COMPILER_SOURCE}
${SHADERGEN_COMMON_FILES}
${SHADER_LIBRARY_FILES}
${STD_MTL_SOURCE}
${STD_MTL_2D_SOURCE_FILES}
${STD_MTL_3D_SOURCE_FILES}

View File

@ -248,12 +248,6 @@ bool MaterialCreateInfo::CreateShader()
{
sc->AddOutput(VAT_UINT,mtl::func::MaterialInstanceID,Interpolation::Flat);
if(sc->GetShaderStage()==VK_SHADER_STAGE_VERTEX_BIT)
sc->AddFunction(mtl::func::HandoverMI_VS);
else
if(sc->GetShaderStage()==VK_SHADER_STAGE_GEOMETRY_BIT)
sc->AddFunction(mtl::func::HandoverMI_GS);
else
sc->AddFunction(mtl::func::HandoverMI);
}

View File

@ -7,6 +7,7 @@
#include"common/MFCommon.h"
namespace hgl{namespace graph{
ShaderCreateInfo::ShaderCreateInfo(VkShaderStageFlagBits ss,MaterialDescriptorInfo *m)
{
shader_stage=ss;
@ -158,9 +159,6 @@ void ShaderCreateInfo::SetMaterialInstance(UBODescriptor *ubo,const AnsiString &
sdm->AddUBO(DescriptorSetType::PerMaterial,ubo);
sdm->AddStruct(mtl::MaterialInstanceStruct);
if(shader_stage==VK_SHADER_STAGE_VERTEX_BIT)
AddFunction(mtl::func::GetMI_VS);
else
AddFunction(mtl::func::GetMI);
mi_codes=mi;
@ -377,7 +375,27 @@ bool ShaderCreateInfo::CreateShader(ShaderCreateInfo *last_sc)
if(main_function.IsEmpty())
return(false);
final_shader="#version 460 core\n";
//@see VKShaderStage.cpp
final_shader=R"(#version 460 core
#define VertexShader 0x01
#define TessControlShader 0x02
#define TeseEvalShader 0x04
#define GeometryShader 0x08
#define FragmentShader 0x10
#define ComputeShader 0x20
#define TaskShader 0x40
#define MeshShader 0x80
#define ShaderStage 0x)";
{
char ss_hex_str[9];
final_shader+=utos(ss_hex_str,8,uint(shader_stage),16);
final_shader+="\n";
}
ProcDefine();

View File

@ -16,38 +16,27 @@ mat4 GetLocalToWorld()
constexpr const char MaterialInstanceID[]="MaterialInstanceID";
constexpr const char HandoverMI_VS[]=R"(
void HandoverMI()
{
Output.MaterialInstanceID=Assign.y;
}
)";
constexpr const char HandoverMI_GS[]=R"(
void HandoverMI()
{
Output.MaterialInstanceID=Input[0].MaterialInstanceID;
}
)";
constexpr const char HandoverMI[]=R"(
void HandoverMI()
{
#if ShaderStage == VertexShader
Output.MaterialInstanceID=Assign.y;
#elif ShaderStage == GeometryShader
Output.MaterialInstanceID=Input[0].MaterialInstanceID;
#else
Output.MaterialInstanceID=Input.MaterialInstanceID;
}
)";
constexpr const char GetMI_VS[]=R"(
MaterialInstance GetMI()
{
return mtl.mi[Assign.y];
#endif
}
)";
constexpr const char GetMI[]=R"(
MaterialInstance GetMI()
{
#if ShaderStage == VertexShader
return mtl.mi[Assign.y];
#else
return mtl.mi[Input.MaterialInstanceID];
#endif
}
)";