Skip to content

Commit

Permalink
[hlsl-out] Enable image snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon-F authored and kvark committed Jul 16, 2021
1 parent 03a5ef3 commit 4ef754b
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 1 deletion.
209 changes: 209 additions & 0 deletions tests/out/hlsl/image.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
Texture2D<uint4> image_src : register(t1);
RWTexture1D<uint4> image_dst : register(u2);
Texture1D<float4> image_1d : register(t0);
Texture2D<float4> image_2d : register(t1);
Texture2DArray<float4> image_2d_array : register(t2);
TextureCube<float4> image_cube : register(t3);
TextureCubeArray<float4> image_cube_array : register(t4);
Texture3D<float4> image_3d : register(t5);
Texture2DMS<float4> 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>)
{
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<float4>)
{
uint4 ret;
image_1d.GetDimensions(ret.x);
return ret.x;
}

int2 NagaDimensions2D(Texture2D<float4>)
{
uint4 ret;
image_2d.GetDimensions(0, ret.x, ret.y, ret.z);
return ret.xy;
}

int NagaNumLevels2D(Texture2D<float4>)
{
uint4 ret;
image_2d.GetDimensions(0, ret.x, ret.y, ret.z);
return ret.z;
}

int2 NagaMipDimensions2D(Texture2D<float4>, uint MipLevel)
{
uint4 ret;
image_2d.GetDimensions(MipLevel, ret.x, ret.y, ret.z);
return ret.xy;
}

int2 NagaDimensions2DArray(Texture2DArray<float4>)
{
uint4 ret;
image_2d_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w);
return ret.xy;
}

int NagaNumLevels2DArray(Texture2DArray<float4>)
{
uint4 ret;
image_2d_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w);
return ret.w;
}

int2 NagaMipDimensions2DArray(Texture2DArray<float4>, uint MipLevel)
{
uint4 ret;
image_2d_array.GetDimensions(MipLevel, ret.x, ret.y, ret.z, ret.w);
return ret.xy;
}

int NagaNumLayers2DArray(Texture2DArray<float4>)
{
uint4 ret;
image_2d_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w);
return ret.w;
}

int2 NagaDimensionsCube(TextureCube<float4>)
{
uint4 ret;
image_cube.GetDimensions(0, ret.x, ret.y, ret.z);
return ret.xy;
}

int NagaNumLevelsCube(TextureCube<float4>)
{
uint4 ret;
image_cube.GetDimensions(0, ret.x, ret.y, ret.z);
return ret.z;
}

int2 NagaMipDimensionsCube(TextureCube<float4>, uint MipLevel)
{
uint4 ret;
image_cube.GetDimensions(MipLevel, ret.x, ret.y, ret.z);
return ret.xy;
}

int2 NagaDimensionsCubeArray(TextureCubeArray<float4>)
{
uint4 ret;
image_cube_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w);
return ret.xy;
}

int NagaNumLevelsCubeArray(TextureCubeArray<float4>)
{
uint4 ret;
image_cube_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w);
return ret.w;
}

int2 NagaMipDimensionsCubeArray(TextureCubeArray<float4>, uint MipLevel)
{
uint4 ret;
image_cube_array.GetDimensions(MipLevel, ret.x, ret.y, ret.z, ret.w);
return ret.xy;
}

int NagaNumLayersCubeArray(TextureCubeArray<float4>)
{
uint4 ret;
image_cube_array.GetDimensions(0, ret.x, ret.y, ret.z, ret.w);
return ret.w;
}

int3 NagaDimensions3D(Texture3D<float4>)
{
uint4 ret;
image_3d.GetDimensions(0, ret.x, ret.y, ret.z, ret.w);
return ret.xyz;
}

int NagaNumLevels3D(Texture3D<float4>)
{
uint4 ret;
image_3d.GetDimensions(0, ret.x, ret.y, ret.z, ret.w);
return ret.w;
}

int3 NagaMipDimensions3D(Texture3D<float4>, uint MipLevel)
{
uint4 ret;
image_3d.GetDimensions(MipLevel, ret.x, ret.y, ret.z, ret.w);
return ret.xyz;
}

int NagaMSNumSamples2D(Texture2DMS<float4>)
{
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);
}
8 changes: 8 additions & 0 deletions tests/out/hlsl/image.hlsl.config
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4ef754b

Please sign in to comment.