texture.array.gather-red.hlsl 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Run: %dxc -T ps_6_0 -E main
  2. SamplerState gSampler : register(s5);
  3. Texture2DArray<float4> t2f4 : register(t1);
  4. Texture2DArray<uint> t2u1 : register(t2);
  5. TextureCubeArray<int4> tCubeArray : register(t3);
  6. // .GatherRed() does not support Texture1DArray.
  7. // CHECK: OpCapability SparseResidency
  8. // CHECK: [[c12:%\d+]] = OpConstantComposite %v2int %int_1 %int_2
  9. // CHECK: [[c34:%\d+]] = OpConstantComposite %v2int %int_3 %int_4
  10. // CHECK: [[c56:%\d+]] = OpConstantComposite %v2int %int_5 %int_6
  11. // CHECK: [[c78:%\d+]] = OpConstantComposite %v2int %int_7 %int_8
  12. // CHECK: [[c1to8:%\d+]] = OpConstantComposite %_arr_v2int_uint_4 [[c12]] [[c34]] [[c56]] [[c78]]
  13. // CHECK: %SparseResidencyStruct = OpTypeStruct %uint %v4uint
  14. // CHECK: [[cv4f_1_5:%\d+]] = OpConstantComposite %v4float %float_1_5 %float_1_5 %float_1_5 %float_1_5
  15. // CHECK: %SparseResidencyStruct_0 = OpTypeStruct %uint %v4int
  16. float4 main(float3 location: A, int2 offset : B) : SV_Target {
  17. // CHECK: [[t2f4:%\d+]] = OpLoad %type_2d_image_array %t2f4
  18. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  19. // CHECK-NEXT: [[loc:%\d+]] = OpLoad %v3float %location
  20. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image [[t2f4]] [[gSampler]]
  21. // CHECK-NEXT: [[res:%\d+]] = OpImageGather %v4float [[sampledImg]] [[loc]] %int_0 ConstOffset [[c12]]
  22. // CHECK-NEXT: OpStore %a [[res]]
  23. float4 a = t2f4.GatherRed(gSampler, location, int2(1, 2));
  24. // CHECK: [[t2f4:%\d+]] = OpLoad %type_2d_image_array %t2f4
  25. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  26. // CHECK-NEXT: [[loc:%\d+]] = OpLoad %v3float %location
  27. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image [[t2f4]] [[gSampler]]
  28. // CHECK-NEXT: [[res:%\d+]] = OpImageGather %v4float [[sampledImg]] [[loc]] %int_0 ConstOffsets [[c1to8]]
  29. // CHECK-NEXT: OpStore %b [[res]]
  30. float4 b = t2f4.GatherRed(gSampler, location, int2(1, 2), int2(3, 4), int2(5, 6), int2(7, 8));
  31. // CHECK: [[t2u1:%\d+]] = OpLoad %type_2d_image_array_0 %t2u1
  32. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  33. // CHECK-NEXT: [[loc:%\d+]] = OpLoad %v3float %location
  34. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2u1]] [[gSampler]]
  35. // CHECK-NEXT: [[res:%\d+]] = OpImageGather %v4uint [[sampledImg]] [[loc]] %int_0 ConstOffset [[c12]]
  36. // CHECK-NEXT: OpStore %c [[res]]
  37. uint4 c = t2u1.GatherRed(gSampler, location, int2(1, 2));
  38. // CHECK: [[t2u1:%\d+]] = OpLoad %type_2d_image_array_0 %t2u1
  39. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  40. // CHECK-NEXT: [[loc:%\d+]] = OpLoad %v3float %location
  41. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2u1]] [[gSampler]]
  42. // CHECK-NEXT: [[res:%\d+]] = OpImageGather %v4uint [[sampledImg]] [[loc]] %int_0 ConstOffsets [[c1to8]]
  43. // CHECK-NEXT: OpStore %d [[res]]
  44. uint4 d = t2u1.GatherRed(gSampler, location, int2(1, 2), int2(3, 4), int2(5, 6), int2(7, 8));
  45. uint status;
  46. // CHECK: [[t2u1:%\d+]] = OpLoad %type_2d_image_array_0 %t2u1
  47. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  48. // CHECK-NEXT: [[loc:%\d+]] = OpLoad %v3float %location
  49. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2u1]] [[gSampler]]
  50. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseGather %SparseResidencyStruct [[sampledImg]] [[loc]] %int_0 ConstOffset [[c12]]
  51. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  52. // CHECK-NEXT: OpStore %status [[status]]
  53. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4uint [[structResult]] 1
  54. // CHECK-NEXT: OpStore %e [[result]]
  55. uint4 e = t2u1.GatherRed(gSampler, location, int2(1, 2), status);
  56. // CHECK: [[t2u1:%\d+]] = OpLoad %type_2d_image_array_0 %t2u1
  57. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  58. // CHECK-NEXT: [[loc:%\d+]] = OpLoad %v3float %location
  59. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2u1]] [[gSampler]]
  60. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseGather %SparseResidencyStruct [[sampledImg]] [[loc]] %int_0 ConstOffsets [[c1to8]]
  61. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  62. // CHECK-NEXT: OpStore %status [[status]]
  63. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4uint [[structResult]] 1
  64. // CHECK-NEXT: OpStore %f [[result]]
  65. uint4 f = t2u1.GatherRed(gSampler, location, int2(1, 2), int2(3, 4), int2(5, 6), int2(7, 8), status);
  66. // CHECK: [[tCubeArray:%\d+]] = OpLoad %type_cube_image_array %tCubeArray
  67. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  68. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[tCubeArray]] [[gSampler]]
  69. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseGather %SparseResidencyStruct_0 [[sampledImg]] [[cv4f_1_5]] %int_0 None
  70. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  71. // CHECK-NEXT: OpStore %status [[status]]
  72. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4int [[structResult]] 1
  73. // CHECK-NEXT: OpStore %g [[result]]
  74. int4 g = tCubeArray.GatherRed(gSampler, /*location*/ float4(1.5, 1.5, 1.5, 1.5), status);
  75. // CHECK: [[offset:%\d+]] = OpLoad %v2int %offset
  76. // CHECK: [[gather:%\d+]] = OpImageGather %v4float {{%\d+}} {{%\d+}} %int_0 Offset [[offset]]
  77. // CHECK: [[texel0:%\d+]] = OpCompositeExtract %float [[gather]] 0
  78. // CHECK: [[gather:%\d+]] = OpImageGather %v4float {{%\d+}} {{%\d+}} %int_0 Offset [[c34]]
  79. // CHECK: [[texel1:%\d+]] = OpCompositeExtract %float [[gather]] 1
  80. // CHECK: [[gather:%\d+]] = OpImageGather %v4float {{%\d+}} {{%\d+}} %int_0 Offset [[c56]]
  81. // CHECK: [[texel2:%\d+]] = OpCompositeExtract %float [[gather]] 2
  82. // CHECK: [[offset:%\d+]] = OpLoad %v2int %offset
  83. // CHECK: [[gather:%\d+]] = OpImageGather %v4float {{%\d+}} {{%\d+}} %int_0 Offset [[offset]]
  84. // CHECK: [[texel3:%\d+]] = OpCompositeExtract %float [[gather]] 3
  85. // CHECK: OpCompositeConstruct %v4float [[texel0]] [[texel1]] [[texel2]] [[texel3]]
  86. float4 h = t2f4.GatherRed(gSampler, location, offset, int2(3, 4), int2(5, 6), offset);
  87. return 1.0;
  88. }