NIS_Main.hlsl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // The MIT License(MIT)
  2. //
  3. // Copyright(c) 2021 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. #ifndef NIS_SCALER
  22. #define NIS_SCALER 1
  23. #endif
  24. #ifndef NIS_DXC
  25. #define NIS_DXC 0
  26. #endif
  27. #if NIS_DXC
  28. #define NIS_PUSH_CONSTANT [[vk::push_constant]]
  29. #define NIS_BINDING(bindingIndex) [[vk::binding(bindingIndex, 0)]]
  30. #define NIS_CONSTANT_BUFFER(structName, variableName, bufferRegister) \
  31. ConstantBuffer<structName> variableName : register(bufferRegister);
  32. #else
  33. #define NIS_PUSH_CONSTANT
  34. #define NIS_BINDING(bindingIndex)
  35. #define NIS_CONSTANT_BUFFER(structName, variableName, bufferRegister) \
  36. cbuffer cbufferType : register(bufferRegister) { structName variableName; };
  37. #endif
  38. NIS_BINDING(0) cbuffer cb : register(b0)
  39. {
  40. float kDetectRatio;
  41. float kDetectThres;
  42. float kMinContrastRatio;
  43. float kRatioNorm;
  44. float kContrastBoost;
  45. float kEps;
  46. float kSharpStartY;
  47. float kSharpScaleY;
  48. float kSharpStrengthMin;
  49. float kSharpStrengthScale;
  50. float kSharpLimitMin;
  51. float kSharpLimitScale;
  52. float kScaleX;
  53. float kScaleY;
  54. float kDstNormX;
  55. float kDstNormY;
  56. float kSrcNormX;
  57. float kSrcNormY;
  58. uint kInputViewportOriginX;
  59. uint kInputViewportOriginY;
  60. uint kInputViewportWidth;
  61. uint kInputViewportHeight;
  62. uint kOutputViewportOriginX;
  63. uint kOutputViewportOriginY;
  64. uint kOutputViewportWidth;
  65. uint kOutputViewportHeight;
  66. float reserved0;
  67. float reserved1;
  68. };
  69. NIS_BINDING(1) SamplerState samplerLinearClamp : register(s0);
  70. NIS_BINDING(2) Texture2D in_texture : register(t0);
  71. NIS_BINDING(3) RWTexture2D<unorm float4> out_texture : register(u0);
  72. #if NIS_SCALER
  73. NIS_BINDING(4) Texture2D coef_scaler : register(t1);
  74. NIS_BINDING(5) Texture2D coef_usm : register(t2);
  75. #endif
  76. #include "NIS_Scaler.h"
  77. [numthreads(NIS_THREAD_GROUP_SIZE, 1, 1)]
  78. void main(uint3 blockIdx : SV_GroupID, uint3 threadIdx : SV_GroupThreadID)
  79. {
  80. #if NIS_SCALER
  81. NVScaler(blockIdx.xy, threadIdx.x);
  82. #else
  83. NVSharpen(blockIdx.xy, threadIdx.x);
  84. #endif
  85. }