struct_loads.hlsl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // RUN: %dxc -E main -T vs_6_2 %s | FileCheck %s
  2. // Test that individual fields can be loaded from a typed buffer based on a struct type.
  3. // The buffer load offset should be aligned to element sizes.
  4. // Regression test for GitHub #2258
  5. AppendStructuredBuffer<int4> output;
  6. struct Scalars { int a, b; };
  7. Buffer<Scalars> buf_scalars;
  8. struct Vectors { int2 a, b; };
  9. Buffer<Vectors> buf_vectors;
  10. struct Array { int a; int b[3]; };
  11. Buffer<Array> buf_array;
  12. int i;
  13. void main()
  14. {
  15. // Float at offset > 0
  16. // CHECK: %[[scalretres:.*]] = call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, {{.*}}, i32 0, i32 undef)
  17. // CHECK: %[[scalval:.*]] = extractvalue %dx.types.ResRet.i32 %[[scalretres]], 1
  18. // CHECK: call void @dx.op.rawBufferStore.i32(i32 140, {{.*}}, i32 {{.*}}, i32 0, i32 %[[scalval]], i32 0, i32 0, i32 0, i8 15, i32 4)
  19. output.Append(int4(buf_scalars[0].b, 0, 0, 0));
  20. // Vector at offset > 0
  21. // CHECK: %[[vecretres:.*]] = call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, {{.*}}, i32 0, i32 undef)
  22. // CHECK: %[[vecvalx:.*]] = extractvalue %dx.types.ResRet.i32 %[[vecretres]], 2
  23. // CHECK: %[[vecvaly:.*]] = extractvalue %dx.types.ResRet.i32 %[[vecretres]], 3
  24. // CHECK: call void @dx.op.rawBufferStore.i32(i32 140, {{.*}}, i32 {{.*}}, i32 0, i32 %[[vecvalx]], i32 %[[vecvaly]], i32 0, i32 0, i8 15, i32 4)
  25. output.Append(int4(buf_vectors[0].b, 0, 0));
  26. // Array at offset > 0, dynamically indexed
  27. // Convert index to offset in struct
  28. // CHECK: shl i32 %{{.*}}, 2
  29. // CHECK: add i32 %{{.*}}, 4
  30. // Load entire struct elements
  31. // CHECK: call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32
  32. // CHECK: extractvalue %dx.types.ResRet.i32 %{{.*}}, 0
  33. // CHECK: extractvalue %dx.types.ResRet.i32 %{{.*}}, 1
  34. // CHECK: extractvalue %dx.types.ResRet.i32 %{{.*}}, 2
  35. // CHECK: extractvalue %dx.types.ResRet.i32 %{{.*}}, 3
  36. // Fill temporary array
  37. // CHECK: getelementptr [4 x i32]
  38. // CHECK: store i32
  39. // CHECK: getelementptr [4 x i32]
  40. // CHECK: store i32
  41. // CHECK: getelementptr [4 x i32]
  42. // CHECK: store i32
  43. // CHECK: getelementptr [4 x i32]
  44. // CHECK: store i32
  45. // Index into array
  46. // CHECK: lshr exact i32 %{{.*}}, 2
  47. // CHECK: getelementptr [4 x i32]
  48. // CHECK: load i32
  49. // Store result
  50. // CHECK: call void @dx.op.rawBufferStore.i32
  51. output.Append(int4(buf_array[0].b[i], 0, 0, 0));
  52. }