texture.load.hlsl 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Run: %dxc -T ps_6_0 -E main
  2. Texture1D <float4> t1 : register(t1);
  3. Texture2D <float4> t2 : register(t2);
  4. Texture3D <float4> t3 : register(t3);
  5. // .Load() does not support TextureCube.
  6. Texture1D <float> t4 : register(t4);
  7. Texture2D <int2> t5 : register(t5);
  8. Texture3D <uint3> t6 : register(t6);
  9. Texture2DMS <float> t7 : register(t7);
  10. Texture2DMSArray<float3> t8 : register(t8);
  11. // CHECK: OpCapability ImageGatherExtended
  12. // CHECK: OpCapability SparseResidency
  13. // CHECK: [[v2ic:%\d+]] = OpConstantComposite %v2int %int_1 %int_2
  14. // CHECK: [[v4ic:%\d+]] = OpConstantComposite %v4int %int_1 %int_2 %int_3 %int_4
  15. // CHECK: [[v3ic:%\d+]] = OpConstantComposite %v3int %int_3 %int_3 %int_3
  16. // CHECK: %SparseResidencyStruct = OpTypeStruct %uint %v4float
  17. // CHECK: %SparseResidencyStruct_0 = OpTypeStruct %uint %v4int
  18. // CHECK: %SparseResidencyStruct_1 = OpTypeStruct %uint %v4uint
  19. float4 main(int3 location: A, int offset: B) : SV_Target {
  20. uint status;
  21. // CHECK: [[coord:%\d+]] = OpCompositeExtract %int [[v2ic]] 0
  22. // CHECK-NEXT: [[lod:%\d+]] = OpCompositeExtract %int [[v2ic]] 1
  23. // CHECK-NEXT:[[offset:%\d+]] = OpLoad %int %offset
  24. // CHECK-NEXT: [[t1:%\d+]] = OpLoad %type_1d_image %t1
  25. // CHECK-NEXT: {{%\d+}} = OpImageFetch %v4float [[t1]] [[coord]] Lod|Offset [[lod]] [[offset]]
  26. float4 val1 = t1.Load(int2(1, 2), offset);
  27. // CHECK: [[loc:%\d+]] = OpLoad %v3int %location
  28. // CHECK-NEXT: [[coord:%\d+]] = OpVectorShuffle %v2int [[loc]] [[loc]] 0 1
  29. // CHECK-NEXT: [[lod:%\d+]] = OpCompositeExtract %int [[loc]] 2
  30. // CHECK-NEXT: [[t2:%\d+]] = OpLoad %type_2d_image %t2
  31. // CHECK-NEXT: {{%\d+}} = OpImageFetch %v4float [[t2]] [[coord]] Lod|ConstOffset [[lod]] [[v2ic]]
  32. float4 val2 = t2.Load(location, int2(1, 2));
  33. // CHECK: [[coord:%\d+]] = OpVectorShuffle %v3int [[v4ic]] [[v4ic]] 0 1 2
  34. // CHECK-NEXT: [[lod:%\d+]] = OpCompositeExtract %int [[v4ic]] 3
  35. // CHECK-NEXT: [[t3:%\d+]] = OpLoad %type_3d_image %t3
  36. // CHECK-NEXT: {{%\d+}} = OpImageFetch %v4float [[t3]] [[coord]] Lod|ConstOffset [[lod]] [[v3ic]]
  37. float4 val3 = t3.Load(int4(1, 2, 3, 4), 3);
  38. // CHECK: [[f4:%\d+]] = OpImageFetch %v4float {{%\d+}} {{%\d+}} Lod|Offset {{%\d+}} {{%\d+}}
  39. // CHECK-NEXT: {{%\d+}} = OpCompositeExtract %float [[f4]] 0
  40. float val4 = t4.Load(int2(1,2), offset);
  41. // CHECK: [[f5:%\d+]] = OpImageFetch %v4int {{%\d+}} {{%\d+}} Lod|ConstOffset {{%\d+}} {{%\d+}}
  42. // CHECK-NEXT: {{%\d+}} = OpVectorShuffle %v2int [[f5]] [[f5]] 0 1
  43. int2 val5 = t5.Load(location, int2(1,2));
  44. // CHECK: [[f6:%\d+]] = OpImageFetch %v4uint {{%\d+}} {{%\d+}} Lod|ConstOffset {{%\d+}} {{%\d+}}
  45. // CHECK-NEXT: {{%\d+}} = OpVectorShuffle %v3uint [[f6]] [[f6]] 0 1 2
  46. uint3 val6 = t6.Load(int4(1, 2, 3, 4), 3);
  47. float val7;
  48. float3 val8;
  49. int sampleIndex = 7;
  50. int2 pos2 = int2(2, 3);
  51. int3 pos3 = int3(2, 3, 4);
  52. int2 offset2 = int2(1, 2);
  53. // CHECK: [[pos0:%\d+]] = OpLoad %v2int %pos2
  54. // CHECK-NEXT: [[si0:%\d+]] = OpLoad %int %sampleIndex
  55. // CHECK-NEXT: [[t70:%\d+]] = OpLoad %type_2d_image_1 %t7
  56. // CHECK-NEXT: [[f70:%\d+]] = OpImageFetch %v4float [[t70]] [[pos0]] Sample [[si0]]
  57. // CHECK-NEXT: {{%\d+}} = OpCompositeExtract %float [[f70]] 0
  58. val7 = t7.Load(pos2, sampleIndex);
  59. // CHECK: [[pos1:%\d+]] = OpLoad %v2int %pos2
  60. // CHECK-NEXT: [[si1:%\d+]] = OpLoad %int %sampleIndex
  61. // CHECK-NEXT:[[offset2:%\d+]] = OpLoad %v2int %offset2
  62. // CHECK-NEXT: [[t71:%\d+]] = OpLoad %type_2d_image_1 %t7
  63. // CHECK-NEXT: [[f71:%\d+]] = OpImageFetch %v4float [[t71]] [[pos1]] Offset|Sample [[offset2]] [[si1]]
  64. // CHECK-NEXT: {{%\d+}} = OpCompositeExtract %float [[f71]] 0
  65. val7 = t7.Load(pos2, sampleIndex, offset2);
  66. // CHECK: [[pos2:%\d+]] = OpLoad %v3int %pos3
  67. // CHECK-NEXT: [[si2:%\d+]] = OpLoad %int %sampleIndex
  68. // CHECK-NEXT: [[t80:%\d+]] = OpLoad %type_2d_image_array %t8
  69. // CHECK-NEXT: [[f80:%\d+]] = OpImageFetch %v4float [[t80]] [[pos2]] Sample [[si2]]
  70. // CHECK-NEXT: {{%\d+}} = OpVectorShuffle %v3float [[f80]] [[f80]] 0 1 2
  71. val8 = t8.Load(pos3, sampleIndex);
  72. // CHECK: [[pos3:%\d+]] = OpLoad %v3int %pos3
  73. // CHECK-NEXT: [[si3:%\d+]] = OpLoad %int %sampleIndex
  74. // CHECK-NEXT: [[t81:%\d+]] = OpLoad %type_2d_image_array %t8
  75. // CHECK-NEXT: [[f81:%\d+]] = OpImageFetch %v4float [[t81]] [[pos3]] ConstOffset|Sample [[v2ic]] [[si3]]
  76. // CHECK-NEXT: {{%\d+}} = OpVectorShuffle %v3float [[f81]] [[f81]] 0 1 2
  77. val8 = t8.Load(pos3, sampleIndex, int2(1,2));
  78. /////////////////////////////////
  79. /// Using the Status argument ///
  80. /////////////////////////////////
  81. // CHECK: [[coord:%\d+]] = OpCompositeExtract %int [[v2ic]] 0
  82. // CHECK-NEXT: [[lod:%\d+]] = OpCompositeExtract %int [[v2ic]] 1
  83. // CHECK-NEXT: [[offset:%\d+]] = OpLoad %int %offset
  84. // CHECK-NEXT: [[t4:%\d+]] = OpLoad %type_1d_image %t4
  85. // CHECK-NEXT:[[structResult:%\d+]] = OpImageSparseFetch %SparseResidencyStruct [[t4]] [[coord]] Lod|Offset [[lod]] [[offset]]
  86. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  87. // CHECK-NEXT: OpStore %status [[status]]
  88. // CHECK-NEXT: [[v4result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  89. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %float [[v4result]] 0
  90. // CHECK-NEXT: OpStore %val14 [[result]]
  91. float val14 = t4.Load(int2(1,2), offset, status);
  92. // CHECK: [[loc:%\d+]] = OpLoad %v3int %location
  93. // CHECK-NEXT: [[coord:%\d+]] = OpVectorShuffle %v2int [[loc]] [[loc]] 0 1
  94. // CHECK-NEXT: [[lod:%\d+]] = OpCompositeExtract %int [[loc]] 2
  95. // CHECK-NEXT: [[t5:%\d+]] = OpLoad %type_2d_image_0 %t5
  96. // CHECK-NEXT:[[structResult:%\d+]] = OpImageSparseFetch %SparseResidencyStruct_0 [[t5]] [[coord]] Lod|ConstOffset [[lod]] [[v2ic]]
  97. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  98. // CHECK-NEXT: OpStore %status [[status]]
  99. // CHECK-NEXT: [[v4result:%\d+]] = OpCompositeExtract %v4int [[structResult]] 1
  100. // CHECK-NEXT: [[result:%\d+]] = OpVectorShuffle %v2int [[v4result]] [[v4result]] 0 1
  101. // CHECK-NEXT: OpStore %val15 [[result]]
  102. int2 val15 = t5.Load(location, int2(1,2), status);
  103. // CHECK: [[coord:%\d+]] = OpVectorShuffle %v3int [[v4ic]] [[v4ic]] 0 1 2
  104. // CHECK-NEXT: [[lod:%\d+]] = OpCompositeExtract %int [[v4ic]] 3
  105. // CHECK-NEXT: [[t6:%\d+]] = OpLoad %type_3d_image_0 %t6
  106. // CHECK-NEXT:[[structResult:%\d+]] = OpImageSparseFetch %SparseResidencyStruct_1 [[t6]] [[coord]] Lod|ConstOffset [[lod]] [[v3ic]]
  107. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  108. // CHECK-NEXT: OpStore %status [[status]]
  109. // CHECK-NEXT: [[v4result:%\d+]] = OpCompositeExtract %v4uint [[structResult]] 1
  110. // CHECK-NEXT: [[result:%\d+]] = OpVectorShuffle %v3uint [[v4result]] [[v4result]] 0 1 2
  111. // CHECK-NEXT: OpStore %val16 [[result]]
  112. uint3 val16 = t6.Load(int4(1, 2, 3, 4), 3, status);
  113. // CHECK: [[pos1:%\d+]] = OpLoad %v2int %pos2
  114. // CHECK-NEXT: [[si1:%\d+]] = OpLoad %int %sampleIndex
  115. // CHECK-NEXT: [[offset2:%\d+]] = OpLoad %v2int %offset2
  116. // CHECK-NEXT: [[t71:%\d+]] = OpLoad %type_2d_image_1 %t7
  117. // CHECK-NEXT:[[structResult:%\d+]] = OpImageSparseFetch %SparseResidencyStruct [[t71]] [[pos1]] Offset|Sample [[offset2]] [[si1]]
  118. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  119. // CHECK-NEXT: OpStore %status [[status]]
  120. // CHECK-NEXT: [[v4result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  121. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %float [[v4result]] 0
  122. // CHECK-NEXT: OpStore %val17 [[result]]
  123. float val17 = t7.Load(pos2, sampleIndex, offset2, status);
  124. // CHECK: [[pos3:%\d+]] = OpLoad %v3int %pos3
  125. // CHECK-NEXT: [[si3:%\d+]] = OpLoad %int %sampleIndex
  126. // CHECK-NEXT: [[t81:%\d+]] = OpLoad %type_2d_image_array %t8
  127. // CHECK-NEXT:[[structResult:%\d+]] = OpImageSparseFetch %SparseResidencyStruct [[t81]] [[pos3]] ConstOffset|Sample [[v2ic]] [[si3]]
  128. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  129. // CHECK-NEXT: OpStore %status [[status]]
  130. // CHECK-NEXT: [[v4result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  131. // CHECK-NEXT: [[result:%\d+]] = OpVectorShuffle %v3float [[v4result]] [[v4result]] 0 1 2
  132. // CHECK-NEXT: OpStore %val18 [[result]]
  133. float3 val18 = t8.Load(pos3, sampleIndex, int2(1,2), status);
  134. return 1.0;
  135. }