BindlessPrototypeSrg.azsli 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. // NOTE: Nest this array, so Azslc will output a size of the bindingslot to 1
  10. struct FloatBuffer
  11. {
  12. float buffer;
  13. };
  14. // Listed on update frequency
  15. ShaderResourceGroupSemantic FrequencyPerScene
  16. {
  17. FrequencyId = 6;
  18. };
  19. ShaderResourceGroupSemantic FloatBufferSemanticId
  20. {
  21. FrequencyId = 7;
  22. };
  23. ShaderResourceGroup FloatBufferSrg : FloatBufferSemanticId
  24. {
  25. StructuredBuffer<FloatBuffer> m_floatBuffer;
  26. };
  27. ShaderResourceGroup ImageSrg : FrequencyPerScene
  28. {
  29. Sampler m_sampler
  30. {
  31. MaxAnisotropy = 16;
  32. AddressU = Wrap;
  33. AddressV = Wrap;
  34. AddressW = Wrap;
  35. };
  36. // Array of textures
  37. Texture2D m_textureArray[];
  38. }
  39. // Helper functions to read data from the FloatBuffer. The FloatBuffer is accessed with an offset and an index.
  40. // The offset holds the initial offset within the FloatBuffer, and the index is a sub-index, which increments with each property that is being read.
  41. // The data needs to be read in the same order as it is allocated on the host.
  42. // read floats
  43. void ReadFromFloatBuffer(out float outFloat, in uint offset, inout uint index)
  44. {
  45. outFloat = FloatBufferSrg::m_floatBuffer[offset + index + 0].buffer;
  46. index += 1;
  47. }
  48. void ReadFromFloatBuffer(out float2 outFloat, in uint offset, inout uint index)
  49. {
  50. outFloat.x = FloatBufferSrg::m_floatBuffer[offset + index + 0].buffer;
  51. outFloat.y = FloatBufferSrg::m_floatBuffer[offset + index + 1].buffer;
  52. index += 2;
  53. }
  54. void ReadFromFloatBuffer(out float3 outFloat, in uint offset, inout uint index)
  55. {
  56. outFloat.x = FloatBufferSrg::m_floatBuffer[offset + index + 0].buffer;
  57. outFloat.y = FloatBufferSrg::m_floatBuffer[offset + index + 1].buffer;
  58. outFloat.z = FloatBufferSrg::m_floatBuffer[offset + index + 2].buffer;
  59. index += 3;
  60. }
  61. void ReadFromFloatBuffer(out float4 outFloat, in uint offset, inout uint index)
  62. {
  63. outFloat.x = FloatBufferSrg::m_floatBuffer[offset + index + 0].buffer;
  64. outFloat.y = FloatBufferSrg::m_floatBuffer[offset + index + 1].buffer;
  65. outFloat.z = FloatBufferSrg::m_floatBuffer[offset + index + 2].buffer;
  66. outFloat.w = FloatBufferSrg::m_floatBuffer[offset + index + 3].buffer;
  67. index += 4;
  68. }
  69. // Read to matrix
  70. void ReadFromFloatBuffer(out float4x4 outFloat, in uint offset, inout uint index)
  71. {
  72. [unroll(4)]
  73. for(uint i = 0; i < 4; i++)
  74. {
  75. ReadFromFloatBuffer(outFloat[i], offset, index);
  76. }
  77. }
  78. // read uint
  79. void ReadFromFloatBuffer(out uint outUInt, in uint offset, inout uint index)
  80. {
  81. outUInt = asuint(FloatBufferSrg::m_floatBuffer[offset + index + 0].buffer);
  82. index += 1;
  83. }
  84. void ReadFromFloatBuffer(out uint2 outUInt, in uint offset, inout uint index)
  85. {
  86. outUInt.x = asuint(FloatBufferSrg::m_floatBuffer[offset + index + 0].buffer);
  87. outUInt.y = asuint(FloatBufferSrg::m_floatBuffer[offset + index + 1].buffer);
  88. index += 2;
  89. }
  90. void ReadFromFloatBuffer(out uint3 outUInt, in uint offset, inout uint index)
  91. {
  92. outUInt.x = asuint(FloatBufferSrg::m_floatBuffer[offset + index + 0].buffer);
  93. outUInt.y = asuint(FloatBufferSrg::m_floatBuffer[offset + index + 1].buffer);
  94. outUInt.z = asuint(FloatBufferSrg::m_floatBuffer[offset + index + 2].buffer);
  95. index += 3;
  96. }
  97. void ReadFromFloatBuffer(out uint4 outUInt, in uint offset, inout uint index)
  98. {
  99. outUInt.x = asuint(FloatBufferSrg::m_floatBuffer[offset + index + 0].buffer);
  100. outUInt.y = asuint(FloatBufferSrg::m_floatBuffer[offset + index + 1].buffer);
  101. outUInt.z = asuint(FloatBufferSrg::m_floatBuffer[offset + index + 2].buffer);
  102. outUInt.w = asuint(FloatBufferSrg::m_floatBuffer[offset + index + 3].buffer);
  103. index += 4;
  104. }
  105. // Read double
  106. void ReadFromFloatBuffer(out double outDouble, in uint offset, inout uint index)
  107. {
  108. uint lowBits;
  109. uint highBits;
  110. ReadFromFloatBuffer(highBits, offset, index);
  111. ReadFromFloatBuffer(lowBits, offset, index);
  112. outDouble = asdouble(lowBits, highBits);
  113. }