Merge pull request #257 from KhronosGroup/fix-215

Add support for querying SPIR-V Capabilities and Extensions.
This commit is contained in:
Hans-Kristian Arntzen 2017-08-15 15:48:15 +02:00 committed by GitHub
commit 6b7b76a63f
3 changed files with 41 additions and 2 deletions

View File

@ -399,6 +399,21 @@ static void print_spec_constants(const Compiler &compiler)
fprintf(stderr, "==================\n\n");
}
static void print_capabilities_and_extensions(const Compiler &compiler)
{
fprintf(stderr, "Capabilities\n");
fprintf(stderr, "============\n");
for (auto &capability : compiler.get_declared_capabilities())
fprintf(stderr, "Capability: %u\n", static_cast<unsigned>(capability));
fprintf(stderr, "============\n\n");
fprintf(stderr, "Extensions\n");
fprintf(stderr, "============\n");
for (auto &ext : compiler.get_declared_extensions())
fprintf(stderr, "Extension: %s\n", ext.c_str());
fprintf(stderr, "============\n\n");
}
struct PLSArg
{
PlsFormat format;
@ -819,6 +834,7 @@ int main(int argc, char *argv[])
print_resources(*compiler, res);
print_push_constant_resources(*compiler, res.push_constant_buffers);
print_spec_constants(*compiler);
print_capabilities_and_extensions(*compiler);
}
if (combined_image_samplers)

View File

@ -1247,12 +1247,17 @@ void Compiler::parse(const Instruction &instruction)
uint32_t cap = ops[0];
if (cap == CapabilityKernel)
SPIRV_CROSS_THROW("Kernel capability not supported.");
declared_capabilities.push_back(static_cast<Capability>(ops[0]));
break;
}
case OpExtension:
// Ignore extensions
{
auto ext = extract_string(spirv, instruction.offset);
declared_extensions.push_back(move(ext));
break;
}
case OpExtInstImport:
{
@ -3627,3 +3632,13 @@ void Compiler::make_constant_null(uint32_t id, uint32_t type)
constant.make_null(constant_type);
}
}
const std::vector<spv::Capability> &Compiler::get_declared_capabilities() const
{
return declared_capabilities;
}
const std::vector<std::string> &Compiler::get_declared_extensions() const
{
return declared_extensions;
}

View File

@ -358,6 +358,12 @@ public:
// To rely on this functionality, ensure that the SPIR-V module is not stripped.
bool buffer_get_hlsl_counter_buffer(uint32_t id, uint32_t &counter_id) const;
// Gets the list of all SPIR-V Capabilities which were declared in the SPIR-V module.
const std::vector<spv::Capability> &get_declared_capabilities() const;
// Gets the list of all SPIR-V extensions which were declared in the SPIR-V module.
const std::vector<std::string> &get_declared_extensions() const;
protected:
const uint32_t *stream(const Instruction &instr) const
{
@ -524,7 +530,6 @@ protected:
void analyze_variable_scope(SPIRFunction &function);
protected:
void parse();
void parse(const Instruction &i);
@ -673,6 +678,9 @@ protected:
};
void make_constant_null(uint32_t id, uint32_t type);
std::vector<spv::Capability> declared_capabilities;
std::vector<std::string> declared_extensions;
};
}