Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/SPIRV-Cross.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChip Davis <cdavis@codeweavers.com>2020-11-21 00:41:46 +0300
committerChip Davis <cdavis@codeweavers.com>2020-11-23 19:30:24 +0300
commitfd738e3387535b4e18104336ff04a0c000ab5f45 (patch)
tree91102c719da448dbb1875b6082627e188f8bf7bc /main.cpp
parent782916a7971bbbd450f288c939ea838da0b2e6f1 (diff)
MSL: Adjust FragCoord for sample-rate shading.
In Metal, the `[[position]]` input to a fragment shader remains at fragment center, even at sample rate, like OpenGL and Direct3D. In Vulkan, however, when the fragment shader runs at sample rate, the `FragCoord` builtin moves to the sample position in the framebuffer, instead of the fragment center. To account for this difference, adjust the `FragCoord`, if present, by the sample position. The -0.5 offset is because the fragment center is at (0.5, 0.5). Also, add an option to force sample-rate shading in a fragment shader. Since Metal has no explicit control for this, this is done by adding a dummy `[[sample_id]]` which is otherwise unused, if none is already present. This is intended to be used from e.g. MoltenVK when a pipeline's `minSampleShading` value is nonzero. Instead of checking if any `Input` variables have `Sample` interpolation, I've elected to check that the `SampleRateShading` capability is present. Since `SampleId`, `SamplePosition`, and the `Sample` interpolation decoration require this cap, this should be equivalent for any valid SPIR-V module. If this isn't acceptable, let me know.
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/main.cpp b/main.cpp
index f9ee2e0d..59f4bd50 100644
--- a/main.cpp
+++ b/main.cpp
@@ -569,6 +569,7 @@ struct CLIArguments
bool msl_ios_use_simdgroup_functions = false;
bool msl_emulate_subgroups = false;
uint32_t msl_fixed_subgroup_size = 0;
+ bool msl_force_sample_rate_shading = false;
bool glsl_emit_push_constant_as_ubo = false;
bool glsl_emit_ubo_as_plain_uniforms = false;
bool glsl_force_flattened_io_blocks = false;
@@ -789,7 +790,9 @@ static void print_help_msl()
"\t\tIntended for Vulkan Portability implementations where Metal support for SIMD-groups is insufficient for true subgroups.\n"
"\t[--msl-fixed-subgroup-size <size>]:\n\t\tAssign a constant <size> to the SubgroupSize builtin.\n"
"\t\tIntended for Vulkan Portability implementations where VK_EXT_subgroup_size_control is not supported or disabled.\n"
- "\t\tIf 0, assume variable subgroup size as actually exposed by Metal.\n");
+ "\t\tIf 0, assume variable subgroup size as actually exposed by Metal.\n"
+ "\t[--msl-force-sample-rate-shading]:\n\t\tForce fragment shaders to run per sample.\n"
+ "\t\tThis adds a [[sample_id]] parameter if none is already present.\n");
// clang-format on
}
@@ -1034,6 +1037,7 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
msl_opts.ios_use_simdgroup_functions = args.msl_ios_use_simdgroup_functions;
msl_opts.emulate_subgroups = args.msl_emulate_subgroups;
msl_opts.fixed_subgroup_size = args.msl_fixed_subgroup_size;
+ msl_opts.force_sample_rate_shading = args.msl_force_sample_rate_shading;
msl_comp->set_msl_options(msl_opts);
for (auto &v : args.msl_discrete_descriptor_sets)
msl_comp->add_discrete_descriptor_set(v);
@@ -1466,6 +1470,7 @@ static int main_inner(int argc, char *argv[])
cbs.add("--msl-emulate-subgroups", [&args](CLIParser &) { args.msl_emulate_subgroups = true; });
cbs.add("--msl-fixed-subgroup-size",
[&args](CLIParser &parser) { args.msl_fixed_subgroup_size = parser.next_uint(); });
+ cbs.add("--msl-force-sample-rate-shading", [&args](CLIParser &) { args.msl_force_sample_rate_shading = true; });
cbs.add("--extension", [&args](CLIParser &parser) { args.extensions.push_back(parser.next_string()); });
cbs.add("--rename-entry-point", [&args](CLIParser &parser) {
auto old_name = parser.next_string();