ClearTextureCompute.ankiprog 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. // A slow compute program to clear an image with a contant color
  6. #pragma anki mutator TEXTURE_DIMENSIONS 2 3
  7. #pragma anki mutator COMPONENT_TYPE 0 1 // 0 is float, 1 is uint
  8. #pragma anki technique comp
  9. #include <AnKi/Shaders/Common.hlsl>
  10. struct Consts
  11. {
  12. #if COMPONENT_TYPE == 0
  13. Vec4 m_clearColor;
  14. #else
  15. UVec4 m_clearColor;
  16. #endif
  17. };
  18. ANKI_FAST_CONSTANTS(Consts, g_consts)
  19. #if TEXTURE_DIMENSIONS == 2
  20. # if COMPONENT_TYPE == 0
  21. RWTexture2D<Vec4> g_storageTex : register(u0);
  22. # else
  23. RWTexture2D<UVec4> g_storageTex : register(u0);
  24. # endif
  25. #else
  26. # if COMPONENT_TYPE == 0
  27. RWTexture3D<Vec4> g_storageTex : register(u0);
  28. # else
  29. RWTexture3D<UVec4> g_storageTex : register(u0);
  30. # endif
  31. #endif
  32. [numthreads(8, 8, (TEXTURE_DIMENSIONS == 2) ? 1 : 8)] void main(UVec3 svDispatchThreadId : SV_DISPATCHTHREADID)
  33. {
  34. #if TEXTURE_DIMENSIONS == 2
  35. UVec2 texSize;
  36. g_storageTex.GetDimensions(texSize.x, texSize.y);
  37. if(svDispatchThreadId.x >= texSize.x || svDispatchThreadId.y >= texSize.y)
  38. {
  39. return;
  40. }
  41. g_storageTex[svDispatchThreadId.xy] = g_consts.m_clearColor;
  42. #else
  43. UVec3 texSize;
  44. g_storageTex.GetDimensions(texSize.x, texSize.y, texSize.z);
  45. if(svDispatchThreadId.x >= texSize.x || svDispatchThreadId.y >= texSize.y || svDispatchThreadId.z >= texSize.z)
  46. {
  47. return;
  48. }
  49. g_storageTex[svDispatchThreadId] = g_consts.m_clearColor;
  50. #endif
  51. }