Support Metal 2.1's texture_buffer type which is the equivalent to HLSL's Buffer/RWBuffer, so doesn't require modifying buffer sizes to match alignments.

This commit is contained in:
Mark Satterthwaite 2019-08-14 10:43:04 -04:00 committed by Lukas Hermanns
parent 8596bf5ee2
commit 239e04762b
2 changed files with 22 additions and 5 deletions

View File

@ -3398,6 +3398,9 @@ void CompilerMSL::emit_custom_functions()
case SPVFuncImplTexelBufferCoords: case SPVFuncImplTexelBufferCoords:
{ {
/* UE Change Begin: Add support for Metal 2.1's new texture_buffer type. */
if (msl_options.texel_buffer_texture_width > 0)
{
string tex_width_str = convert_to_string(msl_options.texel_buffer_texture_width); string tex_width_str = convert_to_string(msl_options.texel_buffer_texture_width);
statement("// Returns 2D texture coords corresponding to 1D texel buffer coords"); statement("// Returns 2D texture coords corresponding to 1D texel buffer coords");
/* UE Change Begin: Metal helper functions must be static force-inline otherwise they will cause problems when linked together in a single Metallib. */ /* UE Change Begin: Metal helper functions must be static force-inline otherwise they will cause problems when linked together in a single Metallib. */
@ -3408,6 +3411,13 @@ void CompilerMSL::emit_custom_functions()
statement(join("return uint2(tc % ", tex_width_str, ", tc / ", tex_width_str, ");")); statement(join("return uint2(tc % ", tex_width_str, ", tc / ", tex_width_str, ");"));
end_scope(); end_scope();
statement(""); statement("");
}
else
{
statement("// Returns 2D texture coords corresponding to 1D texel buffer coords");
statement("#define spvTexelBufferCoord(tc, Tex) uint2(tc % Tex.get_width(), tc / Tex.get_width())");
}
/* UE Change End: Add support for Metal 2.1's new texture_buffer type. */
break; break;
} }
@ -3563,7 +3573,6 @@ void CompilerMSL::emit_custom_functions()
statement(""); statement("");
break; break;
//<<<<<<< HEAD
case SPVFuncImplForwardArgs: case SPVFuncImplForwardArgs:
statement("template<typename T> struct spvRemoveReference { typedef T type; };"); statement("template<typename T> struct spvRemoveReference { typedef T type; };");
statement("template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };"); statement("template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };");
@ -3584,7 +3593,7 @@ void CompilerMSL::emit_custom_functions()
end_scope(); end_scope();
statement(""); statement("");
break; break;
//=======
case SPVFuncImplRowMajor2x3: case SPVFuncImplRowMajor2x3:
statement("// Implementation of a conversion of matrix content from RowMajor to ColumnMajor organization."); statement("// Implementation of a conversion of matrix content from RowMajor to ColumnMajor organization.");
/* UE Change Begin: Metal helper functions must be static force-inline otherwise they will cause problems when linked together in a single Metallib. */ /* UE Change Begin: Metal helper functions must be static force-inline otherwise they will cause problems when linked together in a single Metallib. */
@ -3660,7 +3669,6 @@ void CompilerMSL::emit_custom_functions()
end_scope(); end_scope();
statement(""); statement("");
break; break;
//>>>>>>>>>>>
case SPVFuncImplGetSwizzle: case SPVFuncImplGetSwizzle:
statement("enum class spvSwizzle : uint"); statement("enum class spvSwizzle : uint");
@ -6770,9 +6778,20 @@ string CompilerMSL::to_function_args(uint32_t img, const SPIRType &imgtype, bool
else else
{ {
// Metal texel buffer textures are 2D, so convert 1D coord to 2D. // Metal texel buffer textures are 2D, so convert 1D coord to 2D.
/* UE Change Begin: Add support for Metal 2.1's new texture_buffer type. */
if (is_fetch) if (is_fetch)
{
if (msl_options.texel_buffer_texture_width > 0)
{
tex_coords = "spvTexelBufferCoord(" + round_fp_tex_coords(tex_coords, coord_is_fp) + ")"; tex_coords = "spvTexelBufferCoord(" + round_fp_tex_coords(tex_coords, coord_is_fp) + ")";
} }
else
{
tex_coords = "spvTexelBufferCoord(" + round_fp_tex_coords(tex_coords, coord_is_fp) + ", " + to_expression(img) + ")";
}
}
/* UE Change Begin: Add support for Metal 2.1's new texture_buffer type. */
}
alt_coord_component = 1; alt_coord_component = 1;
break; break;

View File

@ -477,14 +477,12 @@ protected:
SPVFuncImplInverse4x4, SPVFuncImplInverse4x4,
SPVFuncImplInverse3x3, SPVFuncImplInverse3x3,
SPVFuncImplInverse2x2, SPVFuncImplInverse2x2,
//<<<<<<<<
SPVFuncImplRowMajor2x3, SPVFuncImplRowMajor2x3,
SPVFuncImplRowMajor2x4, SPVFuncImplRowMajor2x4,
SPVFuncImplRowMajor3x2, SPVFuncImplRowMajor3x2,
SPVFuncImplRowMajor3x4, SPVFuncImplRowMajor3x4,
SPVFuncImplRowMajor4x2, SPVFuncImplRowMajor4x2,
SPVFuncImplRowMajor4x3, SPVFuncImplRowMajor4x3,
//>>>>>>>>
// It is very important that this come before *Swizzle and ChromaReconstruct*, to ensure it's // It is very important that this come before *Swizzle and ChromaReconstruct*, to ensure it's
// emitted before them. // emitted before them.
SPVFuncImplForwardArgs, SPVFuncImplForwardArgs,