Skip to content

Commit

Permalink
Change 'target' env to 'source' env in spvc API (google#610)
Browse files Browse the repository at this point in the history
Clarify that the environment being referenced is the one associated
with the provided SPIR-V, and not the produced artifact.

Fixes google#609
  • Loading branch information
zoddicus authored May 10, 2019
1 parent dce7a4b commit 1475418
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
8 changes: 4 additions & 4 deletions libshaderc_spvc/include/shaderc/spvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ SHADERC_EXPORT void shaderc_spvc_compile_options_set_entry_point(
SHADERC_EXPORT void shaderc_spvc_compile_options_set_remove_unused_variables(
shaderc_spvc_compile_options_t options, bool b);

// Sets the target shader environment, affecting which warnings or errors will
// be issued during validation.
SHADERC_EXPORT void shaderc_spvc_compile_options_set_target_env(
shaderc_spvc_compile_options_t options, shaderc_target_env target,
// Sets the source shader environment, affecting which warnings or errors will
// be issued during validation. Default value for environment is Vulkan 1.0.
SHADERC_EXPORT void shaderc_spvc_compile_options_set_source_env(
shaderc_spvc_compile_options_t options, shaderc_target_env env,
shaderc_env_version version);

// If true, Vulkan GLSL features are used instead of GL-compatible features.
Expand Down
7 changes: 3 additions & 4 deletions libshaderc_spvc/include/shaderc/spvc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ class CompileOptions {
other.options_ = nullptr;
}

// Which environment should be used to validate the input SPIR-V. Default is
// Vulkan 1.0.
void SetTargetEnvironment(shaderc_target_env target,
// Set the environment for the input SPIR-V. Default is Vulkan 1.0.
void SetSourceEnvironment(shaderc_target_env env,
shaderc_env_version version) {
shaderc_spvc_compile_options_set_target_env(options_, target, version);
shaderc_spvc_compile_options_set_source_env(options_, env, version);
}

// Set the entry point.
Expand Down
16 changes: 8 additions & 8 deletions libshaderc_spvc/src/spvc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct shaderc_spvc_compile_options {
bool remove_unused_variables = false;
bool flatten_ubo = false;
std::string entry_point;
spv_target_env target_env = SPV_ENV_VULKAN_1_0;
spv_target_env source_env = SPV_ENV_VULKAN_1_0;
spirv_cross::CompilerGLSL::Options glsl;
spirv_cross::CompilerHLSL::Options hlsl;
spirv_cross::CompilerMSL::Options msl;
Expand Down Expand Up @@ -66,15 +66,15 @@ void shaderc_spvc_compile_options_release(
delete options;
}

void shaderc_spvc_compile_options_set_target_env(
shaderc_spvc_compile_options_t options, shaderc_target_env target,
void shaderc_spvc_compile_options_set_source_env(
shaderc_spvc_compile_options_t options, shaderc_target_env env,
shaderc_env_version version) {
switch (target) {
switch (env) {
case shaderc_target_env_opengl:
case shaderc_target_env_opengl_compat:
switch (version) {
case shaderc_env_version_opengl_4_5:
options->target_env = SPV_ENV_OPENGL_4_5;
options->source_env = SPV_ENV_OPENGL_4_5;
break;
default:
break;
Expand All @@ -83,10 +83,10 @@ void shaderc_spvc_compile_options_set_target_env(
case shaderc_target_env_vulkan:
switch (version) {
case shaderc_env_version_vulkan_1_0:
options->target_env = SPV_ENV_VULKAN_1_0;
options->source_env = SPV_ENV_VULKAN_1_0;
break;
case shaderc_env_version_vulkan_1_1:
options->target_env = SPV_ENV_VULKAN_1_1;
options->source_env = SPV_ENV_VULKAN_1_1;
break;
default:
break;
Expand Down Expand Up @@ -184,7 +184,7 @@ shaderc_spvc_compilation_result_t validate_and_compile(
if (!result) return nullptr;

if (options->validate) {
spvtools::SpirvTools tools(options->target_env);
spvtools::SpirvTools tools(options->source_env);
if (!tools.IsValid()) return nullptr;
tools.SetMessageConsumer(std::bind(
consume_validation_message, result, std::placeholders::_1,
Expand Down
4 changes: 2 additions & 2 deletions spvc/README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ with a `.glsl,` `.hlsl` or `.msl` extension, as appropriate.

`--version` displays version information.

==== `--validate=<target env>`
==== `--validate=<source env>`

`--validate` validates the input with the given target environment, which is one of:
`--validate` validates the input with the given environment, which is one of:

* vulkan1.0
* vulkan1.1
Expand Down
14 changes: 7 additions & 7 deletions spvc/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,16 @@ int main(int argc, char** argv) {
}
options.SetShaderModel(shader_model_num);
} else if (arg.starts_with("--validate=")) {
string_piece target_env;
GetOptionArgument(argc, argv, &i, "--validate=", &target_env);
if (target_env == "vulkan1.0") {
options.SetTargetEnvironment(shaderc_target_env_vulkan,
string_piece env;
GetOptionArgument(argc, argv, &i, "--validate=", &env);
if (env == "vulkan1.0") {
options.SetSourceEnvironment(shaderc_target_env_vulkan,
shaderc_env_version_vulkan_1_0);
} else if (target_env == "vulkan1.1") {
options.SetTargetEnvironment(shaderc_target_env_vulkan,
} else if (env == "vulkan1.1") {
options.SetSourceEnvironment(shaderc_target_env_vulkan,
shaderc_env_version_vulkan_1_1);
} else {
std::cerr << "spvc: error: invalid value '" << target_env
std::cerr << "spvc: error: invalid value '" << env
<< "' in --validate=" << std::endl;
return 1;
}
Expand Down

0 comments on commit 1475418

Please sign in to comment.