增加SPIRV-Cross测试代码

This commit is contained in:
2019-04-25 21:57:37 +08:00
parent 7e514acbea
commit 3ec0833f59
8 changed files with 81 additions and 10 deletions

View File

@@ -61,4 +61,4 @@ SOURCE_GROUP("Shader Files" FILES ${SHADER_FILES})
add_executable(VulkanTest ${VULKAN_TEST_HEADER_FILES} ${VULKAN_TEST_SOURCE_FILES} ${SHADER_FILES})
target_link_libraries(VulkanTest PRIVATE ${ULRE} ${VULKAN_LIB} ${RENDER_WINDOW_LIBRARY})
target_link_libraries(VulkanTest PRIVATE ${ULRE} ${VULKAN_LIB} ${RENDER_WINDOW_LIBRARY} spirv-cross-core)

View File

@@ -3,9 +3,9 @@
layout(location = 0) in vec2 Vertex;
layout(location = 1) in vec3 Color;
layout (binding = 0) uniform MVPMatrix
layout(binding = 0) uniform MVPMatrix
{
mat4 MVP;
mat4 MVP;
} ubo;
layout(location = 0) out vec4 FragmentColor;

View File

@@ -347,10 +347,10 @@ bool Device::QueuePresent()
return(vkQueuePresentKHR(attr->present_queue, &present)==VK_SUCCESS);
}
Material *Device::CreateMaterial(Shader *shader)
{
DescriptorSetLayoutCreater *dslc=new DescriptorSetLayoutCreater(this);
return(new Material(shader,dslc));
}
//Material *Device::CreateMaterial(Shader *shader)
//{
// DescriptorSetLayoutCreater *dslc=new DescriptorSetLayoutCreater(this);
//
// return(new Material(shader,dslc));
//}
VK_NAMESPACE_END

View File

@@ -1,4 +1,6 @@
#include"VKMaterial.h"
#include"VKDescriptorSets.h"
#include"VKShader.h"
VK_NAMESPACE_BEGIN
Material::~Material()
{
@@ -8,5 +10,6 @@ Material::~Material()
MaterialInstance *Material::CreateInstance()
{
return(nullptr);
}
VK_NAMESPACE_END

View File

@@ -6,6 +6,7 @@ VK_NAMESPACE_BEGIN
class Shader;
class DescriptorSetLayoutCreater;
class MaterialInstance;
class VertexInputState;
/**
* 材质类<br>
@@ -14,13 +15,15 @@ class MaterialInstance;
class Material
{
Shader *shader;
VertexInputState *vis;
DescriptorSetLayoutCreater *dsl_creater;
public:
Material(Shader *s,DescriptorSetLayoutCreater *dslc)
Material(Shader *s,VertexInputState *state,DescriptorSetLayoutCreater *dslc)
{
shader=s;
vis=state;
dsl_creater=dslc;
}
~Material();

View File

@@ -1,6 +1,51 @@
#include"VKShader.h"
#include"spirv_cross.hpp"
VK_NAMESPACE_BEGIN
void shader_dump(const void *spv_data,const uint32_t spv_size)
{
spirv_cross::Compiler comp((const uint32_t *)spv_data,spv_size/sizeof(uint32_t));
spirv_cross::ShaderResources res=comp.get_shader_resources();
for(auto &ref:res.sampled_images)
{
unsigned set=comp.get_decoration(ref.id,spv::DecorationDescriptorSet);
unsigned binding=comp.get_decoration(ref.id,spv::DecorationBinding);
const std::string name=comp.get_name(ref.id);
std::cout<<"sampled image ["<<ref.id<<":"<<name.c_str()<<"] set="<<set<<",binding="<<binding<<std::endl;
}
for(auto &ref:res.stage_inputs)
{
unsigned set=comp.get_decoration(ref.id,spv::DecorationDescriptorSet);
unsigned location=comp.get_decoration(ref.id,spv::DecorationLocation);
const std::string name=comp.get_name(ref.id);
std::cout<<"stage input ["<<ref.id<<":"<<name.c_str()<<"] set="<<set<<",location="<<location<<std::endl;
}
for(auto &ref:res.uniform_buffers)
{
unsigned set=comp.get_decoration(ref.id,spv::DecorationDescriptorSet);
unsigned binding=comp.get_decoration(ref.id,spv::DecorationBinding);
const std::string name=comp.get_name(ref.id);
std::cout<<"UBO ["<<ref.id<<":"<<name.c_str()<<"] set="<<set<<",binding="<<binding<<std::endl;
}
for(auto &ref:res.stage_outputs)
{
unsigned set=comp.get_decoration(ref.id,spv::DecorationDescriptorSet);
unsigned location=comp.get_decoration(ref.id,spv::DecorationLocation);
const std::string name=comp.get_name(ref.id);
std::cout<<"stage output ["<<ref.id<<":"<<name.c_str()<<"] set="<<set<<",location="<<location<<std::endl;
}
}
Shader::~Shader()
{
const int count=shader_stage_list.GetCount();
@@ -18,6 +63,8 @@ Shader::~Shader()
bool Shader::Add(const VkShaderStageFlagBits shader_stage_bit,const void *spv_data,const uint32_t spv_size)
{
shader_dump(spv_data,spv_size);
VkPipelineShaderStageCreateInfo shader_stage;
shader_stage.sType=VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
shader_stage.pNext=nullptr;