Compare commits

...

11 Commits

Author SHA1 Message Date
e4d6832d31 [*] SM3.0 fixes 2024-08-17 15:55:29 +01:00
Hans-Kristian Arntzen
66363ac7e8
Merge pull request #2357 from taisei-project/fix-matrix-stride
Fix incorrect return value for ParsedIR::get_member_decoration(SpvDecorationMatrixStride)
2024-07-30 09:49:39 +02:00
Andrei Alexeyev
b7dbf7a379
Fix incorrect return value for ParsedIR::get_member_decoration(SpvDecorationMatrixStride) 2024-07-23 16:47:03 +02:00
Hans-Kristian Arntzen
68d401117c
Merge pull request #2356 from KhronosGroup/fix-2348
HLSL: Implement SM 6.8 BaseVertex/BaseInstance.
2024-07-15 13:32:13 +02:00
Hans-Kristian Arntzen
1de3f8c1f2 HLSL: Implement SM 6.8 BaseVertex/BaseInstance. 2024-07-15 13:22:11 +02:00
Hans-Kristian Arntzen
d17a2d6940
Merge pull request #2351 from js6i/entry_point_decls
Stale access permissions for overlapping descriptors
2024-07-15 12:52:24 +02:00
Bill Hollings
1297499703 MSL: Minor fix to resource type of spvBufferSizeConstants array indexes.
- spvBufferSizeConstants tracks MSL indexes of buffers, not images.
- Previous code did not allow array index beyond zero.
2024-07-15 12:52:02 +02:00
Hans-Kristian Arntzen
ae75fccf71
Add more detailed comment explaining the force recompile hack. 2024-07-15 12:50:14 +02:00
Hans-Kristian Arntzen
c1bf9099b9
Merge pull request #2350 from etang-cw/QueryLod
Fix MSL for OpImageQueryLod on a vector larger than needed
2024-07-15 12:02:06 +02:00
Hans-Kristian Arntzen
abed74fb9b
Small nit. 2024-07-15 11:53:20 +02:00
Jan Sikorski
b37f1598ad MSL: Recompile when an aliased descriptor's name is changed. 2024-07-11 11:21:04 +02:00
12 changed files with 222 additions and 15 deletions

View File

@ -0,0 +1,25 @@
static float4 gl_Position;
static int gl_BaseInstanceARB;
struct SPIRV_Cross_Input
{
uint gl_BaseInstanceARB : SV_StartInstanceLocation;
};
struct SPIRV_Cross_Output
{
float4 gl_Position : SV_Position;
};
void vert_main()
{
gl_Position = float(gl_BaseInstanceARB).xxxx;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_BaseInstanceARB = stage_input.gl_BaseInstanceARB;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
return stage_output;
}

View File

@ -0,0 +1,25 @@
static float4 gl_Position;
static int gl_BaseVertexARB;
struct SPIRV_Cross_Input
{
uint gl_BaseVertexARB : SV_StartVertexLocation;
};
struct SPIRV_Cross_Output
{
float4 gl_Position : SV_Position;
};
void vert_main()
{
gl_Position = float(gl_BaseVertexARB).xxxx;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_BaseVertexARB = stage_input.gl_BaseVertexARB;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
return stage_output;
}

View File

@ -0,0 +1,28 @@
static float4 gl_Position;
static int gl_InstanceIndex;
static int gl_BaseInstanceARB;
struct SPIRV_Cross_Input
{
uint gl_InstanceIndex : SV_InstanceID;
uint gl_BaseInstanceARB : SV_StartInstanceLocation;
};
struct SPIRV_Cross_Output
{
float4 gl_Position : SV_Position;
};
void vert_main()
{
gl_Position = float(gl_InstanceIndex).xxxx;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_InstanceIndex = int(stage_input.gl_InstanceIndex + stage_input.gl_BaseInstanceARB);
gl_BaseInstanceARB = stage_input.gl_BaseInstanceARB;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
return stage_output;
}

View File

