Fix image load/store on cube arrays in MSL.

This commit is contained in:
Hans-Kristian Arntzen 2018-05-25 12:43:25 +02:00
parent 8bac5c09f3
commit 04b149feb0
4 changed files with 49 additions and 2 deletions

View File

@ -0,0 +1,10 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
kernel void main0(texturecube_array<float> uImageIn [[texture(0)]], texturecube_array<float, access::write> uImageOut [[texture(1)]])
{
uImageOut.write(uImageIn.read(uint2(int3(9, 7, 11).xy), uint(int3(9, 7, 11).z) % 6u, uint(int3(9, 7, 11).z) / 6u), uint2(int3(9, 7, 11).xy), uint(int3(9, 7, 11).z) % 6u, uint(int3(9, 7, 11).z) / 6u);
}

View File

@ -0,0 +1,12 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
kernel void main0(texturecube_array<float> uImageIn [[texture(0)]], texturecube_array<float, access::write> uImageOut [[texture(1)]])
{
int3 coord = int3(9, 7, 11);
float4 indata = uImageIn.read(uint2(coord.xy), uint(coord.z) % 6u, uint(coord.z) / 6u);
uImageOut.write(indata, uint2(coord.xy), uint(coord.z) % 6u, uint(coord.z) / 6u);
}

View File

@ -0,0 +1,13 @@
#version 450
layout(local_size_x = 1) in;
layout(r32f, binding = 0) uniform readonly imageCubeArray uImageIn;
layout(r32f, binding = 1) uniform writeonly imageCubeArray uImageOut;
void main()
{
ivec3 coord = ivec3(9, 7, 11);
vec4 indata = imageLoad(uImageIn, coord);
imageStore(uImageOut, coord, indata);
}

View File

@ -2613,11 +2613,23 @@ string CompilerMSL::to_function_args(uint32_t img, const SPIRType &imgtype, bool
// If fetch from cube, add face explicitly
if (is_cube_fetch)
farg_str += ", uint(" + round_fp_tex_coords(coord_expr + ".z", coord_is_fp) + ")";
{
// Special case for cube arrays, face and layer are packed in one dimension.
if (imgtype.image.arrayed)
farg_str += ", uint(" + join(coord_expr, ".z) % 6u");
else
farg_str += ", uint(" + round_fp_tex_coords(coord_expr + ".z", coord_is_fp) + ")";
}
// If array, use alt coord
if (imgtype.image.arrayed)
farg_str += ", uint(" + round_fp_tex_coords(coord_expr + alt_coord, coord_is_fp) + ")";
{
// Special case for cube arrays, face and layer are packed in one dimension.
if (imgtype.image.dim == DimCube && is_fetch)
farg_str += ", uint(" + join(coord_expr, ".z) / 6u");
else
farg_str += ", uint(" + round_fp_tex_coords(coord_expr + alt_coord, coord_is_fp) + ")";
}
// Depth compare reference value
if (dref)