mirror of
https://github.com/KhronosGroup/SPIRV-Cross.git
synced 2024-11-15 00:11:06 +00:00
MSL: Support option for treating 1D textures as 2D textures of height 1.
Add CompilerMSL::Options::texture_1D_as_2D. Metal imposes significant restrictions on 1D textures, including not being renderable, clearable, or permitting mipmaps. This option allows SPIR-V 1D textures to be treated as 2D textures to permit this additional behaviour. App must of course supply the textures to Metal as 2D textures.
This commit is contained in:
parent
ff1897ae0e
commit
4b5c6c188c
@ -6596,6 +6596,12 @@ string CompilerMSL::to_function_args(VariableID img, const SPIRType &imgtype, bo
|
||||
else if (sampling_type_needs_f32_conversion(coord_type))
|
||||
tex_coords = convert_to_f32(tex_coords, 1);
|
||||
|
||||
if (msl_options.texture_1D_as_2D)
|
||||
{
|
||||
string base_type = is_fetch ? "uint" : "float";
|
||||
tex_coords = base_type + "2(" + tex_coords + ", 0)";
|
||||
}
|
||||
|
||||
alt_coord_component = 1;
|
||||
break;
|
||||
|
||||
@ -6787,14 +6793,14 @@ string CompilerMSL::to_function_args(VariableID img, const SPIRType &imgtype, bo
|
||||
|
||||
// LOD Options
|
||||
// Metal does not support LOD for 1D textures.
|
||||
if (bias && imgtype.image.dim != Dim1D)
|
||||
if (bias && (imgtype.image.dim != Dim1D || msl_options.texture_1D_as_2D))
|
||||
{
|
||||
forward = forward && should_forward(bias);
|
||||
farg_str += ", bias(" + to_expression(bias) + ")";
|
||||
}
|
||||
|
||||
// Metal does not support LOD for 1D textures.
|
||||
if (lod && imgtype.image.dim != Dim1D)
|
||||
if (lod && (imgtype.image.dim != Dim1D || msl_options.texture_1D_as_2D))
|
||||
{
|
||||
forward = forward && should_forward(lod);
|
||||
if (is_fetch)
|
||||
@ -6806,8 +6812,8 @@ string CompilerMSL::to_function_args(VariableID img, const SPIRType &imgtype, bo
|
||||
farg_str += ", level(" + to_expression(lod) + ")";
|
||||
}
|
||||
}
|
||||
else if (is_fetch && !lod && imgtype.image.dim != Dim1D && imgtype.image.dim != DimBuffer && !imgtype.image.ms &&
|
||||
imgtype.image.sampled != 2)
|
||||
else if (is_fetch && !lod && (imgtype.image.dim != Dim1D || msl_options.texture_1D_as_2D) &&
|
||||
imgtype.image.dim != DimBuffer && !imgtype.image.ms && imgtype.image.sampled != 2)
|
||||
{
|
||||
// Lod argument is optional in OpImageFetch, but we require a LOD value, pick 0 as the default.
|
||||
// Check for sampled type as well, because is_fetch is also used for OpImageRead in MSL.
|
||||
@ -6815,7 +6821,7 @@ string CompilerMSL::to_function_args(VariableID img, const SPIRType &imgtype, bo
|
||||
}
|
||||
|
||||
// Metal does not support LOD for 1D textures.
|
||||
if ((grad_x || grad_y) && imgtype.image.dim != Dim1D)
|
||||
if ((grad_x || grad_y) && (imgtype.image.dim != Dim1D || msl_options.texture_1D_as_2D))
|
||||
{
|
||||
forward = forward && should_forward(grad_x);
|
||||
forward = forward && should_forward(grad_y);
|
||||
@ -9547,8 +9553,13 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id)
|
||||
switch (img_type.dim)
|
||||
{
|
||||
case Dim1D:
|
||||
img_type_name += "depth1d_unsupported_by_metal";
|
||||
break;
|
||||
if (!msl_options.texture_1D_as_2D)
|
||||
{
|
||||
// Use a native Metal 1D texture
|
||||
img_type_name += "depth1d_unsupported_by_metal";
|
||||
break;
|
||||
}
|
||||
// else fall through and use 2D
|
||||
case Dim2D:
|
||||
if (img_type.ms && img_type.arrayed)
|
||||
{
|
||||
@ -9578,9 +9589,6 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id)
|
||||
{
|
||||
switch (img_type.dim)
|
||||
{
|
||||
case Dim1D:
|
||||
img_type_name += (img_type.arrayed ? "texture1d_array" : "texture1d");
|
||||
break;
|
||||
case DimBuffer:
|
||||
if (img_type.ms || img_type.arrayed)
|
||||
SPIRV_CROSS_THROW("Cannot use texel buffers with multisampling or array layers.");
|
||||
@ -9594,6 +9602,14 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id)
|
||||
else
|
||||
img_type_name += "texture2d";
|
||||
break;
|
||||
case Dim1D:
|
||||
if (!msl_options.texture_1D_as_2D)
|
||||
{
|
||||
// Use a native Metal 1D texture
|
||||
img_type_name += (img_type.arrayed ? "texture1d_array" : "texture1d");
|
||||
break;
|
||||
}
|
||||
// else fall through and use 2D
|
||||
case Dim2D:
|
||||
case DimSubpassData:
|
||||
if (img_type.ms && img_type.arrayed)
|
||||
|
@ -274,6 +274,7 @@ public:
|
||||
bool multiview = false;
|
||||
bool view_index_from_device_index = false;
|
||||
bool dispatch_base = false;
|
||||
bool texture_1D_as_2D = false;
|
||||
|
||||
// Enable use of MSL 2.0 indirect argument buffers.
|
||||
// MSL 2.0 must also be enabled.
|
||||
|
Loading…
Reference in New Issue
Block a user