AppRenderer.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #pragma once
  22. #include <iostream>
  23. #include <sstream>
  24. #include <iomanip>
  25. #include <d3d11.h>
  26. #include <wrl.h>
  27. #include "DeviceResources.h"
  28. #include "NVScaler.h"
  29. #include "NVSharpen.h"
  30. #include "UIRenderer.h"
  31. #include "BilinearUpscale.h"
  32. #include "Image.h"
  33. #include "d3dx12.h"
  34. using namespace Microsoft::WRL;
  35. class AppRenderer
  36. {
  37. public:
  38. AppRenderer(DeviceResources& deviceResources, UIData& ui, const std::vector<std::string>& shaderPaths);
  39. bool updateSize();
  40. void update();
  41. void render();
  42. uint32_t width() { return m_outputWidth; }
  43. uint32_t height() { return m_outputHeight; }
  44. bool isInitialized() { return m_init; }
  45. void saveOutput(const std::string& filename);
  46. protected:
  47. void scheduleCopyOutput();
  48. void saveOutputToFile();
  49. private:
  50. UIData& m_ui;
  51. DeviceResources& m_deviceResources;
  52. NVScaler m_NVScaler;
  53. NVSharpen m_NVSharpen;
  54. BilinearUpscale m_upscale;
  55. uint32_t m_inputWidth = 0;
  56. uint32_t m_inputHeight = 0;
  57. uint32_t m_outputWidth = 0;
  58. uint32_t m_outputHeight = 0;
  59. ComPtr<ID3D12Resource> m_input;
  60. ComPtr<ID3D12Resource> m_output;
  61. ComPtr<ID3D12Resource> m_inputUpload;
  62. DescriptorHeap m_samplerDescriptorHeap;
  63. DescriptorHeap m_RVDescriptorHeap;
  64. std::vector<uint8_t> m_image;
  65. uint32_t m_rowPitch;
  66. std::filesystem::path m_currentFilePath;
  67. uint32_t m_currentOutputWidth;
  68. uint32_t m_currentOutputHeight;
  69. float m_currentScale = 100;
  70. float m_currentSharpness = 0;
  71. bool m_updateWindowSize = false;
  72. bool m_updateSharpness = false;
  73. bool m_uploadCoefficients = true;
  74. bool m_init = false;
  75. bool m_saveOutput = false;
  76. bool m_saveReadBack = false;
  77. std::string m_saveFileName = "";
  78. ComPtr<ID3D12Resource> m_outputReadBack;
  79. uint32_t m_saveWidth = 0;
  80. uint32_t m_saveHeight = 0;
  81. uint32_t m_saveRowPitch = 0;
  82. enum DescriptorHeapCount : uint32_t
  83. {
  84. cCB = 3,
  85. cUAV = 1,
  86. cSRV = 3,
  87. };
  88. enum DescriptorHeapIndex : uint32_t
  89. {
  90. iCB = 0,
  91. iUAV = iCB + cCB,
  92. iSRV = iUAV + cUAV,
  93. iHeapEnd = iSRV + cSRV
  94. };
  95. };