NIS_Main.hlsl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // The MIT License(MIT)
  2. //
  3. // Copyright(c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. // this software and associated documentation files(the "Software"), to deal in
  7. // the Software without restriction, including without limitation the rights to
  8. // use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of
  9. // the Software, and to permit persons to whom the Software is furnished to do so,
  10. // subject to the following conditions :
  11. //
  12. // The above copyright notice and this permission notice shall be included in all
  13. // copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR
  18. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #define NIS_HLSL 1
  22. #ifndef NIS_SCALER
  23. #define NIS_SCALER 1
  24. #endif
  25. #ifndef NIS_DXC
  26. #define NIS_DXC 0
  27. #endif
  28. #if NIS_DXC
  29. #define NIS_PUSH_CONSTANT [[vk::push_constant]]
  30. #define NIS_BINDING(bindingIndex) [[vk::binding(bindingIndex, 0)]]
  31. #else
  32. #define NIS_PUSH_CONSTANT
  33. #define NIS_BINDING(bindingIndex)
  34. #endif
  35. NIS_BINDING(0) cbuffer cb : register(b0)
  36. {
  37. float kDetectRatio;
  38. float kDetectThres;
  39. float kMinContrastRatio;
  40. float kRatioNorm;
  41. float kContrastBoost;
  42. float kEps;
  43. float kSharpStartY;
  44. float kSharpScaleY;
  45. float kSharpStrengthMin;
  46. float kSharpStrengthScale;
  47. float kSharpLimitMin;
  48. float kSharpLimitScale;
  49. float kScaleX;
  50. float kScaleY;
  51. float kDstNormX;
  52. float kDstNormY;
  53. float kSrcNormX;
  54. float kSrcNormY;
  55. uint kInputViewportOriginX;
  56. uint kInputViewportOriginY;
  57. uint kInputViewportWidth;
  58. uint kInputViewportHeight;
  59. uint kOutputViewportOriginX;
  60. uint kOutputViewportOriginY;
  61. uint kOutputViewportWidth;
  62. uint kOutputViewportHeight;
  63. float reserved0;
  64. float reserved1;
  65. };
  66. NIS_BINDING(1) SamplerState samplerLinearClamp : register(s0);
  67. NIS_BINDING(2) Texture2D in_texture : register(t0);
  68. NIS_BINDING(3) RWTexture2D<float4> out_texture : register(u0);
  69. #if NIS_SCALER
  70. NIS_BINDING(4) Texture2D coef_scaler : register(t1);
  71. NIS_BINDING(5) Texture2D coef_usm : register(t2);
  72. #endif
  73. #include "NIS_Scaler.h"
  74. [numthreads(NIS_THREAD_GROUP_SIZE, 1, 1)]
  75. void main(uint3 blockIdx : SV_GroupID, uint3 threadIdx : SV_GroupThreadID)
  76. {
  77. #if NIS_SCALER
  78. NVScaler(blockIdx.xy, threadIdx.x);
  79. #else
  80. NVSharpen(blockIdx.xy, threadIdx.x);
  81. #endif
  82. }