From 3ec0833f590b462bd25103b58194592265130aad Mon Sep 17 00:00:00 2001 From: HuYingzhuo Date: Thu, 25 Apr 2019 21:57:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SPIRV-Cross=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 5 ++++ example/Vulkan/CMakeLists.txt | 2 +- example/Vulkan/FlatColor.vert | 4 +-- example/Vulkan/VKDevice.cpp | 12 ++++----- example/Vulkan/VKMaterial.cpp | 3 +++ example/Vulkan/VKMaterial.h | 5 +++- example/Vulkan/VKShader.cpp | 47 +++++++++++++++++++++++++++++++++++ inc/hgl/TypeFunc.h | 13 ++++++++++ 8 files changed, 81 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7efe29e..e731bc66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,11 +15,16 @@ 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() diff --git a/example/Vulkan/CMakeLists.txt b/example/Vulkan/CMakeLists.txt index 4d7bfa50..2c8aa09f 100644 --- a/example/Vulkan/CMakeLists.txt +++ b/example/Vulkan/CMakeLists.txt @@ -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) diff --git a/example/Vulkan/FlatColor.vert b/example/Vulkan/FlatColor.vert index 3b5a4715..f1325560 100644 --- a/example/Vulkan/FlatColor.vert +++ b/example/Vulkan/FlatColor.vert @@ -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; diff --git a/example/Vulkan/VKDevice.cpp b/example/Vulkan/VKDevice.cpp index 60b5a3cf..a60ab90f 100644 --- a/example/Vulkan/VKDevice.cpp +++ b/example/Vulkan/VKDevice.cpp @@ -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 diff --git a/example/Vulkan/VKMaterial.cpp b/example/Vulkan/VKMaterial.cpp index 6c92693d..61ba7428 100644 --- a/example/Vulkan/VKMaterial.cpp +++ b/example/Vulkan/VKMaterial.cpp @@ -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 diff --git a/example/Vulkan/VKMaterial.h b/example/Vulkan/VKMaterial.h index 4238b20d..1f5382eb 100644 --- a/example/Vulkan/VKMaterial.h +++ b/example/Vulkan/VKMaterial.h @@ -6,6 +6,7 @@ VK_NAMESPACE_BEGIN class Shader; class DescriptorSetLayoutCreater; class MaterialInstance; +class VertexInputState; /** * 材质类
@@ -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(); diff --git a/example/Vulkan/VKShader.cpp b/example/Vulkan/VKShader.cpp index 516d23b9..8686624c 100644 --- a/example/Vulkan/VKShader.cpp +++ b/example/Vulkan/VKShader.cpp @@ -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 ["<