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 /spirv_msl.hpp
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 'spirv_msl.hpp')
-rw-r--r--spirv_msl.hpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/spirv_msl.hpp b/spirv_msl.hpp
index 0b78df47..61d4fbea 100644
--- a/spirv_msl.hpp
+++ b/spirv_msl.hpp
@@ -401,6 +401,11 @@ public:
// different shaders for these three scenarios.
IndexType vertex_index_type = IndexType::None;
+ // If set, a dummy [[sample_id]] input is added to a fragment shader if none is present.
+ // This will force the shader to run at sample rate, assuming Metal does not optimize
+ // the extra threads away.
+ bool force_sample_rate_shading = false;
+
bool is_ios() const
{
return platform == iOS;
@@ -798,6 +803,7 @@ protected:
std::string to_sampler_expression(uint32_t id);
std::string to_swizzle_expression(uint32_t id);
std::string to_buffer_size_expression(uint32_t id);
+ bool is_sample_rate() const;
bool is_direct_input_builtin(spv::BuiltIn builtin);
std::string builtin_qualifier(spv::BuiltIn builtin);
std::string builtin_type_decl(spv::BuiltIn builtin, uint32_t id = 0);