RandomGenerators.hlsl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // RUN: %dxc -E main -T ps_6_0 -enable-templates %s | FileCheck %s
  2. // CHECK: call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 0, float 0x404FD93640000000)
  3. // CHECK: call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 1, float 0x4047269780000000)
  4. // CHECK: call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 2, float 0x4045A83E40000000)
  5. // CHECK: call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 3, float 0x4045669660000000)
  6. struct MyRandomGeneratorA
  7. {
  8. float seed;
  9. float Rand()
  10. {
  11. // Not a good random number generator
  12. seed = (seed * 17 + 57) / 99.0;
  13. return seed;
  14. }
  15. };
  16. struct MyRandomGeneratorB
  17. {
  18. float Rand()
  19. {
  20. // An even worse random number generator
  21. return 42.0;
  22. }
  23. };
  24. template<typename GeneratorType>
  25. float4 Model(GeneratorType Generator)
  26. {
  27. float4 E;
  28. E.x = Generator.Rand();
  29. E.y = Generator.Rand();
  30. E.z = Generator.Rand();
  31. E.w = Generator.Rand();
  32. return E;
  33. };
  34. float4 main() : SV_TARGET {
  35. MyRandomGeneratorA genA;
  36. genA.seed = 123.0;
  37. MyRandomGeneratorB genB;
  38. return Model<MyRandomGeneratorA>(genA) + Model<MyRandomGeneratorB>(genB);
  39. }