diff --git a/tests/out/hlsl/image.hlsl b/tests/out/hlsl/image.hlsl new file mode 100644 index 0000000000..f5f20b4ba2 --- /dev/null +++ b/tests/out/hlsl/image.hlsl @@ -0,0 +1,209 @@ +Texture2D image_src : register(t1); +RWTexture1D image_dst : register(u2); +Texture1D image_1d : register(t0); +Texture2D image_2d : register(t1); +Texture2DArray image_2d_array : register(t2); +TextureCube image_cube : register(t3); +TextureCubeArray image_cube_array : register(t4); +Texture3D image_3d : register(t5); +Texture2DMS image_aa : register(t6); +SamplerState sampler_reg : register(s0); +SamplerComparisonState sampler_cmp : register(s1); +Texture2D image_2d_depth : register(t2); + +struct ComputeInput_main { + uint3 local_id1 : SV_GroupThreadID; +}; + +int2 NagaDimensions2D(Texture2D) +{ + uint4 ret; + image_src.GetDimensions(0, ret.x, ret.y, ret.z); + return ret.xy; +} + +[numthreads(16, 1, 1)] +void main(ComputeInput_main computeinput_main) +{ + int2 dim = NagaDimensions2D(image_src); + int2 itc = (mul(dim, int2(computeinput_main.local_id1.xy)) % int2(10, 20)); + uint4 value = image_src.Load(int3(itc, 0)); + image_dst[itc.x] = value; + return; +} + +int NagaDimensions1D(Texture1D) +{ + uint4 ret; + image_1d.GetDimensions(ret.x); + return ret.x; +} + +int2 NagaDimensions2D(Texture2D) +{ + uint4 ret; + image_2d.GetDimensions(0, ret.x, ret.y, ret.z); + return ret.xy; +} + +int NagaNumLevels2D(Texture2D) +{ + uint4 ret; + image_2d.GetDimensions(0, ret.x, ret.y, ret.z); + return ret.z; +} + +int2 NagaMipDimensions2D(Texture2D, uint MipLevel) +{ + uint4 ret; + image_2d.GetDimensions(MipLevel, ret.x, ret.y, ret.z); + return ret.xy; +} + +int2 NagaDimensions2DArray(Texture2DArray) +{ + uint4 ret; + image_2d_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w); + return ret.xy; +} + +int NagaNumLevels2DArray(Texture2DArray) +{ + uint4 ret; + image_2d_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w); + return ret.w; +} + +int2 NagaMipDimensions2DArray(Texture2DArray, uint MipLevel) +{ + uint4 ret; + image_2d_array.GetDimensions(MipLevel, ret.x, ret.y, ret.z, ret.w); + return ret.xy; +} + +int NagaNumLayers2DArray(Texture2DArray) +{ + uint4 ret; + image_2d_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w); + return ret.w; +} + +int2 NagaDimensionsCube(TextureCube) +{ + uint4 ret; + image_cube.GetDimensions(0, ret.x, ret.y, ret.z); + return ret.xy; +} + +int NagaNumLevelsCube(TextureCube) +{ + uint4 ret; + image_cube.GetDimensions(0, ret.x, ret.y, ret.z); + return ret.z; +} + +int2 NagaMipDimensionsCube(TextureCube, uint MipLevel) +{ + uint4 ret; + image_cube.GetDimensions(MipLevel, ret.x, ret.y, ret.z); + return ret.xy; +} + +int2 NagaDimensionsCubeArray(TextureCubeArray) +{ + uint4 ret; + image_cube_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w); + return ret.xy; +} + +int NagaNumLevelsCubeArray(TextureCubeArray) +{ + uint4 ret; + image_cube_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w); + return ret.w; +} + +int2 NagaMipDimensionsCubeArray(TextureCubeArray, uint MipLevel) +{ + uint4 ret; + image_cube_array.GetDimensions(MipLevel, ret.x, ret.y, ret.z, ret.w); + return ret.xy; +} + +int NagaNumLayersCubeArray(TextureCubeArray) +{ + uint4 ret; + image_cube_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w); + return ret.w; +} + +int3 NagaDimensions3D(Texture3D) +{ + uint4 ret; + image_3d.GetDimensions(0, ret.x, ret.y, ret.z, ret.w); + return ret.xyz; +} + +int NagaNumLevels3D(Texture3D) +{ + uint4 ret; + image_3d.GetDimensions(0, ret.x, ret.y, ret.z, ret.w); + return ret.w; +} + +int3 NagaMipDimensions3D(Texture3D, uint MipLevel) +{ + uint4 ret; + image_3d.GetDimensions(MipLevel, ret.x, ret.y, ret.z, ret.w); + return ret.xyz; +} + +int NagaMSNumSamples2D(Texture2DMS) +{ + uint4 ret; + image_aa.GetDimensions(ret.x, ret.y, ret.z); + return ret.z; +} + +float4 queries() : SV_Position +{ + int dim_1d = NagaDimensions1D(image_1d); + int2 dim_2d = NagaDimensions2D(image_2d); + int num_levels_2d = NagaNumLevels2D(image_2d); + int2 dim_2d_lod = NagaMipDimensions2D(image_2d, 1); + int2 dim_2d_array = NagaDimensions2DArray(image_2d_array); + int num_levels_2d_array = NagaNumLevels2DArray(image_2d_array); + int2 dim_2d_array_lod = NagaMipDimensions2DArray(image_2d_array, 1); + int num_layers_2d = NagaNumLayers2DArray(image_2d_array); + int2 dim_cube = NagaDimensionsCube(image_cube); + int num_levels_cube = NagaNumLevelsCube(image_cube); + int2 dim_cube_lod = NagaMipDimensionsCube(image_cube, 1); + int2 dim_cube_array = NagaDimensionsCubeArray(image_cube_array); + int num_levels_cube_array = NagaNumLevelsCubeArray(image_cube_array); + int2 dim_cube_array_lod = NagaMipDimensionsCubeArray(image_cube_array, 1); + int num_layers_cube = NagaNumLayersCubeArray(image_cube_array); + int3 dim_3d = NagaDimensions3D(image_3d); + int num_levels_3d = NagaNumLevels3D(image_3d); + int3 dim_3d_lod = NagaMipDimensions3D(image_3d, 1); + int num_samples_aa = NagaMSNumSamples2D(image_aa); + int sum = ((((((((((((((((((dim_1d + dim_2d.y) + dim_2d_lod.y) + dim_2d_array.y) + dim_2d_array_lod.y) + num_layers_2d) + dim_cube.y) + dim_cube_lod.y) + dim_cube_array.y) + dim_cube_array_lod.y) + num_layers_cube) + dim_3d.z) + dim_3d_lod.z) + num_samples_aa) + num_levels_2d) + num_levels_2d_array) + num_levels_3d) + num_levels_cube) + num_levels_cube_array); + return float4(float(sum).xxxx); +} + +float4 sample1() : SV_Target0 +{ + float2 tc = float2(0.5.xx); + float4 s2d = image_2d.Sample(sampler_reg, tc); + float4 s2d_offset = image_2d.Sample(sampler_reg, tc, int2(3, 1)); + float4 s2d_level = image_2d.SampleLevel(sampler_reg, tc, 2.3); + float4 s2d_level_offset = image_2d.SampleLevel(sampler_reg, tc, 2.3, int2(3, 1)); + return (((s2d + s2d_offset) + s2d_level) + s2d_level_offset); +} + +float sample_comparison() : SV_Target0 +{ + float2 tc = float2(0.5.xx); + float s2d_depth = image_2d_depth.SampleCmp(sampler_cmp, tc, 0.5); + float s2d_depth_level = image_2d_depth.SampleCmpLevelZero(sampler_cmp, tc, 0.5); + return (s2d_depth + s2d_depth_level); +} diff --git a/tests/out/hlsl/image.hlsl.config b/tests/out/hlsl/image.hlsl.config new file mode 100644 index 0000000000..3e97dafc35 --- /dev/null +++ b/tests/out/hlsl/image.hlsl.config @@ -0,0 +1,8 @@ +compute=cs_5_0 +compute_name=main +vertex=vs_5_0 +vertex_name=queries +fragment=ps_5_0 +fragment_name=sample1 +fragment=ps_5_0 +fragment_name=sample_comparison diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 323c851b5c..c0b1db87a5 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -355,7 +355,10 @@ fn convert_wgsl() { "shadow", Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::WGSL, ), - ("image", Targets::SPIRV | Targets::METAL | Targets::WGSL), + ( + "image", + Targets::SPIRV | Targets::METAL | Targets::HLSL | Targets::WGSL, + ), ("extra", Targets::SPIRV | Targets::METAL | Targets::WGSL), ( "operators",