Merge branch 'devel_23_instance' of https://github.com/hyzboy/ULRE into devel_23_instance

This commit is contained in:
hyzboy 2022-03-31 23:36:54 +08:00
commit ef7068be08
12 changed files with 67 additions and 31 deletions

2
CMCore

@ -1 +1 @@
Subproject commit 6c2f5b255c0c04e20531e2fc8ac7843df264fa5b Subproject commit bfed461c84e7b780a3ab7a86d2c45e27b247f29f

View File

@ -109,12 +109,12 @@ private:
rb_config.Color.Set(1,1,1,1); rb_config.Color.Set(1,1,1,1);
rb_config.OutColor.Set(0,0,0,0); rb_config.OutColor.Set(0,0,0,0);
rb_config.InColor.Use(COLOR::MozillaOrange,1.0); rb_config.InColor=GetColor4f(COLOR::MozillaOrange,1.0);
rb_config.Radius[0]=0; rb_config.Radius[0]=0;
rb_config.Radius[1]=16; rb_config.Radius[1]=16;
rb_config.Radius[2]=0; rb_config.Radius[2]=0;
rb_config.Radius[3]=16; rb_config.Radius[3]=16;
rb_config.LineWidth=1.5; rb_config.LineWidth=2;
ubo_rb_config =db->CreateUBO(sizeof(RoundedBoxConfig), &rb_config); ubo_rb_config =db->CreateUBO(sizeof(RoundedBoxConfig), &rb_config);

View File

@ -17,7 +17,7 @@ class TestApp:public CameraAppFramework
{ {
struct struct
{ {
Color4f color; Color4f diffuse; //虽然shader中写vec3但这里依然用Color4f
Color4f abiment; Color4f abiment;
}color_material; }color_material;
@ -46,15 +46,17 @@ public:
{ {
start_time=GetDoubleTime(); start_time=GetDoubleTime();
} }
~TestApp()=default; ~TestApp()
{
SAFE_CLEAR(render_list);
}
private: private:
bool InitMaterial() bool InitMaterial()
{ {
material=db->CreateMaterial(OS_TEXT("res/shader/VertexLight.vert"), material=db->CreateMaterial(OS_TEXT("res/material/SimplestDirectionLight"));
OS_TEXT("res/shader/VertexColor.frag"));
if(!material) if(!material)
return(false); return(false);
@ -70,21 +72,29 @@ private:
bool InitUBO() bool InitUBO()
{ {
color_material.color.Set(1,1,1,1); color_material.diffuse.Set(1,1,1);
color_material.abiment.Set(0.25,0.25,0.25,1.0); color_material.abiment.Set(0.25,0.25,0.25);
ubo_color=device->CreateUBO(sizeof(color_material),&color_material); ubo_color=db->CreateUBO(sizeof(color_material),&color_material);
if(!ubo_color)return(false); if(!ubo_color)return(false);
sun_direction=normalized(Vector3f(rand(),rand(),rand())); sun_direction=normalized(Vector3f(rand(),rand(),rand()));
ubo_sun=device->CreateUBO(sizeof(sun_direction),&sun_direction); ubo_sun=db->CreateUBO(sizeof(sun_direction),&sun_direction);
if(!ubo_sun)return(false); if(!ubo_sun)return(false);
material_instance->BindUBO("color_material",ubo_color); {
material_instance->BindUBO("sun",ubo_sun); MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::Value);
material_instance->Update(); if(!mp)return(false);
mp->BindUBO("material",ubo_color);
mp->BindUBO("sun",ubo_sun);
mp->Update();
}
BindCameraUBO(material_instance);
return(true); return(true);
} }
@ -103,7 +113,7 @@ private:
uint count; uint count;
float size; float size;
RenderableInstance *ri=db->CreateRenderableInstance(pipeline,material_instance,renderable_object); RenderableInstance *ri=db->CreateRenderableInstance(renderable_object,material_instance,pipeline);
for(uint i=0;i<360;i++) for(uint i=0;i<360;i++)
{ {
@ -131,6 +141,8 @@ public:
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT)) if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false); return(false);
render_list=new RenderList(device);
if(!InitMaterial()) if(!InitMaterial())
return(false); return(false);
@ -152,16 +164,15 @@ public:
{ {
CameraAppFramework::Draw(); CameraAppFramework::Draw();
Matrix4f rot=rotate(GetDoubleTime()-start_time,camera.up_vector); Matrix4f rot=rotate(GetDoubleTime()-start_time,camera->world_up);
render_root.RefreshMatrix(&rot); render_root.RefreshMatrix(&rot);
render_list.Clear(); render_list->Expend(GetCameraInfo(),&render_root);
render_root.ExpendToList(&render_list);
} }
void BuildCommandBuffer(uint32 index) void BuildCommandBuffer(uint32 index)
{ {
VulkanApplicationFramework::BuildCommandBuffer(index,&render_list); VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
} }
};//class TestApp:public CameraAppFramework };//class TestApp:public CameraAppFramework

View File

@ -55,7 +55,7 @@ public:
bool BindSSBO (const int binding,const GPUBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range,bool dynamic=false); bool BindSSBO (const int binding,const GPUBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range,bool dynamic=false);
bool BindSampler(const int binding,Texture *,Sampler *); bool BindSampler(const int binding,Texture *,Sampler *);
bool BindInputAttachment(const int binding,Texture *); bool BindInputAttachment(const int binding,ImageView *);
void Update(); void Update();
};//class DescriptorSets };//class DescriptorSets
VK_NAMESPACE_END VK_NAMESPACE_END

