OK???? 3rd_draw_triangle_use_RenderList run OK!.

This commit is contained in:
2023-09-05 20:19:53 +08:00
parent 6e8932fc2f
commit 8bb742f3f4
17 changed files with 356 additions and 145 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include<hgl/graph/RenderNode.h>
#include<hgl/graph/VKVBOList.h>
VK_NAMESPACE_BEGIN
struct RenderExtraBuffer;
@@ -42,9 +43,7 @@ private:
protected:
uint32_t binding_count;
VkBuffer *buffer_list;
VkDeviceSize *buffer_offset;
VBOList * vbo_list;
MaterialInstance * last_mi;
Pipeline * last_pipeline;

View File

@@ -2,6 +2,7 @@
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/VKVBOList.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/color/Color4f.h>
@@ -140,7 +141,7 @@ public:
return(true);
}
bool BindDescriptorSets(Renderable *ri);
bool BindDescriptorSets(Material *);
bool PushDescriptorSet(VkPipelineLayout pipeline_layout,uint32_t set,uint32_t count,const VkWriteDescriptorSet *write_desc_set)
{
@@ -160,6 +161,17 @@ public:
vkCmdBindVertexBuffers(cmd_buf,first,count,vbo,offsets);
}
bool BindVBO(VBOList *vbo_list)
{
if(!vbo_list)return(false);
if(!vbo_list->IsFull())return(false);
vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->binding_count,vbo_list->buffer_list,vbo_list->buffer_offset);
return(true);
}
void BindIBO(const IndexBufferData *);
bool BindVBO(Renderable *);

57
inc/hgl/graph/VKVBOList.h Normal file
View File

@@ -0,0 +1,57 @@
#pragma once
VK_NAMESPACE_BEGIN
class VBOList
{
uint32_t binding_count;
VkBuffer *buffer_list;
VkDeviceSize *buffer_offset;
uint32_t write_count;
friend class RenderCmdBuffer;
public:
VBOList(const uint32 bc)
{
binding_count=bc;
buffer_list=new VkBuffer[binding_count];
buffer_offset=new VkDeviceSize[binding_count];
write_count=0;
}
~VBOList()
{
delete[] buffer_offset;
delete[] buffer_list;
}
void Restart()
{
write_count=0;
}
const bool IsFull()const
{
return write_count>=binding_count;
}
void Add(const VkBuffer buf,const VkDeviceSize offset)
{
buffer_list[write_count]=buf;
buffer_offset[write_count]=offset;
++write_count;
}
void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
{
hgl_cpy(buffer_list +write_count,buf, count);
hgl_cpy(buffer_offset+write_count,offset,count);
write_count+=count;
}
};//class VBOList
VK_NAMESPACE_END

View File

@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include<hgl/graph/mtl/StdMaterial.h>
#include<hgl/graph/mtl/ShaderBuffer.h>
@@ -42,6 +42,18 @@ constexpr const ShaderBufferSource SBS_CameraInfo=
float znear,zfar;)"
};
// UBO必须严格指定数组的大小
// SSBO则不需要使用[]方式指定为动态大小数组
constexpr const ShaderBufferSource SBS_LocalToWorld=
{
"LocalToWorldData",
"l2w",
R"(
mat4 mats[L2W_MAX_COUNT];)"
};
constexpr const char MaterialInstanceStruct[]="MaterialInstance";
constexpr const ShaderBufferSource SBS_MaterialInstanceData=

View File

@@ -13,6 +13,7 @@
namespace hgl{namespace graph
{
struct GPUDeviceAttribute;
struct UBODescriptor;
namespace mtl
{
@@ -21,13 +22,20 @@ namespace hgl{namespace graph
protected:
const MaterialCreateConfig *config;
uint32_t ubo_range;
uint32_t ssbo_range;
MaterialDescriptorInfo mdi; ///<材质描述符管理器
AnsiString mi_codes; ///<MaterialInstance代码
uint32_t mi_data_bytes; ///<MaterialInstance数据长度
uint32_t mi_shader_stage; ///<MaterialInstance着色器阶段
uint32_t mi_max_count; ///<MaterialInstance最大数量
uint32_t mi_max_count;
UBODescriptor *mi_ubo;
uint32_t l2w_shader_stage;
uint32_t l2w_max_count;
UBODescriptor *l2w_ubo;
ShaderCreateInfoMap shader_map; ///<着色器列表
@@ -68,7 +76,9 @@ namespace hgl{namespace graph
MaterialCreateInfo(const MaterialCreateConfig *);
~MaterialCreateInfo()=default;
bool SetMaterialInstance(const AnsiString &mi_glsl_codes,const uint32_t mi_struct_bytes,const uint32_t shader_stage_flag_bit);
bool SetMaterialInstance(const AnsiString &mi_glsl_codes,const uint32_t mi_struct_bytes,const uint32_t shader_stage_flag_bits);
bool SetLocalToWorld(const uint32_t shader_stage_flag_bits);
bool AddStruct(const AnsiString &ubo_typename,const AnsiString &codes);
bool AddStruct(const ShaderBufferSource &ss){return AddStruct(ss.struct_name,ss.codes);}
@@ -78,7 +88,7 @@ namespace hgl{namespace graph
bool AddUBO(const uint32_t flag_bits,const DescriptorSetType &set_type,const ShaderBufferSource &ss);
bool CreateShader(const GPUDeviceAttribute *);
bool CreateShader();
};//class MaterialCreateInfo
}//namespace mtl
}//namespace graph

View File

@@ -81,6 +81,7 @@ public:
void AddFunction(const AnsiString &str){function_list.Add(str);}
void SetMaterialInstance(UBODescriptor *,const AnsiString &);
void SetLocalToWorld(UBODescriptor *);
void SetMain(const AnsiString &str){main_function=str;}

View File

@@ -19,9 +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);
void AddMaterialInstanceID();
void AddJoint();
void AddLocalToWorld();
void AddAssign();
};//class ShaderCreateInfoVertex:public ShaderCreateInfo
}//namespace graph
}//namespace hgl::graph