增加SPIRV-Cross测试代码
This commit is contained in:
parent
7e514acbea
commit
3ec0833f59
@ -15,11 +15,16 @@ check_system_version()
|
|||||||
set_compiler_param()
|
set_compiler_param()
|
||||||
set_output_directory()
|
set_output_directory()
|
||||||
|
|
||||||
|
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
add_subdirectory(3rdpty/glfw)
|
add_subdirectory(3rdpty/glfw)
|
||||||
include_directories(3rdpty/glfw/include)
|
include_directories(3rdpty/glfw/include)
|
||||||
|
|
||||||
include_directories(${Vulkan_INCLUDE_DIRS})
|
include_directories(${Vulkan_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
SET(SPIRV_CROSS_PATH 3rdpty/SPIRV-Cross)
|
||||||
|
include_directories(${SPIRV_CROSS_PATH})
|
||||||
|
add_subdirectory(${SPIRV_CROSS_PATH})
|
||||||
|
|
||||||
SET(OPENGL_LIB opengl32)
|
SET(OPENGL_LIB opengl32)
|
||||||
ELSE()
|
ELSE()
|
||||||
|
@ -61,4 +61,4 @@ SOURCE_GROUP("Shader Files" FILES ${SHADER_FILES})
|
|||||||
|
|
||||||
add_executable(VulkanTest ${VULKAN_TEST_HEADER_FILES} ${VULKAN_TEST_SOURCE_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)
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
layout(location = 0) in vec2 Vertex;
|
layout(location = 0) in vec2 Vertex;
|
||||||
layout(location = 1) in vec3 Color;
|
layout(location = 1) in vec3 Color;
|
||||||
|
|
||||||
layout (binding = 0) uniform MVPMatrix
|
layout(binding = 0) uniform MVPMatrix
|
||||||
{
|
{
|
||||||
mat4 MVP;
|
mat4 MVP;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
layout(location = 0) out vec4 FragmentColor;
|
layout(location = 0) out vec4 FragmentColor;
|
||||||
|
@ -347,10 +347,10 @@ bool Device::QueuePresent()
|
|||||||
return(vkQueuePresentKHR(attr->present_queue, &present)==VK_SUCCESS);
|
return(vkQueuePresentKHR(attr->present_queue, &present)==VK_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Material *Device::CreateMaterial(Shader *shader)
|
//Material *Device::CreateMaterial(Shader *shader)
|
||||||
{
|
//{
|
||||||
DescriptorSetLayoutCreater *dslc=new DescriptorSetLayoutCreater(this);
|
// DescriptorSetLayoutCreater *dslc=new DescriptorSetLayoutCreater(this);
|
||||||
|
//
|
||||||
return(new Material(shader,dslc));
|
// return(new Material(shader,dslc));
|
||||||
}
|
//}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include"VKMaterial.h"
|
#include"VKMaterial.h"
|
||||||
|
#include"VKDescriptorSets.h"
|
||||||
|
#include"VKShader.h"
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
Material::~Material()
|
Material::~Material()
|
||||||
{
|
{
|
||||||
@ -8,5 +10,6 @@ Material::~Material()
|
|||||||
|
|
||||||
MaterialInstance *Material::CreateInstance()
|
MaterialInstance *Material::CreateInstance()
|
||||||
{
|
{
|
||||||
|
return(nullptr);
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -6,6 +6,7 @@ VK_NAMESPACE_BEGIN
|
|||||||
class Shader;
|
class Shader;
|
||||||
class DescriptorSetLayoutCreater;
|
class DescriptorSetLayoutCreater;
|
||||||
class MaterialInstance;
|
class MaterialInstance;
|
||||||
|
class VertexInputState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 材质类<br>
|
* 材质类<br>
|
||||||
@ -14,13 +15,15 @@ class MaterialInstance;
|
|||||||
class Material
|
class Material
|
||||||
{
|
{
|
||||||
Shader *shader;
|
Shader *shader;
|
||||||
|
VertexInputState *vis;
|
||||||
DescriptorSetLayoutCreater *dsl_creater;
|
DescriptorSetLayoutCreater *dsl_creater;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Material(Shader *s,DescriptorSetLayoutCreater *dslc)
|
Material(Shader *s,VertexInputState *state,DescriptorSetLayoutCreater *dslc)
|
||||||
{
|
{
|
||||||
shader=s;
|
shader=s;
|
||||||
|
vis=state;
|
||||||
dsl_creater=dslc;
|
dsl_creater=dslc;
|
||||||
}
|
}
|
||||||
~Material();
|
~Material();
|
||||||
|
@ -1,6 +1,51 @@
|
|||||||
#include"VKShader.h"
|
#include"VKShader.h"
|
||||||
|
#include"spirv_cross.hpp"
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
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()
|
Shader::~Shader()
|
||||||
{
|
{
|
||||||
const int count=shader_stage_list.GetCount();
|
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)
|
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;
|
VkPipelineShaderStageCreateInfo shader_stage;
|
||||||
shader_stage.sType=VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
shader_stage.sType=VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||||
shader_stage.pNext=nullptr;
|
shader_stage.pNext=nullptr;
|
||||||
|
@ -531,6 +531,19 @@ namespace hgl
|
|||||||
memset(data,0,count*sizeof(T));
|
memset(data,0,count*sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分配指定类型数据块并清0
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
inline T *hgl_zero_new(const size_t count)
|
||||||
|
{
|
||||||
|
if(count<=0)return(nullptr);
|
||||||
|
|
||||||
|
T *data=new T[count];
|
||||||
|
memset(data,0,count*sizeof(T));
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指定类型数据清0
|
* 指定类型数据清0
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user