@ -0,0 +1,28 @@
static float4 gl_Position;
static int gl_VertexIndex;
static int gl_BaseVertexARB;
struct SPIRV_Cross_Input
{
uint gl_VertexIndex : SV_VertexID;
uint gl_BaseVertexARB : SV_StartVertexLocation;
};
struct SPIRV_Cross_Output
{
float4 gl_Position : SV_Position;
};
void vert_main()
{
gl_Position = float(gl_VertexIndex).xxxx;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_VertexIndex = int(stage_input.gl_VertexIndex + stage_input.gl_BaseVertexARB);
gl_BaseVertexARB = stage_input.gl_BaseVertexARB;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
return stage_output;
}

View File

@ -0,0 +1,7 @@
#version 450
#extension GL_ARB_shader_draw_parameters : require
void main()
{
gl_Position = vec4(gl_BaseInstanceARB);
}

View File

@ -0,0 +1,7 @@
#version 450
#extension GL_ARB_shader_draw_parameters : require
void main()
{
gl_Position = vec4(gl_BaseVertexARB);
}

View File

@ -0,0 +1,6 @@
#version 450
void main()
{
gl_Position = vec4(gl_InstanceIndex);
}

View File

@ -0,0 +1,6 @@
#version 450
void main()
{
gl_Position = vec4(gl_VertexIndex);
}

View File

