method.buffer.load.hlsl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Run: %dxc -T ps_6_0 -E main
  2. // CHECK: OpCapability ImageBuffer
  3. Buffer<int> intbuf;
  4. Buffer<uint> uintbuf;
  5. Buffer<float> floatbuf;
  6. RWBuffer<int2> int2buf;
  7. RWBuffer<uint2> uint2buf;
  8. RWBuffer<float2> float2buf;
  9. Buffer<int3> int3buf;
  10. Buffer<uint3> uint3buf;
  11. Buffer<float3> float3buf;
  12. RWBuffer<int4> int4buf;
  13. RWBuffer<uint4> uint4buf;
  14. RWBuffer<float4> float4buf;
  15. // CHECK: OpCapability SparseResidency
  16. // CHECK: %SparseResidencyStruct = OpTypeStruct %uint %v4float
  17. void main() {
  18. int address;
  19. // CHECK: [[img1:%\d+]] = OpLoad %type_buffer_image %intbuf
  20. // CHECK: [[f1:%\d+]] = OpImageFetch %v4int [[img1]] {{%\d+}} None
  21. // CHECK-NEXT: {{%\d+}} = OpCompositeExtract %int [[f1]] 0
  22. int i1 = intbuf.Load(address);
  23. // CHECK: [[img2:%\d+]] = OpLoad %type_buffer_image_0 %uintbuf
  24. // CHECK: [[f2:%\d+]] = OpImageFetch %v4uint [[img2]] {{%\d+}} None
  25. // CHECK-NEXT: {{%\d+}} = OpCompositeExtract %uint [[f2]] 0
  26. uint u1 = uintbuf.Load(address);
  27. // CHECK: [[img3:%\d+]] = OpLoad %type_buffer_image_1 %floatbuf
  28. // CHECK: [[f3:%\d+]] = OpImageFetch %v4float [[img3]] {{%\d+}} None
  29. // CHECK-NEXT: {{%\d+}} = OpCompositeExtract %float [[f3]] 0
  30. float f1 = floatbuf.Load(address);
  31. // CHECK: [[img4:%\d+]] = OpLoad %type_buffer_image_2 %int2buf
  32. // CHECK: [[f4:%\d+]] = OpImageRead %v4int [[img4]] {{%\d+}} None
  33. // CHECK-NEXT: {{%\d+}} = OpVectorShuffle %v2int [[f4]] [[f4]] 0 1
  34. int2 i2 = int2buf.Load(address);
  35. // CHECK: [[img5:%\d+]] = OpLoad %type_buffer_image_3 %uint2buf
  36. // CHECK: [[f5:%\d+]] = OpImageRead %v4uint [[img5]] {{%\d+}} None
  37. // CHECK-NEXT: {{%\d+}} = OpVectorShuffle %v2uint [[f5]] [[f5]] 0 1
  38. uint2 u2 = uint2buf.Load(address);
  39. // CHECK: [[img6:%\d+]] = OpLoad %type_buffer_image_4 %float2buf
  40. // CHECK: [[f6:%\d+]] = OpImageRead %v4float [[img6]] {{%\d+}} None
  41. // CHECK-NEXT: {{%\d+}} = OpVectorShuffle %v2float [[f6]] [[f6]] 0 1
  42. float2 f2 = float2buf.Load(address);
  43. // CHECK: [[img7:%\d+]] = OpLoad %type_buffer_image_5 %int3buf
  44. // CHECK: [[f7:%\d+]] = OpImageFetch %v4int [[img7]] {{%\d+}} None
  45. // CHECK-NEXT: {{%\d+}} = OpVectorShuffle %v3int [[f7]] [[f7]] 0 1 2
  46. int3 i3 = int3buf.Load(address);
  47. // CHECK: [[img8:%\d+]] = OpLoad %type_buffer_image_6 %uint3buf
  48. // CHECK: [[f8:%\d+]] = OpImageFetch %v4uint [[img8]] {{%\d+}} None
  49. // CHECK-NEXT: {{%\d+}} = OpVectorShuffle %v3uint [[f8]] [[f8]] 0 1 2
  50. uint3 u3 = uint3buf.Load(address);
  51. // CHECK: [[img9:%\d+]] = OpLoad %type_buffer_image_7 %float3buf
  52. // CHECK: [[f9:%\d+]] = OpImageFetch %v4float [[img9]] {{%\d+}} None
  53. // CHECK-NEXT: {{%\d+}} = OpVectorShuffle %v3float [[f9]] [[f9]] 0 1 2
  54. float3 f3 = float3buf.Load(address);
  55. // CHECK: [[img10:%\d+]] = OpLoad %type_buffer_image_8 %int4buf
  56. // CHECK: {{%\d+}} = OpImageRead %v4int [[img10]] {{%\d+}} None
  57. // CHECK-NEXT: OpStore %i4 {{%\d+}}
  58. int4 i4 = int4buf.Load(address);
  59. // CHECK: [[img11:%\d+]] = OpLoad %type_buffer_image_9 %uint4buf
  60. // CHECK: {{%\d+}} = OpImageRead %v4uint [[img11]] {{%\d+}} None
  61. // CHECK-NEXT: OpStore %u4 {{%\d+}}
  62. uint4 u4 = uint4buf.Load(address);
  63. // CHECK: [[img12:%\d+]] = OpLoad %type_buffer_image_10 %float4buf
  64. // CHECK: {{%\d+}} = OpImageRead %v4float [[img12]] {{%\d+}} None
  65. // CHECK-NEXT: OpStore %f4 {{%\d+}}
  66. float4 f4 = float4buf.Load(address);
  67. ///////////////////////////////
  68. // Using the Status argument //
  69. ///////////////////////////////
  70. uint status;
  71. // CHECK: [[img3:%\d+]] = OpLoad %type_buffer_image_1 %floatbuf
  72. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseFetch %SparseResidencyStruct [[img3]] {{%\d+}} None
  73. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  74. // CHECK-NEXT: OpStore %status [[status]]
  75. // CHECK-NEXT: [[v4result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  76. // CHECK-NEXT: [[result:%\d+]] = OpCompositeExtract %float [[v4result]] 0
  77. // CHECK-NEXT: OpStore %r1 [[result]]
  78. float r1 = floatbuf.Load(address, status); // Test for Buffer
  79. // CHECK: [[img6:%\d+]] = OpLoad %type_buffer_image_4 %float2buf
  80. // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseRead %SparseResidencyStruct [[img6]] {{%\d+}} None
  81. // CHECK-NEXT: [[status:%\d+]] = OpCompositeExtract %uint [[structResult]] 0
  82. // CHECK-NEXT: OpStore %status [[status]]
  83. // CHECK-NEXT: [[v4result:%\d+]] = OpCompositeExtract %v4float [[structResult]] 1
  84. // CHECK-NEXT: [[result:%\d+]] = OpVectorShuffle %v2float [[v4result]] [[v4result]] 0 1
  85. // CHECK-NEXT: OpStore %r2 [[result]]
  86. float2 r2 = float2buf.Load(address, status); // Test for RWBuffer
  87. }