View File

@ -29,10 +29,10 @@ public:
virtual ~ImageView(); virtual ~ImageView();
operator VkImageView(){return image_view;}
public: public:
VkImageView GetImageView () {return image_view;}
const VkImageViewType GetViewType ()const{return ivci->viewType;} const VkImageViewType GetViewType ()const{return ivci->viewType;}
const VkFormat GetFormat ()const{return ivci->format;} const VkFormat GetFormat ()const{return ivci->format;}
const VkExtent3D & GetExtent ()const{return extent;} const VkExtent3D & GetExtent ()const{return extent;}

View File

@ -47,7 +47,8 @@ public:
const int GetUBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);} const int GetUBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);}
const int GetSSBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,name);} const int GetSSBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,name);}
const int GetSampler (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, name);} const int GetSampler (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
const int GetAttachment (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
const DescriptorSetLayoutCreateInfo *GetBinding(const DescriptorSetsType &type)const{return sds+size_t(type);} const DescriptorSetLayoutCreateInfo *GetBinding(const DescriptorSetsType &type)const{return sds+size_t(type);}
};//class MaterialDescriptorSets };//class MaterialDescriptorSets

View File

@ -45,6 +45,7 @@ public:
bool BindUBO(const AnsiString &name,GPUBuffer *ubo,bool dynamic=false); bool BindUBO(const AnsiString &name,GPUBuffer *ubo,bool dynamic=false);
bool BindSSBO(const AnsiString &name,GPUBuffer *ubo,bool dynamic=false); bool BindSSBO(const AnsiString &name,GPUBuffer *ubo,bool dynamic=false);
bool BindSampler(const AnsiString &name,Texture *tex,Sampler *sampler); bool BindSampler(const AnsiString &name,Texture *tex,Sampler *sampler);
bool BindInputAttachment(const AnsiString &name,ImageView *);
void Update(); void Update();
};//class MaterialParameters };//class MaterialParameters

View File

