From 5d159645ec705a36d8318301208c892eac91601c Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sat, 17 Aug 2024 18:54:44 +0100 Subject: [PATCH] [*] Dummy SM3.0 MSAA intrins --- spirv_hlsl.cpp | 56 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index 784a6373..cc676f14 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -579,10 +579,13 @@ void CompilerHLSL::emit_builtin_outputs_in_struct() break; case BuiltInSampleMask: - if (hlsl_options.shader_model < 41 || execution.model != ExecutionModelFragment) - SPIRV_CROSS_THROW("Sample Mask output is only supported in PS 4.1 or higher."); - type = "uint"; - semantic = "SV_Coverage"; + if (hlsl_options.shader_model >= 41) + { + if (execution.model != ExecutionModelFragment) + SPIRV_CROSS_THROW("Sample Mask output is only supported in PS 4.1 or higher."); + type = "uint"; + semantic = "SV_Coverage"; + } break; case BuiltInFragDepth: @@ -799,17 +802,21 @@ void CompilerHLSL::emit_builtin_inputs_in_struct() break; case BuiltInSampleId: - if (legacy) - SPIRV_CROSS_THROW("Sample ID not supported in SM 3.0 or lower."); - type = "uint"; - semantic = "SV_SampleIndex"; + if (hlsl_options.shader_model > 30) + { + type = "uint"; + semantic = "SV_SampleIndex"; + } break; case BuiltInSampleMask: - if (hlsl_options.shader_model < 50 || get_entry_point().model != ExecutionModelFragment) - SPIRV_CROSS_THROW("Sample Mask input is only supported in PS 5.0 or higher."); - type = "uint"; - semantic = "SV_Coverage"; + if (hlsl_options.shader_model >= 50) + { + if (get_entry_point().model != ExecutionModelFragment) + SPIRV_CROSS_THROW("Sample Mask input is only supported in PS 5.0 or higher."); + type = "uint"; + semantic = "SV_Coverage"; + } break; case BuiltInGlobalInvocationId: @@ -3216,7 +3223,25 @@ void CompilerHLSL::emit_hlsl_entry_point() break; case BuiltInSampleMask: - statement(builtin, "[0] = stage_input.", builtin, ";"); + if (hlsl_options.shader_model >= 50) + { + statement(builtin, "[0] = stage_input.", builtin, ";"); + } + else + { + statement(builtin, "[0] = 0;"); + } + break; + + case BuiltInSampleId: + if (hlsl_options.shader_model > 30) + { + statement(builtin, " = stage_input.", builtin, ";"); + } + else + { + statement(builtin, " = 0;"); + } break; case BuiltInNumWorkgroups: @@ -3394,7 +3419,10 @@ void CompilerHLSL::emit_hlsl_entry_point() break; case BuiltInSampleMask: - statement("stage_output.gl_SampleMask = gl_SampleMask[0];"); + if (hlsl_options.shader_model >= 50) + { + statement("stage_output.gl_SampleMask = gl_SampleMask[0];"); + } break; default: