2
0

texture.array.sample-level.hlsl 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Run: %dxc -T ps_6_0 -E main
  2. SamplerState gSampler : register(s5);
  3. // Note: The front end forbids sampling from non-floating-point texture formats.
  4. Texture1DArray <float4> t1 : register(t1);
  5. Texture2DArray <float4> t2 : register(t2);
  6. TextureCubeArray <float4> t3 : register(t3);
  7. Texture2DArray <float> t4 : register(t4);
  8. TextureCubeArray <float3> t5 : register(t5);
  9. // CHECK: OpCapability ImageGatherExtended
  10. // CHECK: OpCapability SparseResidency
  11. // CHECK: [[v2fc:%\d+]] = OpConstantComposite %v2float %float_1 %float_1
  12. // CHECK: %type_sampled_image = OpTypeSampledImage %type_1d_image_array
  13. // CHECK: [[v3fc:%\d+]] = OpConstantComposite %v3float %float_1 %float_2 %float_1
  14. // CHECK: %type_sampled_image_0 = OpTypeSampledImage %type_2d_image_array
  15. // CHECK: [[v4fc:%\d+]] = OpConstantComposite %v4float %float_1 %float_2 %float_3 %float_1
  16. // CHECK: %type_sampled_image_1 = OpTypeSampledImage %type_cube_image_array
  17. // CHECK: %SparseResidencyStruct = OpTypeStruct %uint %v4float
  18. float4 main(int2 offset : A) : SV_Target {
  19. // CHECK: [[t1:%\d+]] = OpLoad %type_1d_image_array %t1
  20. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  21. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image [[t1]] [[gSampler]]
  22. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v2fc]] Lod|ConstOffset %float_10 %int_1
  23. float4 val1 = t1.SampleLevel(gSampler, float2(1, 1), 10, 1);
  24. // CHECK: [[t2:%\d+]] = OpLoad %type_2d_image_array %t2
  25. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  26. // CHECK-NEXT: [[offset:%\d+]] = OpLoad %v2int %offset
  27. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2]] [[gSampler]]
  28. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v3fc]] Lod|Offset %float_20 [[offset]]
  29. float4 val2 = t2.SampleLevel(gSampler, float3(1, 2, 1), 20, offset);
  30. // CHECK: [[t3:%\d+]] = OpLoad %type_cube_image_array %t3
  31. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  32. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[t3]] [[gSampler]]
  33. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v4fc]] Lod %float_30
  34. float4 val3 = t3.SampleLevel(gSampler, float4(1, 2, 3, 1), 30);
  35. uint status;
  36. // CHECK: [[t2:%\d+]] = OpLoad %type_2d_image_array %t2
  37. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  38. // CHECK-NEXT: [[offset:%\d+]] = OpLoad %v2int %offset
  39. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2]] [[gSampler]]
  40. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseSampleExplicitLod %SparseResidencyStruct [[sampledImg]] [[v3fc]] Lod|Offset %float_20 [[offset]]
  41. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  42. // CHECK-NEXT: OpStore %status [[status]]
  43. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  44. // CHECK-NEXT: OpStore %val4 [[result]]
  45. float4 val4 = t2.SampleLevel(gSampler, float3(1, 2, 1), 20, offset, status);
  46. // CHECK: [[t3:%\d+]] = OpLoad %type_cube_image_array %t3
  47. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  48. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[t3]] [[gSampler]]
  49. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseSampleExplicitLod %SparseResidencyStruct [[sampledImg]] [[v4fc]] Lod %float_30
  50. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  51. // CHECK-NEXT: OpStore %status [[status]]
  52. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  53. // CHECK-NEXT: OpStore %val5 [[result]]
  54. float4 val5 = t3.SampleLevel(gSampler, float4(1, 2, 3, 1), 30, status);
  55. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  56. // Make sure OpImageSampleExplicitLod returns a vec4.
  57. // Make sure OpImageSparseSampleExplicitLod returns a struct, in which the second member is a vec4.
  58. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  59. // CHECK: [[v4result:%\d+]] = OpImageSampleExplicitLod %v4float {{%\d+}} {{%\d+}} Lod|Offset %float_20 {{%\d+}}
  60. // CHECK: {{%\d+}} = OpCompositeExtract %float [[v4result]] 0
  61. float val6 = t4.SampleLevel(gSampler, float3(1, 2, 1), 20, offset);
  62. // CHECK: [[structResult:%\d+]] = OpImageSparseSampleExplicitLod %SparseResidencyStruct {{%\d+}} {{%\d+}} Lod %float_30
  63. // CHECK: [[v4result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  64. // CHECK: {{%\d+}} = OpVectorShuffle %v3float [[v4result]] [[v4result]] 0 1 2
  65. float3 val7 = t5.SampleLevel(gSampler, float4(1, 2, 3, 1), 30, status);
  66. return 1.0;
  67. }