texture.array.sample-bias.hlsl 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 MinLod
  11. // CHECK: OpCapability SparseResidency
  12. // CHECK: [[v2fc:%\d+]] = OpConstantComposite %v2float %float_1 %float_1
  13. // CHECK: %type_sampled_image = OpTypeSampledImage %type_1d_image_array
  14. // CHECK: [[v3fc:%\d+]] = OpConstantComposite %v3float %float_1 %float_2 %float_1
  15. // CHECK: %type_sampled_image_0 = OpTypeSampledImage %type_2d_image_array
  16. // CHECK: [[v4fc:%\d+]] = OpConstantComposite %v4float %float_1 %float_2 %float_3 %float_1
  17. // CHECK: %type_sampled_image_1 = OpTypeSampledImage %type_cube_image_array
  18. // CHECK: %SparseResidencyStruct = OpTypeStruct %uint %v4float
  19. float4 main(int2 offset : A) : SV_Target {
  20. // CHECK: [[t1:%\d+]] = OpLoad %type_1d_image_array %t1
  21. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  22. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image [[t1]] [[gSampler]]
  23. // CHECK-NEXT: {{%\d+}} = OpImageSampleImplicitLod %v4float [[sampledImg]] [[v2fc]] Bias|ConstOffset %float_0_5 %int_1
  24. float4 val1 = t1.SampleBias(gSampler, float2(1, 1), 0.5, 1);
  25. // CHECK: [[t2:%\d+]] = OpLoad %type_2d_image_array %t2
  26. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  27. // CHECK-NEXT: [[offset:%\d+]] = OpLoad %v2int %offset
  28. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2]] [[gSampler]]
  29. // CHECK-NEXT: {{%\d+}} = OpImageSampleImplicitLod %v4float [[sampledImg]] [[v3fc]] Bias|Offset %float_0_5 [[offset]]
  30. float4 val2 = t2.SampleBias(gSampler, float3(1, 2, 1), 0.5, offset);
  31. // CHECK: [[t3:%\d+]] = OpLoad %type_cube_image_array %t3
  32. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  33. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[t3]] [[gSampler]]
  34. // CHECK-NEXT: {{%\d+}} = OpImageSampleImplicitLod %v4float [[sampledImg]] [[v4fc]] Bias %float_0_5
  35. float4 val3 = t3.SampleBias(gSampler, float4(1, 2, 3, 1), 0.5);
  36. float clamp;
  37. // CHECK: [[clamp:%\d+]] = OpLoad %float %clamp
  38. // CHECK-NEXT: [[t1:%\d+]] = OpLoad %type_1d_image_array %t1
  39. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  40. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image [[t1]] [[gSampler]]
  41. // CHECK-NEXT: {{%\d+}} = OpImageSampleImplicitLod %v4float [[sampledImg]] [[v2fc]] Bias|ConstOffset|MinLod %float_0_5 %int_1 [[clamp]]
  42. float4 val4 = t1.SampleBias(gSampler, float2(1, 1), 0.5, 1, clamp);
  43. // CHECK: [[t3:%\d+]] = OpLoad %type_cube_image_array %t3
  44. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  45. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[t3]] [[gSampler]]
  46. // CHECK-NEXT: {{%\d+}} = OpImageSampleImplicitLod %v4float [[sampledImg]] [[v4fc]] Bias|MinLod %float_0_5 %float_2_5
  47. float4 val5 = t3.SampleBias(gSampler, float4(1, 2, 3, 1), 0.5, /*clamp*/ 2.5f);
  48. uint status;
  49. // CHECK: [[clamp:%\d+]] = OpLoad %float %clamp
  50. // CHECK-NEXT: [[t1:%\d+]] = OpLoad %type_1d_image_array %t1
  51. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  52. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image [[t1]] [[gSampler]]
  53. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseSampleImplicitLod %SparseResidencyStruct [[sampledImg]] [[v2fc]] Bias|ConstOffset|MinLod %float_0_5 %int_1 [[clamp]]
  54. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  55. // CHECK-NEXT: OpStore %status [[status]]
  56. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  57. // CHECK-NEXT: OpStore %val6 [[result]]
  58. float4 val6 = t1.SampleBias(gSampler, float2(1, 1), 0.5, 1, clamp, status);
  59. // CHECK: [[t3:%\d+]] = OpLoad %type_cube_image_array %t3
  60. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  61. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[t3]] [[gSampler]]
  62. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseSampleImplicitLod %SparseResidencyStruct [[sampledImg]] [[v4fc]] Bias|MinLod %float_0_5 %float_2_5
  63. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  64. // CHECK-NEXT: OpStore %status [[status]]
  65. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  66. // CHECK-NEXT: OpStore %val7 [[result]]
  67. float4 val7 = t3.SampleBias(gSampler, float4(1, 2, 3, 1), 0.5, /*clamp*/ 2.5f, status);
  68. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  69. // Make sure OpImageSampleImplicitLod returns a vec4.
  70. // Make sure OpImageSparseSampleImplicitLod returns a struct, in which the second member is a vec4.
  71. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  72. // CHECK: [[v4result:%\d+]] = OpImageSampleImplicitLod %v4float {{%\d+}} {{%\d+}} Bias|Offset %float_0_5 {{%\d+}}
  73. // CHECK: {{%\d+}} = OpCompositeExtract %float [[v4result]] 0
  74. float val8 = t4.SampleBias(gSampler, float3(1, 2, 1), 0.5, offset);
  75. // CHECK: [[structResult:%\d+]] = OpImageSparseSampleImplicitLod %SparseResidencyStruct {{%\d+}} {{%\d+}} Bias|MinLod %float_0_5 %float_2_5
  76. // CHECK: [[v4result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  77. // CHECK: {{%\d+}} = OpVectorShuffle %v3float [[v4result]] [[v4result]] 0 1 2
  78. float3 val9 = t5.SampleBias(gSampler, float4(1, 2, 3, 1), 0.5, /*clamp*/ 2.5f, status);
  79. return 1.0;
  80. }