example the first_triangle support ShaderResource

This commit is contained in:
hyzboy 2020-06-10 17:11:24 +08:00
parent d94e6dee6c
commit 26a434e9fb
5 changed files with 14 additions and 18 deletions

View File

@ -18,7 +18,6 @@
#include<hgl/graph/vulkan/VKMaterial.h> #include<hgl/graph/vulkan/VKMaterial.h>
#include<hgl/graph/vulkan/VKMaterialInstance.h> #include<hgl/graph/vulkan/VKMaterialInstance.h>
#include<hgl/graph/vulkan/VKRenderTarget.h> #include<hgl/graph/vulkan/VKRenderTarget.h>
#include<hgl/graph/shader/glsl2spv.h>
#include<hgl/graph/SceneDB.h> #include<hgl/graph/SceneDB.h>
#include<hgl/graph/RenderList.h> #include<hgl/graph/RenderList.h>

View File

@ -62,8 +62,8 @@ private:
bool InitMaterial() bool InitMaterial()
{ {
material=shader_manage->CreateMaterial(OS_TEXT("res/shader/FlatColor.vert.spv"), material=shader_manage->CreateMaterial(OS_TEXT("res/shader/FlatColor.vert"),
OS_TEXT("res/shader/VertexColor.frag.spv")); OS_TEXT("res/shader/VertexColor.frag"));
if(!material) if(!material)
return(false); return(false);
@ -91,13 +91,15 @@ private:
return(true); return(true);
} }
void InitVBO() bool InitVBO()
{ {
vertex_buffer =device->CreateVBO(FMT_RG32F, VERTEX_COUNT,vertex_data); vertex_buffer =device->CreateVBO(FMT_RG32F, VERTEX_COUNT,vertex_data);
color_buffer =device->CreateVBO(FMT_RGB32F, VERTEX_COUNT,color_data); color_buffer =device->CreateVBO(FMT_RGB32F, VERTEX_COUNT,color_data);
render_obj->Set("Vertex", vertex_buffer); if(!render_obj->Set("Vertex", vertex_buffer))return(false);
render_obj->Set("Color", color_buffer); if(!render_obj->Set("Color", color_buffer))return(false);
return(true);
} }
bool InitPipeline() bool InitPipeline()
@ -138,7 +140,8 @@ public:
if(!InitUBO()) if(!InitUBO())
return(false); return(false);
InitVBO(); if(!InitVBO())
return(false);
if(!InitPipeline()) if(!InitPipeline())
return(false); return(false);

2
res

@ -1 +1 @@
Subproject commit ee094e2efb1616014d18388eae4440fd740d07d1 Subproject commit c8c306e5a7cd3e975af4eb718f20ea16653ca4d3

View File

@ -30,12 +30,11 @@ VertexShaderModule::VertexShaderModule(VkDevice dev,int id,VkPipelineShaderStage
VkVertexInputBindingDescription *bind=binding_list; VkVertexInputBindingDescription *bind=binding_list;
VkVertexInputAttributeDescription *attr=attribute_list; VkVertexInputAttributeDescription *attr=attribute_list;
uint32_t binding_index=0;
ShaderStage **si=stage_inputs.GetData(); ShaderStage **si=stage_inputs.GetData();
for(uint i=0;i<attr_count;i++) for(uint i=0;i<attr_count;i++)
{ {
bind->binding =binding_index; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号所以这个数字必须从0开始而且紧密排列。 bind->binding =i; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号所以这个数字必须从0开始而且紧密排列。
//在VertexInput类中buf_list需要严格按照本此binding为序列号排列 //在VertexInput类中buf_list需要严格按照本此binding为序列号排列
bind->stride =GetStrideByFormat((*si)->format); bind->stride =GetStrideByFormat((*si)->format);
bind->inputRate =VK_VERTEX_INPUT_RATE_VERTEX; bind->inputRate =VK_VERTEX_INPUT_RATE_VERTEX;
@ -45,14 +44,13 @@ VertexShaderModule::VertexShaderModule(VkDevice dev,int id,VkPipelineShaderStage
//比如在一个流中传递{pos,color}这样两个数据就需要两个attrib //比如在一个流中传递{pos,color}这样两个数据就需要两个attrib
//但在我们的设计中仅支持一个流传递一个attrib //但在我们的设计中仅支持一个流传递一个attrib
attr->binding =binding_index; attr->binding =i;
attr->location =(*si)->location; //此值对应shader中的layout(location= attr->location =(*si)->location; //此值对应shader中的layout(location=
attr->format =(*si)->format; attr->format =(*si)->format;
attr->offset =0; attr->offset =0;
++attr; ++attr;
++bind; ++bind;
++binding_index;
++si; ++si;
} }

View File

@ -94,7 +94,7 @@ VK_NAMESPACE_BEGIN
for(int i=0;i<count;i++) for(int i=0;i<count;i++)
{ {
if(name==(*ss)->name) if(name==(*ss)->name)
return (*ss)->location; return i;
++ss; ++ss;
} }
@ -122,7 +122,7 @@ VK_NAMESPACE_BEGIN
ShaderResource *LoadShaderResoruce(const OSString &filename) ShaderResource *LoadShaderResoruce(const OSString &filename)
{ {
int64 filesize; int64 filesize;
uint8 *origin_filedata=(uint8 *)filesystem::LoadFileToMemory(filename,filesize); uint8 *origin_filedata=(uint8 *)filesystem::LoadFileToMemory(filename+OS_TEXT(".shader"),filesize);
if(!origin_filedata)return(nullptr); if(!origin_filedata)return(nullptr);
@ -159,10 +159,6 @@ VK_NAMESPACE_BEGIN
desc_type=AccessByPointer(filedata,uint32); desc_type=AccessByPointer(filedata,uint32);
filedata=LoadShaderDescriptor(sr->GetDescriptorList((VkDescriptorType)desc_type),filedata); filedata=LoadShaderDescriptor(sr->GetDescriptorList((VkDescriptorType)desc_type),filedata);
{
delete sr;
return(nullptr);
}
} }
return sr; return sr;