@ -25,7 +25,7 @@ public:
VkDeviceMemory GetDeviceMemory () {return data?data->memory->operator VkDeviceMemory():VK_NULL_HANDLE;} VkDeviceMemory GetDeviceMemory () {return data?data->memory->operator VkDeviceMemory():VK_NULL_HANDLE;}
VkImage GetImage () {return data?data->image:VK_NULL_HANDLE;} VkImage GetImage () {return data?data->image:VK_NULL_HANDLE;}
VkImageLayout GetImageLayout () {return data?data->image_layout:VK_IMAGE_LAYOUT_UNDEFINED;} VkImageLayout GetImageLayout () {return data?data->image_layout:VK_IMAGE_LAYOUT_UNDEFINED;}
VkImageView GetVulkanImageView () {return data?data->image_view->operator VkImageView():VK_NULL_HANDLE;} VkImageView GetVulkanImageView () {return data?data->image_view->GetImageView():VK_NULL_HANDLE;}
GPUMemory * GetMemory () {return data?data->memory:nullptr;} GPUMemory * GetMemory () {return data?data->memory:nullptr;}
ImageView * GetImageView () {return data?data->image_view:nullptr;} ImageView * GetImageView () {return data?data->image_view:nullptr;}

2
res

@ -1 +1 @@
Subproject commit fd0bd99c873a376121eb534b99fe7fbfb24c2fd2 Subproject commit 70b697f13ef20e957d51efcb0ff8632f4615e3c0

View File

@ -57,6 +57,13 @@ namespace
imageView=tex->GetVulkanImageView(); imageView=tex->GetVulkanImageView();
imageLayout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; imageLayout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} }
DescriptorImageInfo(VkImageView iv)
{
sampler=VK_NULL_HANDLE;
imageView=iv;
imageLayout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
}
};//struct DescriptorImageInfo:public VkDescriptorImageInfo };//struct DescriptorImageInfo:public VkDescriptorImageInfo
}//namespace }//namespace
@ -159,14 +166,14 @@ bool DescriptorSets::BindSampler(const int binding,Texture *tex,Sampler *sampler
return(true); return(true);
} }
bool DescriptorSets::BindInputAttachment(const int binding,Texture *tex) bool DescriptorSets::BindInputAttachment(const int binding,ImageView *iv)
{ {
if(binding<0||!tex) if(binding<0||!iv)
return(false); return(false);
if(binded_sets.IsMember(binding))return(false); if(binded_sets.IsMember(binding))return(false);
DescriptorImageInfo *image_info=new DescriptorImageInfo(tex,nullptr); DescriptorImageInfo *image_info=new DescriptorImageInfo(iv->GetImageView());
image_list.Add(image_info); image_list.Add(image_info);

View File

@ -41,7 +41,7 @@ Framebuffer *GPUDevice::CreateFramebuffer(RenderPass *rp,ImageView **color_list,
if(*cf!=(*iv)->GetFormat()) if(*cf!=(*iv)->GetFormat())
return(nullptr); return(nullptr);
*ap=**iv; *ap=(*iv)->GetImageView();
++ap; ++ap;
++cf; ++cf;
@ -59,7 +59,7 @@ Framebuffer *GPUDevice::CreateFramebuffer(RenderPass *rp,ImageView **color_list,
return(nullptr); return(nullptr);
} }
attachments[color_count]=*depth; attachments[color_count]=depth->GetImageView();
extent.width=depth->GetExtent().width; extent.width=depth->GetExtent().width;
extent.height=depth->GetExtent().height; extent.height=depth->GetExtent().height;

View File

@ -64,6 +64,22 @@ bool MaterialParameters::BindSampler(const AnsiString &name,Texture *tex,Sampler
return(true); return(true);
} }
bool MaterialParameters::BindInputAttachment(const AnsiString &name,ImageView *iv)
{
if(name.IsEmpty()||!iv)
return(false);
const int index=mds->GetAttachment(name);
if(index<0)
return(false);
if(!descriptor_sets->BindInputAttachment(index,iv))
return(false);
return(true);
}
void MaterialParameters::Update() void MaterialParameters::Update()
{ {
descriptor_sets->Update(); descriptor_sets->Update();