texture.array.sample-grad.hlsl 6.6 KB

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