texture.gather.hlsl 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Run: %dxc -T ps_6_0 -E main
  2. SamplerState gSampler : register(s1);
  3. Texture2D <float4> t2 : register(t2);
  4. TextureCube <uint3> t4 : register(t4);
  5. Texture2D <int2> t6 : register(t6);
  6. TextureCube <float> t8 : register(t8);
  7. // .Gather() does not support Texture1D and Texture3D.
  8. // CHECK: OpCapability SparseResidency
  9. // CHECK: [[v2ic:%\d+]] = OpConstantComposite %v2int %int_1 %int_2
  10. // CHECK: [[v3fc:%\d+]] = OpConstantComposite %v3float %float_0_1 %float_0_2 %float_0_3
  11. // CHECK: %SparseResidencyStruct = OpTypeStruct %uint %v4int
  12. // CHECK: %SparseResidencyStruct_0 = OpTypeStruct %uint %v4float
  13. float4 main(float2 location: A) : SV_Target {
  14. // CHECK: [[t2:%\d+]] = OpLoad %type_2d_image %t2
  15. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  16. // CHECK-NEXT: [[loc:%\d+]] = OpLoad %v2float %location
  17. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image [[t2]] [[gSampler]]
  18. // CHECK-NEXT: {{%\d+}} = OpImageGather %v4float [[sampledImg]] [[loc]] %int_0 ConstOffset [[v2ic]]
  19. float4 val2 = t2.Gather(gSampler, location, int2(1, 2));
  20. // CHECK: [[t4:%\d+]] = OpLoad %type_cube_image %t4
  21. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  22. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t4]] [[gSampler]]
  23. // CHECK-NEXT: {{%\d+}} = OpImageGather %v4uint [[sampledImg]] [[v3fc]] %int_0
  24. uint4 val4 = t4.Gather(gSampler, float3(0.1, 0.2, 0.3));
  25. // CHECK: [[t6:%\d+]] = OpLoad %type_2d_image_0 %t6
  26. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  27. // CHECK-NEXT: [[loc:%\d+]] = OpLoad %v2float %location
  28. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[t6]] [[gSampler]]
  29. // CHECK-NEXT: {{%\d+}} = OpImageGather %v4int [[sampledImg]] [[loc]] %int_0 ConstOffset [[v2ic]]
  30. int4 val6 = t6.Gather(gSampler, location, int2(1, 2));
  31. // CHECK: [[t8:%\d+]] = OpLoad %type_cube_image_0 %t8
  32. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  33. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_2 [[t8]] [[gSampler]]
  34. // CHECK-NEXT: {{%\d+}} = OpImageGather %v4float [[sampledImg]] [[v3fc]] %int_0
  35. float4 val8 = t8.Gather(gSampler, float3(0.1, 0.2, 0.3));
  36. uint status;
  37. // CHECK: [[t6:%\d+]] = OpLoad %type_2d_image_0 %t6
  38. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  39. // CHECK-NEXT: [[loc:%\d+]] = OpLoad %v2float %location
  40. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[t6]] [[gSampler]]
  41. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseGather %SparseResidencyStruct [[sampledImg]] [[loc]] %int_0 ConstOffset [[v2ic]]
  42. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  43. // CHECK-NEXT: OpStore %status [[status]]
  44. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4int [[structResult]] 1
  45. // CHECK-NEXT: OpStore %val9 [[result]]
  46. int4 val9 = t6.Gather(gSampler, location, int2(1, 2), status);
  47. // CHECK: [[t8:%\d+]] = OpLoad %type_cube_image_0 %t8
  48. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  49. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_2 [[t8]] [[gSampler]]
  50. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseGather %SparseResidencyStruct_0 [[sampledImg]] [[v3fc]] %int_0 None
  51. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  52. // CHECK-NEXT: OpStore %status [[status]]
  53. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  54. // CHECK-NEXT: OpStore %val10 [[result]]
  55. float4 val10 = t8.Gather(gSampler, float3(0.1, 0.2, 0.3), status);
  56. return 1.0;
  57. }