Vulkan: Add semantic name remapping.

Will be useful for custom named passes.
This commit is contained in:
Hans-Kristian Arntzen 2016-03-25 23:15:23 +01:00
parent 3838b3c045
commit 21c7ff99d1
3 changed files with 51 additions and 6 deletions

View File

@ -219,6 +219,10 @@ struct CommonResources
vector<Texture> original_history;
vector<Texture> framebuffer_feedback;
unordered_map<string, slang_texture_semantic_map> texture_semantic_map;
unordered_map<string, slang_texture_semantic_map> texture_semantic_uniform_map;
unordered_map<string, slang_semantic> semantic_map;
VkDevice device;
};
@ -1301,6 +1305,10 @@ bool Pass::build()
}
reflection = slang_reflection{};
reflection.texture_semantic_map = &common->texture_semantic_map;
reflection.texture_semantic_uniform_map = &common->texture_semantic_uniform_map;
reflection.semantic_map = &common->semantic_map;
if (!slang_reflect_spirv(vertex_shader, fragment_shader, &reflection))
return false;

View File

@ -102,18 +102,42 @@ static slang_texture_semantic slang_name_to_texture_semantic_array(const string
return SLANG_INVALID_TEXTURE_SEMANTIC;
}
static slang_texture_semantic slang_name_to_texture_semantic(const string &name, unsigned *index)
static slang_texture_semantic slang_name_to_texture_semantic(
const unordered_map<string, slang_texture_semantic_map> &semantic_map,
const string &name, unsigned *index)
{
auto itr = semantic_map.find(name);
if (itr != end(semantic_map))
{
*index = itr->second.index;
return itr->second.semantic;
}
return slang_name_to_texture_semantic_array(name, texture_semantic_names, index);
}
static slang_texture_semantic slang_uniform_name_to_texture_semantic(const string &name, unsigned *index)
static slang_texture_semantic slang_uniform_name_to_texture_semantic(
const unordered_map<string, slang_texture_semantic_map> &semantic_map,
const string &name, unsigned *index)
{
auto itr = semantic_map.find(name);
if (itr != end(semantic_map))
{
*index = itr->second.index;
return itr->second.semantic;
}
return slang_name_to_texture_semantic_array(name, texture_semantic_uniform_names, index);
}
static slang_semantic slang_uniform_name_to_semantic(const string &name)
static slang_semantic slang_uniform_name_to_semantic(
const unordered_map<string, slang_semantic> &semantic_map,
const string &name)
{
auto itr = semantic_map.find(name);
if (itr != end(semantic_map))
return itr->second;
unsigned i = 0;
for (auto n : semantic_uniform_names)
{
@ -227,8 +251,9 @@ static bool add_active_buffer_ranges(const Compiler &compiler, const Resource &r
auto &type = compiler.get_type(compiler.get_type(resource.type_id).member_types[range.index]);
unsigned tex_sem_index = 0;
auto sem = slang_uniform_name_to_semantic(name);
auto tex_sem = slang_uniform_name_to_texture_semantic(name, &tex_sem_index);
auto sem = slang_uniform_name_to_semantic(*reflection->semantic_map, name);
auto tex_sem = slang_uniform_name_to_texture_semantic(*reflection->texture_semantic_uniform_map,
name, &tex_sem_index);
if (sem != SLANG_INVALID_SEMANTIC)
{
@ -417,7 +442,8 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
binding_mask |= 1 << binding;
unsigned array_index = 0;
slang_texture_semantic index = slang_name_to_texture_semantic(texture.name, &array_index);
slang_texture_semantic index = slang_name_to_texture_semantic(*reflection->texture_semantic_map,
texture.name, &array_index);
if (index == SLANG_INVALID_TEXTURE_SEMANTIC)
{

View File

@ -17,6 +17,7 @@
#define SLANG_REFLECTION_HPP
#include <string>
#include <unordered_map>
#include <stdint.h>
// Textures with built-in meaning.
@ -88,6 +89,12 @@ struct slang_semantic_meta
bool uniform = false;
};
struct slang_texture_semantic_map
{
slang_texture_semantic semantic;
unsigned index;
};
struct slang_reflection
{
slang_reflection();
@ -98,6 +105,10 @@ struct slang_reflection
std::vector<slang_texture_semantic_meta> semantic_textures[SLANG_NUM_TEXTURE_SEMANTICS];
slang_semantic_meta semantics[SLANG_NUM_SEMANTICS];
const std::unordered_map<std::string, slang_texture_semantic_map> *texture_semantic_map = nullptr;
const std::unordered_map<std::string, slang_texture_semantic_map> *texture_semantic_uniform_map = nullptr;
const std::unordered_map<std::string, slang_semantic> *semantic_map = nullptr;
};
bool slang_reflect_spirv(const std::vector<uint32_t> &vertex,