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