texture.sample-level.hlsl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. Texture1D <float4> t1 : register(t1);
  5. Texture2D <float4> t2 : register(t2);
  6. Texture3D <float4> t3 : register(t3);
  7. TextureCube <float4> t4 : register(t4);
  8. Texture3D <float> t5 : register(t5);
  9. TextureCube <float2> t6 : register(t6);
  10. // CHECK: OpCapability ImageGatherExtended
  11. // CHECK: OpCapability SparseResidency
  12. // CHECK: %type_sampled_image = OpTypeSampledImage %type_1d_image
  13. // CHECK: [[v2fc:%\d+]] = OpConstantComposite %v2float %float_1 %float_2
  14. // CHECK: [[v2ic:%\d+]] = OpConstantComposite %v2int %int_2 %int_2
  15. // CHECK: %type_sampled_image_0 = OpTypeSampledImage %type_2d_image
  16. // CHECK: [[v3fc:%\d+]] = OpConstantComposite %v3float %float_1 %float_2 %float_3
  17. // CHECK: %type_sampled_image_1 = OpTypeSampledImage %type_3d_image
  18. // CHECK: %type_sampled_image_2 = OpTypeSampledImage %type_cube_image
  19. // CHECK: %SparseResidencyStruct = OpTypeStruct %uint %v4float
  20. float4 main(int3 offset: A) : SV_Target {
  21. // CHECK: [[t1:%\d+]] = OpLoad %type_1d_image %t1
  22. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  23. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image [[t1]] [[gSampler]]
  24. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] %float_1 Lod %float_10
  25. float4 val1 = t1.SampleLevel(gSampler, 1, 10);
  26. // CHECK: [[t2:%\d+]] = OpLoad %type_2d_image %t2
  27. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  28. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2]] [[gSampler]]
  29. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v2fc]] Lod|ConstOffset %float_10 [[v2ic]]
  30. float4 val2 = t2.SampleLevel(gSampler, float2(1, 2), 10, 2);
  31. // CHECK: [[t3:%\d+]] = OpLoad %type_3d_image %t3
  32. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  33. // CHECK-NEXT: [[offset:%\d+]] = OpLoad %v3int %offset
  34. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[t3]] [[gSampler]]
  35. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v3fc]] Lod|Offset %float_10 [[offset]]
  36. float4 val3 = t3.SampleLevel(gSampler, float3(1, 2, 3), 10, offset);
  37. // CHECK: [[t4:%\d+]] = OpLoad %type_cube_image %t4
  38. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  39. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_2 [[t4]] [[gSampler]]
  40. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v3fc]] Lod %float_10
  41. float4 val4 = t4.SampleLevel(gSampler, float3(1, 2, 3), 10);
  42. uint status;
  43. // CHECK: [[t3:%\d+]] = OpLoad %type_3d_image %t3
  44. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  45. // CHECK-NEXT: [[offset:%\d+]] = OpLoad %v3int %offset
  46. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[t3]] [[gSampler]]
  47. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseSampleExplicitLod %SparseResidencyStruct [[sampledImg]] [[v3fc]] Lod|Offset %float_10 [[offset]]
  48. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  49. // CHECK-NEXT: OpStore %status [[status]]
  50. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  51. // CHECK-NEXT: OpStore %val5 [[result]]
  52. float4 val5 = t3.SampleLevel(gSampler, float3(1, 2, 3), 10, offset, status);
  53. // CHECK: [[t4:%\d+]] = OpLoad %type_cube_image %t4
  54. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  55. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_2 [[t4]] [[gSampler]]
  56. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseSampleExplicitLod %SparseResidencyStruct [[sampledImg]] [[v3fc]] Lod %float_10
  57. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  58. // CHECK-NEXT: OpStore %status [[status]]
  59. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  60. // CHECK-NEXT: OpStore %val6 [[result]]
  61. float4 val6 = t4.SampleLevel(gSampler, float3(1, 2, 3), 10, status);
  62. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  63. // Make sure OpImageSampleExplicitLod returns a vec4.
  64. // Make sure OpImageSparseSampleExplicitLod returns a struct, in which the second member is a vec4.
  65. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  66. // CHECK: [[v4result:%\d+]] = OpImageSampleExplicitLod %v4float {{%\d+}} {{%\d+}} Lod|Offset %float_10 {{%\d+}}
  67. // CHECK: {{%\d+}} = OpCompositeExtract %float [[v4result]] 0
  68. float val7 = t5.SampleLevel(gSampler, float3(1, 2, 3), 10, offset);
  69. // CHECK: [[structResult:%\d+]] = OpImageSparseSampleExplicitLod %SparseResidencyStruct {{%\d+}} {{%\d+}} Lod %float_10
  70. // CHECK: [[v4result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  71. // CHECK: {{%\d+}} = OpVectorShuffle %v2float [[v4result]] [[v4result]] 0 1
  72. float2 val8 = t6.SampleLevel(gSampler, float3(1, 2, 3), 10, status);
  73. return 1.0;
  74. }