@ -783,6 +783,8 @@ uint32_t ParsedIR::get_member_decoration(TypeID id, uint32_t index, Decoration d
return dec.stream;
case DecorationSpecId:
return dec.spec_id;
case DecorationMatrixStride:
return dec.matrix_stride;
case DecorationIndex:
return dec.index;
default:

View File

@ -783,6 +783,9 @@ void CompilerHLSL::emit_builtin_inputs_in_struct()
break;
case BuiltInPrimitiveId:
if (legacy)
SPIRV_CROSS_THROW("Primitive ID not supported in SM 3.0 or lower.");
type = "uint";
semantic = "SV_PrimitiveID";
break;
@ -830,8 +833,16 @@ void CompilerHLSL::emit_builtin_inputs_in_struct()
break;
case BuiltInFrontFacing:
type = "bool";
semantic = "SV_IsFrontFace";
if (legacy)
{
type = "float";
semantic = "VFACE";
}
else
{
type = "bool";
semantic = "SV_IsFrontFace";
}
break;
case BuiltInViewIndex:
@ -849,11 +860,25 @@ void CompilerHLSL::emit_builtin_inputs_in_struct()
case BuiltInSubgroupLeMask:
case BuiltInSubgroupGtMask:
case BuiltInSubgroupGeMask:
case BuiltInBaseVertex:
case BuiltInBaseInstance:
// Handled specially.
break;
case BuiltInBaseVertex:
if (hlsl_options.shader_model >= 68)
{
type = "uint";
semantic = "SV_StartVertexLocation";
}
break;
case BuiltInBaseInstance:
if (hlsl_options.shader_model >= 68)
{
type = "uint";
semantic = "SV_StartInstanceLocation";
}
break;
case BuiltInHelperInvocation:
if (hlsl_options.shader_model < 50 || get_entry_point().model != ExecutionModelFragment)
SPIRV_CROSS_THROW("Helper Invocation input is only supported in PS 5.0 or higher.");
@ -1231,7 +1256,7 @@ void CompilerHLSL::emit_builtin_variables()
case BuiltInVertexIndex:
case BuiltInInstanceIndex:
type = "int";
if (hlsl_options.support_nonzero_base_vertex_base_instance)
if (hlsl_options.support_nonzero_base_vertex_base_instance || hlsl_options.shader_model >= 68)
base_vertex_info.used = true;
break;
@ -1353,7 +1378,7 @@ void CompilerHLSL::emit_builtin_variables()
}
});
if (base_vertex_info.used)
if (base_vertex_info.used && hlsl_options.shader_model < 68)
{
string binding_info;
if (base_vertex_info.explicit_binding)
@ -3132,27 +3157,57 @@ void CompilerHLSL::emit_hlsl_entry_point()
}
break;
case BuiltInFrontFacing:
{
if (legacy)
statement(builtin, " = bool(stage_input.", builtin, " > 0.0 ? true : false);");
else
{
statement(builtin, " = int(stage_input.", builtin, ");");
}
break;
}
case BuiltInVertexId:
case BuiltInVertexIndex:
case BuiltInInstanceIndex:
// D3D semantics are uint, but shader wants int.
if (hlsl_options.support_nonzero_base_vertex_base_instance)
if (hlsl_options.support_nonzero_base_vertex_base_instance || hlsl_options.shader_model >= 68)
{
if (static_cast<BuiltIn>(i) == BuiltInInstanceIndex)
statement(builtin, " = int(stage_input.", builtin, ") + SPIRV_Cross_BaseInstance;");
if (hlsl_options.shader_model >= 68)
{
if (static_cast<BuiltIn>(i) == BuiltInInstanceIndex)
statement(builtin, " = int(stage_input.", builtin, " + stage_input.gl_BaseInstanceARB);");
else
statement(builtin, " = int(stage_input.", builtin, " + stage_input.gl_BaseVertexARB);");
}
else
statement(builtin, " = int(stage_input.", builtin, ") + SPIRV_Cross_BaseVertex;");
{
if (static_cast<BuiltIn>(i) == BuiltInInstanceIndex)
statement(builtin, " = int(stage_input.", builtin, ") + SPIRV_Cross_BaseInstance;");
else
statement(builtin, " = int(stage_input.", builtin, ") + SPIRV_Cross_BaseVertex;");
}
}
else
statement(builtin, " = int(stage_input.", builtin, ");");
break;
case BuiltInBaseVertex:
statement(builtin, " = SPIRV_Cross_BaseVertex;");
if (hlsl_options.shader_model >= 68)
statement(builtin, " = stage_input.gl_BaseVertexARB;");
else
statement(builtin, " = SPIRV_Cross_BaseVertex;");
break;
case BuiltInBaseInstance:
statement(builtin, " = SPIRV_Cross_BaseInstance;");
if (hlsl_options.shader_model >= 68)
statement(builtin, " = stage_input.gl_BaseInstanceARB;");
else
statement(builtin, " = SPIRV_Cross_BaseInstance;");
break;
case BuiltInInstanceId:
@ -6714,6 +6769,15 @@ string CompilerHLSL::compile()
if (need_subpass_input)
active_input_builtins.set(BuiltInFragCoord);
// Need to offset by BaseVertex/BaseInstance in SM 6.8+.
if (hlsl_options.shader_model >= 68)
{
if (active_input_builtins.get(BuiltInVertexIndex))
active_input_builtins.set(BuiltInBaseVertex);
if (active_input_builtins.get(BuiltInInstanceIndex))
active_input_builtins.set(BuiltInBaseInstance);
}
uint32_t pass_count = 0;
do
{

View File

@ -9262,8 +9262,8 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
auto sampler_expr = to_sampler_expression(image_id);
auto *combined = maybe_get<SPIRCombinedImageSampler>(image_id);
auto image_expr = combined ? to_expression(combined->image) : to_expression(image_id);
const SPIRType& image_type = expression_type(image_id);
const SPIRType& coord_type = expression_type(coord_id);
const SPIRType &image_type = expression_type(image_id);
const SPIRType &coord_type = expression_type(coord_id);
switch (image_type.image.dim)
{
@ -14085,7 +14085,7 @@ void CompilerMSL::fix_up_shader_inputs_outputs()
statement("constant uint", is_array_type ? "* " : "& ", to_buffer_size_expression(var_id),
is_array_type ? " = &" : " = ", to_name(argument_buffer_ids[desc_set]),
".spvBufferSizeConstants", "[",
convert_to_string(get_metal_resource_index(var, SPIRType::Image)), "];");
convert_to_string(get_metal_resource_index(var, SPIRType::UInt)), "];");
}
else
{
@ -18189,6 +18189,13 @@ void CompilerMSL::emit_argument_buffer_aliased_descriptor(const SPIRVariable &al
}
else
{
// This alias may have already been used to emit an entry point declaration. If there is a mismatch, we need a recompile.
// Moving this code to be run earlier will also conflict,
// because we need the qualified alias for the base resource,
// so forcing recompile until things sync up is the least invasive method for now.
if (ir.meta[aliased_var.self].decoration.qualified_alias != name)
force_recompile();
// This will get wrapped in a separate temporary when a spvDescriptorArray wrapper is emitted.
set_qualified_name(aliased_var.self, name);
}

View File

@ -494,6 +494,8 @@ def shader_to_sm(shader):
return '62'
elif '.sm60.' in shader:
return '60'
elif '.sm68.' in shader:
return '68'
elif '.sm51.' in shader:
return '51'
elif '.sm30.' in shader: