texture.sample-grad.hlsl 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. Texture1D <float> t5 : register(t5);
  9. Texture2D <float2> t6 : register(t6);
  10. // CHECK: OpCapability ImageGatherExtended
  11. // CHECK: OpCapability MinLod
  12. // CHECK: OpCapability SparseResidency
  13. // CHECK: %type_sampled_image = OpTypeSampledImage %type_1d_image
  14. // CHECK: [[v2f_0_1:%\d+]] = OpConstantComposite %v2float %float_0_1 %float_0_1
  15. // CHECK: [[v2f_0_2:%\d+]] = OpConstantComposite %v2float %float_0_2 %float_0_2
  16. // CHECK: [[v2f_0_3:%\d+]] = OpConstantComposite %v2float %float_0_3 %float_0_3
  17. // CHECK: %type_sampled_image_0 = OpTypeSampledImage %type_2d_image
  18. // CHECK: [[v3f_0_1:%\d+]] = OpConstantComposite %v3float %float_0_1 %float_0_1 %float_0_1
  19. // CHECK: [[v3f_0_2:%\d+]] = OpConstantComposite %v3float %float_0_2 %float_0_2 %float_0_2
  20. // CHECK: [[v3f_0_3:%\d+]] = OpConstantComposite %v3float %float_0_3 %float_0_3 %float_0_3
  21. // CHECK: [[v3i_3:%\d+]] = OpConstantComposite %v3int %int_3 %int_3 %int_3
  22. // CHECK: %type_sampled_image_1 = OpTypeSampledImage %type_3d_image
  23. // CHECK: %type_sampled_image_2 = OpTypeSampledImage %type_cube_image
  24. // CHECK: %SparseResidencyStruct = OpTypeStruct %uint %v4float
  25. float4 main(int2 offset : A) : SV_Target {
  26. // CHECK: [[t1:%\d+]] = OpLoad %type_1d_image %t1
  27. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  28. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image [[t1]] [[gSampler]]
  29. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] %float_0_1 Grad %float_0_2 %float_0_3
  30. float4 val1 = t1.SampleGrad(gSampler, 0.1, 0.2, 0.3);
  31. // CHECK: [[t2:%\d+]] = OpLoad %type_2d_image %t2
  32. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  33. // CHECK-NEXT: [[offset:%\d+]] = OpLoad %v2int %offset
  34. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2]] [[gSampler]]
  35. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v2f_0_1]] Grad|Offset [[v2f_0_2]] [[v2f_0_3]] [[offset]]
  36. float4 val2 = t2.SampleGrad(gSampler, float2(0.1, 0.1), float2(0.2, 0.2), float2(0.3, 0.3), offset);
  37. // CHECK: [[t3:%\d+]] = OpLoad %type_3d_image %t3
  38. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  39. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_1 [[t3]] [[gSampler]]
  40. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v3f_0_1]] Grad|ConstOffset [[v3f_0_2]] [[v3f_0_3]] [[v3i_3]]
  41. float4 val3 = t3.SampleGrad(gSampler, float3(0.1, 0.1, 0.1), float3(0.2, 0.2, 0.2), float3(0.3, 0.3, 0.3), 3);
  42. // CHECK: [[t4:%\d+]] = OpLoad %type_cube_image %t4
  43. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  44. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_2 [[t4]] [[gSampler]]
  45. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v3f_0_1]] Grad [[v3f_0_2]] [[v3f_0_3]]
  46. float4 val4 = t4.SampleGrad(gSampler, float3(0.1, 0.1, 0.1), float3(0.2, 0.2, 0.2), float3(0.3, 0.3, 0.3));
  47. float clamp;
  48. // CHECK: [[clamp:%\d+]] = OpLoad %float %clamp
  49. // CHECK-NEXT: [[t2:%\d+]] = OpLoad %type_2d_image %t2
  50. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  51. // CHECK-NEXT: [[offset:%\d+]] = OpLoad %v2int %offset
  52. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2]] [[gSampler]]
  53. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v2f_0_1]] Grad|Offset|MinLod [[v2f_0_2]] [[v2f_0_3]] [[offset]] [[clamp]]
  54. float4 val5 = t2.SampleGrad(gSampler, float2(0.1, 0.1), float2(0.2, 0.2), float2(0.3, 0.3), offset, clamp);
  55. // CHECK: [[t4:%\d+]] = OpLoad %type_cube_image %t4
  56. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  57. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_2 [[t4]] [[gSampler]]
  58. // CHECK-NEXT: {{%\d+}} = OpImageSampleExplicitLod %v4float [[sampledImg]] [[v3f_0_1]] Grad|MinLod [[v3f_0_2]] [[v3f_0_3]] %float_3_5
  59. float4 val6 = t4.SampleGrad(gSampler, float3(0.1, 0.1, 0.1), float3(0.2, 0.2, 0.2), float3(0.3, 0.3, 0.3), /*clamp*/3.5);
  60. uint status;
  61. // CHECK: [[clamp:%\d+]] = OpLoad %float %clamp
  62. // CHECK-NEXT: [[t2:%\d+]] = OpLoad %type_2d_image %t2
  63. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  64. // CHECK-NEXT: [[offset:%\d+]] = OpLoad %v2int %offset
  65. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_0 [[t2]] [[gSampler]]
  66. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseSampleExplicitLod %SparseResidencyStruct [[sampledImg]] [[v2f_0_1]] Grad|Offset|MinLod [[v2f_0_2]] [[v2f_0_3]] [[offset]] [[clamp]]
  67. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  68. // CHECK-NEXT: OpStore %status [[status]]
  69. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  70. // CHECK-NEXT: OpStore %val7 [[result]]
  71. float4 val7 = t2.SampleGrad(gSampler, float2(0.1, 0.1), float2(0.2, 0.2), float2(0.3, 0.3), offset, clamp, status);
  72. // CHECK: [[t4:%\d+]] = OpLoad %type_cube_image %t4
  73. // CHECK-NEXT: [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler
  74. // CHECK-NEXT: [[sampledImg:%\d+]] = OpSampledImage %type_sampled_image_2 [[t4]] [[gSampler]]
  75. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseSampleExplicitLod %SparseResidencyStruct [[sampledImg]] [[v3f_0_1]] Grad|MinLod [[v3f_0_2]] [[v3f_0_3]] %float_3_5
  76. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  77. // CHECK-NEXT: OpStore %status [[status]]
  78. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  79. // CHECK-NEXT: OpStore %val8 [[result]]
  80. float4 val8 = t4.SampleGrad(gSampler, float3(0.1, 0.1, 0.1), float3(0.2, 0.2, 0.2), float3(0.3, 0.3, 0.3), /*clamp*/3.5, status);
  81. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  82. // Make sure OpImageSampleExplicitLod returns a vec4.
  83. // Make sure OpImageSparseSampleExplicitLod returns a struct, in which the second member is a vec4.
  84. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  85. // CHECK: [[v4result:%\d+]] = OpImageSampleExplicitLod %v4float {{%\d+}} %float_0_1 Grad %float_0_2 %float_0_3
  86. // CHECK: {{%\d+}} = OpCompositeExtract %float [[v4result]] 0
  87. float val9 = t5.SampleGrad(gSampler, 0.1, 0.2, 0.3);
  88. // CHECK: [[structResult:%\d+]] = OpImageSparseSampleExplicitLod %SparseResidencyStruct {{%\d+}} {{%\d+}} Grad|Offset|MinLod {{%\d+}} {{%\d+}} {{%\d+}} {{%\d+}}
  89. // CHECK: [[v4result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  90. // CHECK: {{%\d+}} = OpVectorShuffle %v2float [[v4result]] [[v4result]] 0 1
  91. float2 val10 = t6.SampleGrad(gSampler, float2(0.1, 0.1), float2(0.2, 0.2), float2(0.3, 0.3), offset, clamp, status);
  92. return 1.0;
  93. }