From 784e7f0e0b6c81c0dba147b1bb0d67f9b46ed8e2 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 9 Jun 2025 22:52:10 +0800 Subject: [PATCH] =?UTF-8?q?SBS=E5=A2=9E=E5=8A=A0DescriptorSetType=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=EF=BC=8C=E6=9C=AA=E6=9D=A5=E6=89=80=E6=9C=89=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E5=9C=B0=E6=96=B9=E4=BD=BF=E7=94=A8=E6=AD=A4=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BB=A5=E9=81=BF=E5=85=8D=E5=AF=B9=E4=B8=8D=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMCore | 2 +- example/Basic/BillboardTest.cpp | 2 +- inc/hgl/graph/VK.h | 1 + inc/hgl/graph/VKBufferMap.h | 1 + inc/hgl/graph/VKDescriptorBindingManage.h | 4 ++- inc/hgl/graph/VKMaterial.h | 7 ++++- inc/hgl/graph/mtl/BlinnPhong.h | 5 +++- inc/hgl/graph/mtl/ShaderBufferSource.h | 12 ++++++-- inc/hgl/graph/mtl/UBOCommon.h | 30 +++++++++++++------- src/SceneGraph/render/RenderAssignBuffer.cpp | 4 +-- src/ShaderGen/MaterialCreateInfo.cpp | 5 ++-- 11 files changed, 51 insertions(+), 22 deletions(-) diff --git a/CMCore b/CMCore index fff02148..10108953 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit fff021488c9608c2ac4ee06bc544e9a80849c6f0 +Subproject commit 10108953ebff000823b072be9e4c632471520945 diff --git a/example/Basic/BillboardTest.cpp b/example/Basic/BillboardTest.cpp index 227b2009..6930ea43 100644 --- a/example/Basic/BillboardTest.cpp +++ b/example/Basic/BillboardTest.cpp @@ -216,5 +216,5 @@ public: int os_main(int,os_char **) { - return RunFramework(OS_TEXT("AutoInstance"),1024,1024); + return RunFramework(OS_TEXT("AutoInstance"),1280,720); } diff --git a/inc/hgl/graph/VK.h b/inc/hgl/graph/VK.h index 9553bc7d..957e5a29 100644 --- a/inc/hgl/graph/VK.h +++ b/inc/hgl/graph/VK.h @@ -96,6 +96,7 @@ class Semaphore; struct PipelineLayoutData; class DescriptorSet; +enum class DescriptorSetType; struct VertexInputAttribute; diff --git a/inc/hgl/graph/VKBufferMap.h b/inc/hgl/graph/VKBufferMap.h index e2314635..3759f3d4 100644 --- a/inc/hgl/graph/VKBufferMap.h +++ b/inc/hgl/graph/VKBufferMap.h @@ -22,6 +22,7 @@ public: buffer=nullptr; offset=0; stride=count=0; + map_ptr=nullptr; } virtual ~VKBufferMap() diff --git a/inc/hgl/graph/VKDescriptorBindingManage.h b/inc/hgl/graph/VKDescriptorBindingManage.h index fd2cd220..a70b7c43 100644 --- a/inc/hgl/graph/VKDescriptorBindingManage.h +++ b/inc/hgl/graph/VKDescriptorBindingManage.h @@ -3,7 +3,6 @@ #include #include #include -#include VK_NAMESPACE_BEGIN @@ -46,6 +45,9 @@ public: template bool AddUBO(const AnsiString &name,DeviceBufferMap *dbm) { + if(name.IsEmpty()||!dbm) + return(false); + return AddUBO(name,dbm->GetDeviceBuffer()); } diff --git a/inc/hgl/graph/VKMaterial.h b/inc/hgl/graph/VKMaterial.h index e3a8ccdc..58fb3f48 100644 --- a/inc/hgl/graph/VKMaterial.h +++ b/inc/hgl/graph/VKMaterial.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include namespace hgl { @@ -83,6 +83,11 @@ public: bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false); bool BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler); + bool BindUBO(const ShaderBufferDesc *sbd,DeviceBuffer *ubo,bool dynamic=false) + { + return BindUBO(sbd->set_type,sbd->name,ubo,dynamic); + } + void Update(); public: diff --git a/inc/hgl/graph/mtl/BlinnPhong.h b/inc/hgl/graph/mtl/BlinnPhong.h index 859dacaa..be71ab0b 100644 --- a/inc/hgl/graph/mtl/BlinnPhong.h +++ b/inc/hgl/graph/mtl/BlinnPhong.h @@ -14,9 +14,12 @@ namespace blinnphong constexpr const ShaderBufferSource SBS_SunLight= { - "SunLight", + DescriptorSetType::Scene, + "sun", + "SunLight", + R"( vec4 direction; vec4 color; diff --git a/inc/hgl/graph/mtl/ShaderBufferSource.h b/inc/hgl/graph/mtl/ShaderBufferSource.h index 3c633efe..8b4d8c3f 100644 --- a/inc/hgl/graph/mtl/ShaderBufferSource.h +++ b/inc/hgl/graph/mtl/ShaderBufferSource.h @@ -1,11 +1,19 @@ #pragma once +#include + namespace hgl::graph { - struct ShaderBufferSource + struct ShaderBufferDesc + { + const DescriptorSetType set_type; + + const char *name; + }; + + struct ShaderBufferSource:public ShaderBufferDesc { const char *struct_name; - const char *name; const char *codes; }; }//namespace hgl::graph diff --git a/inc/hgl/graph/mtl/UBOCommon.h b/inc/hgl/graph/mtl/UBOCommon.h index 7a9645b5..e7cb0564 100644 --- a/inc/hgl/graph/mtl/UBOCommon.h +++ b/inc/hgl/graph/mtl/UBOCommon.h @@ -6,8 +6,10 @@ STD_MTL_NAMESPACE_BEGIN constexpr const ShaderBufferSource SBS_ViewportInfo= { - "ViewportInfo", + DescriptorSetType::RenderTarget, + "viewport", + "ViewportInfo", R"( mat4 ortho_matrix; @@ -20,8 +22,10 @@ constexpr const ShaderBufferSource SBS_ViewportInfo= constexpr const ShaderBufferSource SBS_CameraInfo= { - "CameraInfo", + DescriptorSetType::Camera, + "camera", + "CameraInfo", R"( mat4 projection; @@ -48,12 +52,13 @@ constexpr const ShaderBufferSource SBS_CameraInfo= }; constexpr const char LocalToWorldStruct[]="LocalToWorld"; -constexpr const DescriptorSetType DST_LocalToWorld=DescriptorSetType::PerFrame; constexpr const ShaderBufferSource SBS_LocalToWorld= { - "LocalToWorldData", + DescriptorSetType::PerFrame, + "l2w", + "LocalToWorldData", R"( mat4 mats[L2W_MAX_COUNT]; @@ -64,12 +69,13 @@ constexpr const ShaderBufferSource SBS_LocalToWorld= // SSBO则不需要,使用[]方式指定为动态大小数组 constexpr const char MaterialInstanceStruct[]="MaterialInstance"; -constexpr const DescriptorSetType DST_MaterialInstance=DescriptorSetType::PerMaterial; constexpr const ShaderBufferSource SBS_MaterialInstance= { - "MaterialInstanceData", + DescriptorSetType::PerMaterial, + "mtl", + "MaterialInstanceData", R"( MaterialInstance mi[MI_MAX_COUNT];)" @@ -77,11 +83,13 @@ constexpr const ShaderBufferSource SBS_MaterialInstance= constexpr const ShaderBufferSource SBS_JointInfo= { - "JointInfo", - "joint", + DescriptorSetType::PerFrame, -R"( - mat4 mats[]; -)" + "joint", + "JointInfo", + + R"( + mat4 mats[]; + )" }; STD_MTL_NAMESPACE_END diff --git a/src/SceneGraph/render/RenderAssignBuffer.cpp b/src/SceneGraph/render/RenderAssignBuffer.cpp index 397cbe93..db0ab370 100644 --- a/src/SceneGraph/render/RenderAssignBuffer.cpp +++ b/src/SceneGraph/render/RenderAssignBuffer.cpp @@ -30,8 +30,8 @@ void RenderAssignBuffer::Bind(Material *mtl)const { if(!mtl)return; - mtl->BindUBO(mtl::DST_LocalToWorld, mtl::SBS_LocalToWorld.name, l2w_buffer); - mtl->BindUBO(mtl::DST_MaterialInstance, mtl::SBS_MaterialInstance.name, mi_buffer); + mtl->BindUBO(&mtl::SBS_LocalToWorld, l2w_buffer); + mtl->BindUBO(&mtl::SBS_MaterialInstance, mi_buffer); } void RenderAssignBuffer::Clear() diff --git a/src/ShaderGen/MaterialCreateInfo.cpp b/src/ShaderGen/MaterialCreateInfo.cpp index 86c505a9..a89451a7 100644 --- a/src/ShaderGen/MaterialCreateInfo.cpp +++ b/src/ShaderGen/MaterialCreateInfo.cpp @@ -168,11 +168,12 @@ bool MaterialCreateInfo::SetMaterialInstance(const AnsiString &glsl_codes,const mi_max_count=hgl_min(ubo_range/data_bytes,HGL_U16_MAX); mdi.AddStruct(MaterialInstanceStruct,mi_codes); + mdi.AddStruct(SBS_MaterialInstance); mi_ubo=CreateUBODescriptor(SBS_MaterialInstance,shader_stage_flag_bits); - mdi.AddUBO(shader_stage_flag_bits,DST_MaterialInstance,mi_ubo); + mdi.AddUBO(shader_stage_flag_bits,SBS_MaterialInstance.set_type,mi_ubo); const AnsiString MI_MAX_COUNT_STRING=AnsiString::numberOf(mi_max_count); @@ -204,7 +205,7 @@ bool MaterialCreateInfo::SetLocalToWorld(const uint32_t shader_stage_flag_bits) l2w_ubo=CreateUBODescriptor(SBS_LocalToWorld,shader_stage_flag_bits); - mdi.AddUBO(shader_stage_flag_bits,DST_LocalToWorld,l2w_ubo); + mdi.AddUBO(shader_stage_flag_bits,SBS_LocalToWorld.set_type,l2w_ubo); const AnsiString L2W_MAX_COUNT_STRING=AnsiString::numberOf(l2w_max_count);