a few update
This commit is contained in:
parent
c2279c553d
commit
cef5ad073b
@ -3,7 +3,7 @@
|
||||
#include<hgl/graph/VKVBOList.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct RenderAssignBuffer;
|
||||
class RenderAssignBuffer;
|
||||
|
||||
/**
|
||||
* 同一材质的对象渲染列表
|
||||
|
@ -68,6 +68,9 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
const uint32_t GetMIDataBytes ()const{return mi_data_bytes;}
|
||||
const uint32_t GetMIMaxCount ()const{return mi_max_count;}
|
||||
|
||||
MaterialInstance *CreateMI(const VILConfig *vil_cfg=nullptr);
|
||||
};//class Material
|
||||
|
||||
|
@ -61,7 +61,7 @@ MaterialRenderList::MaterialRenderList(GPUDevice *d,Material *m)
|
||||
device=d;
|
||||
cmd_buf=nullptr;
|
||||
mtl=m;
|
||||
assign_buffer=nullptr;
|
||||
assign_buffer=new RenderAssignBuffer(d,mtl->GetMIDataBytes());
|
||||
|
||||
vbo_list=new VBOList(mtl->GetVertexInput()->GetCount());
|
||||
}
|
||||
@ -91,24 +91,10 @@ void MaterialRenderList::End()
|
||||
|
||||
if(node_count<=0)return;
|
||||
|
||||
if(!assign_buffer)
|
||||
assign_buffer=new RenderAssignBuffer;
|
||||
|
||||
if(assign_buffer->node_count<node_count)
|
||||
assign_buffer->NodeAlloc(device,node_count);
|
||||
|
||||
Stat();
|
||||
|
||||
//写入LocalToWorld数据
|
||||
assign_buffer->WriteLocalToWorld(rn_list.GetData(),node_count);
|
||||
|
||||
const uint mi_count=mi_set.GetCount();
|
||||
|
||||
if(mi_count<=0)return;
|
||||
|
||||
//if(assign_buffer->mi_count<mi_count)
|
||||
// assign_buffer->MIAlloc(device,mi_count,);
|
||||
//assign_buffer->WriteMaterialInstance(rn_list.GetData(),node_count,mi_set);
|
||||
assign_buffer->WriteNode(rn_list.GetData(),node_count,mi_set);
|
||||
}
|
||||
|
||||
void MaterialRenderList::RenderItem::Set(Renderable *ri)
|
||||
@ -226,7 +212,7 @@ bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
||||
// }
|
||||
//}
|
||||
|
||||
if(!vbo_list->IsFull())
|
||||
if(!vbo_list->IsFull()) //Assign组
|
||||
{
|
||||
const uint assign_binding_count=vil->GetCount(VertexInputGroup::Assign);
|
||||
|
||||
@ -239,7 +225,6 @@ bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if(count!=binding_count)
|
||||
//{
|
||||
// //还有没支持的绑定组????
|
||||
|
@ -25,7 +25,7 @@ void RenderAssignBuffer::Bind(MaterialInstance *mi)const
|
||||
// mi->BindUBO(DescriptorSetType::PerFrame,"Assign",assign_buffer->ubo_mi);
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::ClearNode()
|
||||
void RenderAssignBuffer::Clear()
|
||||
{
|
||||
SAFE_CLEAR(ubo_l2w);
|
||||
SAFE_CLEAR(ubo_mi);
|
||||
@ -34,47 +34,47 @@ void RenderAssignBuffer::ClearNode()
|
||||
node_count=0;
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::Clear()
|
||||
void RenderAssignBuffer::Alloc(const uint nc,const uint mc)
|
||||
{
|
||||
ClearNode();
|
||||
// ClearMI();
|
||||
Clear();
|
||||
|
||||
// SAFE_CLEAR(bone_id)
|
||||
// SAFE_CLEAR(bone_weight)
|
||||
{
|
||||
node_count=power_to_2(nc);
|
||||
|
||||
ubo_l2w=device->CreateUBO(node_count*sizeof(Matrix4f));
|
||||
}
|
||||
|
||||
{
|
||||
mi_count=power_to_2(mc);
|
||||
|
||||
ubo_mi=device->CreateUBO(mi_count*mi_data_bytes);
|
||||
}
|
||||
|
||||
vbo_assigns=device->CreateVBO(ASSIGN_VBO_FMT,node_count);
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::NodeAlloc(GPUDevice *dev,const uint c)
|
||||
{
|
||||
ClearNode();
|
||||
node_count=power_to_2(c);
|
||||
|
||||
ubo_l2w=dev->CreateUBO(node_count*sizeof(Matrix4f));
|
||||
//ubo_mi=dev->CreateUBO(node_count*sizeof(uint8));
|
||||
vbo_assigns=dev->CreateVBO(ASSIGN_VBO_FMT,node_count);
|
||||
}
|
||||
|
||||
//void MIAlloc(GPUDevice *dev,const uint c,const uint mis)
|
||||
//{
|
||||
// ClearMI();
|
||||
// if(c<=0||mi_size<=0)return;
|
||||
//
|
||||
// mi_count=power_to_2(c);
|
||||
// mi_size=mis;
|
||||
|
||||
// mi_id=dev->CreateVBO(VF_V1U8,mi_count);
|
||||
// mi_id_buffer=mi_id->GetBuffer();
|
||||
|
||||
// mi_data_buffer=dev->CreateUBO(mi_count*mi_size);
|
||||
//}
|
||||
|
||||
void RenderAssignBuffer::WriteLocalToWorld(RenderNode *render_node,const uint count)
|
||||
void RenderAssignBuffer::WriteNode(RenderNode *render_node,const uint count,const MaterialInstanceSets &mi_set)
|
||||
{
|
||||
RenderNode *rn;
|
||||
|
||||
//new l2w array in ubo
|
||||
Alloc(count,mi_set.GetCount());
|
||||
|
||||
{
|
||||
uint8 *mip=(uint8 *)(ubo_mi->Map());
|
||||
|
||||
for(MaterialInstance *mi:mi_set)
|
||||
{
|
||||
// memcpy(mip,mi->GetData(),mi_data_bytes);
|
||||
mip+=mi_data_bytes;
|
||||
}
|
||||
|
||||
ubo_mi->Unmap();
|
||||
}
|
||||
|
||||
uint16 *idp=(uint16 *)(vbo_assigns->Map());
|
||||
|
||||
{
|
||||
Matrix4f *tp=(hgl::Matrix4f *)(ubo_l2w->Map());
|
||||
uint16 *idp=(uint16 *)(vbo_assigns->Map());
|
||||
|
||||
rn=render_node;
|
||||
|
||||
@ -86,12 +86,16 @@ void RenderAssignBuffer::WriteLocalToWorld(RenderNode *render_node,const uint co
|
||||
*idp=i;
|
||||
++idp;
|
||||
|
||||
//*idp=mi_set.Find(rn->ri->GetMaterialInstance());
|
||||
//++idp;
|
||||
|
||||
++rn;
|
||||
}
|
||||
|
||||
vbo_assigns->Unmap();
|
||||
ubo_l2w->Unmap();
|
||||
}
|
||||
|
||||
vbo_assigns->Unmap();
|
||||
}
|
||||
|
||||
//void WriteMaterialInstance(RenderNode *render_node,const uint count,const MaterialInstanceSets &mi_set)
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
// ubo_range大致分为三档:
|
||||
@ -28,29 +28,28 @@ class MaterialInstance;
|
||||
/*
|
||||
* 渲染节点额外提供的数据
|
||||
*/
|
||||
struct RenderAssignBuffer
|
||||
class RenderAssignBuffer
|
||||
{
|
||||
uint node_count; ///<渲染节点数量
|
||||
// uint mi_count; ///<材质实例数量
|
||||
private:
|
||||
|
||||
//uint mi_size; ///<单个材质实例数量长度
|
||||
//DeviceBuffer *mi_data_buffer; ///<材质实例数据UBO/SSBO
|
||||
GPUDevice *device;
|
||||
|
||||
//VBO *mi_id;
|
||||
//VkBuffer mi_id_buffer;
|
||||
uint node_count; ///<渲染节点数量
|
||||
DeviceBuffer *ubo_l2w; ///<Local2World数据
|
||||
|
||||
// VBO *bone_id,*bone_weight;
|
||||
// VkBuffer bone_id_buffer,bone_weight_buffer;
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
//Assign UBO
|
||||
DeviceBuffer *ubo_l2w;
|
||||
DeviceBuffer *ubo_mi;
|
||||
uint mi_count; ///<材质实例数量
|
||||
uint mi_data_bytes; ///<单个材质实例数据字节数
|
||||
DeviceBuffer *ubo_mi; ///<材质实例数据
|
||||
|
||||
//Assign VBO
|
||||
VBO *vbo_assigns; ///<RG16UI格式的VertexInputStream,,,,X:L2W ID,Y:MI ID
|
||||
|
||||
private:
|
||||
|
||||
void Alloc(const uint nc,const uint mc);
|
||||
|
||||
void Clear();
|
||||
|
||||
public:
|
||||
|
||||
VkBuffer GetAssignVBO()const;
|
||||
@ -59,15 +58,18 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
RenderAssignBuffer(){hgl_zero(*this);}
|
||||
RenderAssignBuffer(GPUDevice *dev,const uint mi_bytes)
|
||||
{
|
||||
hgl_zero(*this);
|
||||
|
||||
device=dev;
|
||||
|
||||
mi_data_bytes=mi_bytes;
|
||||
}
|
||||
|
||||
~RenderAssignBuffer(){Clear();}
|
||||
|
||||
void ClearNode();
|
||||
|
||||
void Clear();
|
||||
|
||||
void NodeAlloc(GPUDevice *dev,const uint c);
|
||||
void WriteLocalToWorld(RenderNode *render_node,const uint count);
|
||||
void WriteNode(RenderNode *render_node,const uint count,const MaterialInstanceSets &mi_set);
|
||||
|
||||
};//struct RenderAssignBuffer
|
||||
VK_NAMESPACE_END
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
1.Material 材质可以简单理解为是Shader的包装。
|
||||
|
||||
2.Material Instance 材质实例是指同一材质下,不同的参数配置或不同的顶点输入格式。
|
||||
2.Material Instance 材质实例是指同一材质下,不同的参数配置。
|
||||
|
||||
## 我们需要做什么?
|
||||
|
||||
@ -43,7 +43,7 @@ layout(set=?,binding=?) uniform MaterialInstanceData
|
||||
2.建立一个RG8UI或RG16UI的Vertex Input Stream,用于保存访问LocalToWorld/MaterialInstance的索引
|
||||
|
||||
```glsl
|
||||
layout(location=?) in uvec2 Assign;
|
||||
layout(location=?) in uvec2 Assign; //Local To World矩阵ID与材质ID输入数据流
|
||||
|
||||
mat4 GetLocalToWorld()
|
||||
{
|
||||
|
@ -12,6 +12,8 @@ const VkDeviceSize GPUDevice::GetSSBORange (){return attr->physical_device->Get
|
||||
|
||||
bool GPUDevice::CreateBuffer(DeviceBufferData *buf,VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data,SharingMode sharing_mode)
|
||||
{
|
||||
if(size<=0)return(false);
|
||||
|
||||
BufferCreateInfo buf_info;
|
||||
|
||||
buf_info.usage = buf_usage;
|
||||
@ -55,6 +57,8 @@ bool GPUDevice::CreateBuffer(DeviceBufferData *buf,VkBufferUsageFlags buf_usage,
|
||||
|
||||
VBO *GPUDevice::CreateVBO(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode)
|
||||
{
|
||||
if(count==0)return(nullptr);
|
||||
|
||||
const uint32_t stride=GetStrideByFormat(format);
|
||||
|
||||
if(stride==0)
|
||||
@ -75,6 +79,8 @@ VBO *GPUDevice::CreateVBO(VkFormat format,uint32_t count,const void *data,Sharin
|
||||
|
||||
IndexBuffer *GPUDevice::CreateIBO(IndexType index_type,uint32_t count,const void *data,SharingMode sharing_mode)
|
||||
{
|
||||
if(count==0)return(nullptr);
|
||||
|
||||
uint32_t stride;
|
||||
|
||||
if(index_type==IndexType::U8 )stride=1;else
|
||||
@ -94,6 +100,8 @@ IndexBuffer *GPUDevice::CreateIBO(IndexType index_type,uint32_t count,const void
|
||||
|
||||
DeviceBuffer *GPUDevice::CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data,SharingMode sharing_mode)
|
||||
{
|
||||
if(size<=0)return(nullptr);
|
||||
|
||||
DeviceBufferData buf;
|
||||
|
||||
if(!CreateBuffer(&buf,buf_usage,range,size,data,sharing_mode))
|
||||
|
Loading…
x
Reference in New Issue
Block a user