Add explicit support for remapping variables.

Will enable use of extensions like framebuffer fetch, last fragment
depth and so on.
This commit is contained in:
Hans-Kristian Arntzen 2016-07-06 09:58:01 +02:00
parent d5dc5f3f1c
commit 8e63c770da
4 changed files with 41 additions and 1 deletions

View File

@ -2000,3 +2000,13 @@ ExecutionModel Compiler::get_execution_model() const
{
return execution.model;
}
void Compiler::set_remapped_variable_state(uint32_t id, bool remap_enable)
{
get<SPIRVariable>(id).remapped_variable = remap_enable;
}
bool Compiler::get_remapped_variable_state(uint32_t id) const
{
return get<SPIRVariable>(id).remapped_variable;
}

View File

@ -171,6 +171,12 @@ public:
// Query shader resources, use ids with reflection interface to modify or query binding points, etc.
ShaderResources get_shader_resources() const;
// Remapped variables are considered built-in variables and a backend will
// not emit a declaration for this variable.
// This is mostly useful for making use of builtins which are dependent on extensions.
void set_remapped_variable_state(uint32_t id, bool remap_enable);
bool get_remapped_variable_state(uint32_t id) const;
// Query and modify OpExecutionMode.
uint64_t get_execution_mode_mask() const;
void unset_execution_mode(spv::ExecutionMode mode);

View File

@ -204,6 +204,9 @@ void CompilerGLSL::emit_header()
{
statement("#version ", options.version, options.es && options.version > 100 ? " es" : "");
for (auto &header : header_lines)
statement(header);
// Needed for binding = # on UBOs, etc.
if (!options.es && options.version < 420)
{
@ -4087,6 +4090,11 @@ void CompilerGLSL::add_resource_name(uint32_t id)
add_variable(resource_names, id);
}
void CompilerGLSL::add_header_line(const std::string &line)
{
header_lines.push_back(line);
}
void CompilerGLSL::require_extension(const string &ext)
{
if (forced_extensions.find(ext) == end(forced_extensions))

View File

@ -114,6 +114,22 @@ public:
}
std::string compile() override;
// Adds a line to be added right after #version in GLSL backend.
// This is useful for enabling custom extensions which are outside the scope of SPIRV-Cross.
// This can be combined with variable remapping.
// A new-line will be added.
//
// While add_header_line() is a more generic way of adding arbitrary text to the header
// of a GLSL file, require_extension() should be used when adding extensions since it will
// avoid creating collisions with SPIRV-Cross generated extensions.
//
// Code added via add_header_line() is typically backend-specific.
void add_header_line(const std::string &str);
// Adds an extension which is required to run this shader, e.g.
// require_extension("GL_KHR_my_extension");
void require_extension(const std::string &ext);
protected:
void reset();
void emit_function(SPIRFunction &func, uint64_t return_flags);
@ -288,7 +304,6 @@ protected:
// Can modify flags to remote readonly/writeonly if image type
// and force recompile.
bool check_atomic_image(uint32_t id);
void require_extension(const std::string &ext);
void replace_fragment_output(SPIRVariable &var);
void replace_fragment_outputs();
@ -306,6 +321,7 @@ protected:
void track_expression_read(uint32_t id);
std::unordered_set<std::string> forced_extensions;
std::vector<std::string> header_lines;
uint32_t statement_count;