增加SPIRV-Cross测试代码
This commit is contained in:
parent
7e514acbea
commit
3ec0833f59
@ -15,12 +15,17 @@ check_system_version()
|
||||
set_compiler_param()
|
||||
set_output_directory()
|
||||
|
||||
|
||||
IF(WIN32)
|
||||
add_subdirectory(3rdpty/glfw)
|
||||
include_directories(3rdpty/glfw/include)
|
||||
|
||||
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)
|
||||
ELSE()
|
||||
SET(OPENGL_LIB GL)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -532,6 +532,19 @@ namespace hgl
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配指定类型数据块并清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
|
||||
*/
|
||||
template<typename T>
|
||||
|
Loading…
x
Reference in New Issue
Block a user