From e92020819e49c0c23960299ed04f2c58c0c8ddc8 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Sat, 10 Sep 2016 13:05:35 +0200 Subject: [PATCH] Add reflection support for separate textures and samplers. --- main.cpp | 2 ++ spirv_cross.cpp | 14 +++++++++++++- spirv_cross.hpp | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index cd63ee9..10fda4b 100644 --- a/main.cpp +++ b/main.cpp @@ -317,6 +317,8 @@ static void print_resources(const Compiler &compiler, const ShaderResources &res print_resources(compiler, "inputs", res.stage_inputs); print_resources(compiler, "outputs", res.stage_outputs); print_resources(compiler, "textures", res.sampled_images); + print_resources(compiler, "separate textures", res.separate_images); + print_resources(compiler, "separate samplers", res.separate_samplers); print_resources(compiler, "images", res.storage_images); print_resources(compiler, "ssbos", res.storage_buffers); print_resources(compiler, "ubos", res.uniform_buffers); diff --git a/spirv_cross.cpp b/spirv_cross.cpp index e9b9193..8fdff0c 100644 --- a/spirv_cross.cpp +++ b/spirv_cross.cpp @@ -583,10 +583,22 @@ ShaderResources Compiler::get_shader_resources(const unordered_set *ac res.push_constant_buffers.push_back({ var.self, var.basetype, type.self, meta[var.self].decoration.alias }); } // Images - else if (type.storage == StorageClassUniformConstant && type.basetype == SPIRType::Image) + else if (type.storage == StorageClassUniformConstant && type.basetype == SPIRType::Image && + type.image.sampled == 2) { res.storage_images.push_back({ var.self, var.basetype, type.self, meta[var.self].decoration.alias }); } + // Separate images + else if (type.storage == StorageClassUniformConstant && type.basetype == SPIRType::Image && + type.image.sampled == 1) + { + res.separate_images.push_back({ var.self, var.basetype, type.self, meta[var.self].decoration.alias }); + } + // Separate samplers + else if (type.storage == StorageClassUniformConstant && type.basetype == SPIRType::Sampler) + { + res.separate_samplers.push_back({ var.self, var.basetype, type.self, meta[var.self].decoration.alias }); + } // Textures else if (type.storage == StorageClassUniformConstant && type.basetype == SPIRType::SampledImage) { diff --git a/spirv_cross.hpp b/spirv_cross.hpp index 07d8ed4..e583705 100644 --- a/spirv_cross.hpp +++ b/spirv_cross.hpp @@ -73,6 +73,11 @@ struct ShaderResources // There can only be one push constant block, // but keep the vector in case this restriction is lifted in the future. std::vector push_constant_buffers; + + // For Vulkan GLSL and HLSL source, + // these correspond to separate texture2D and samplers respectively. + std::vector separate_images; + std::vector separate_samplers; }; struct BufferRange