BilinearUpscale.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <dxgi1_4.h>
  23. #include <d3d12.h>
  24. #include "d3dx12.h"
  25. extern "C" {
  26. #include <dxcapi.h>
  27. }
  28. #include "DeviceResources.h"
  29. __declspec(align(256))
  30. struct BilinearUpscaleConfig
  31. {
  32. uint32_t kInputViewportOriginX;
  33. uint32_t kInputViewportOriginY;
  34. uint32_t kInputViewportWidth;
  35. uint32_t kInputViewportHeight;
  36. uint32_t kOutputViewportOriginX;
  37. uint32_t kOutputViewportOriginY;
  38. uint32_t kOutputViewportWidth;
  39. uint32_t kOutputViewportHeight;
  40. float kScaleX;
  41. float kScaleY;
  42. float kDstNormX;
  43. float kDstNormY;
  44. float kSrcNormX;
  45. float kSrcNormY;
  46. };
  47. void BilinearUpdateConfig(BilinearUpscaleConfig& config,
  48. uint32_t inputViewportOriginX, uint32_t inputViewportOriginY,
  49. uint32_t inputViewportWidth, uint32_t inputViewportHeight,
  50. uint32_t inputTextureWidth, uint32_t inputTextureHeight,
  51. uint32_t outputViewportOriginX, uint32_t outputViewportOriginY,
  52. uint32_t outputViewportWidth, uint32_t outputViewportHeight,
  53. uint32_t outputTextureWidth, uint32_t outputTextureHeight);
  54. class BilinearUpscale {
  55. public:
  56. BilinearUpscale(DeviceResources& deviceResources, const std::vector<std::string>& shaderPaths);
  57. void update(uint32_t inputWidth, uint32_t inputHeight, uint32_t outputWidth, uint32_t outputHeight);
  58. ID3D12PipelineState* getComputePSO() { return m_computePSO.Get(); }
  59. ID3D12Resource* getConstantBuffer() { return m_constatBuffer.Get(); }
  60. ID3D12RootSignature* getRootSignature() { return m_computeRootSignature.Get(); }
  61. std::vector<UINT> getDispatchDim() {
  62. return { UINT(std::ceil(m_outputWidth / float(m_BlockWidth))), UINT(std::ceil(m_outputHeight / float(m_BlockHeight))), 1 };
  63. }
  64. private:
  65. DeviceResources& m_deviceResources;
  66. BilinearUpscaleConfig m_config;
  67. ComPtr<ID3D12RootSignature> m_computeRootSignature;
  68. ComPtr<ID3D12PipelineState> m_computePSO;
  69. ComPtr<ID3D12Resource> m_constatBuffer;
  70. ComPtr<ID3D12Resource> m_stagingBuffer;
  71. uint32_t m_outputWidth;
  72. uint32_t m_outputHeight;
  73. uint32_t m_BlockWidth = 16;
  74. uint32_t m_BlockHeight = 16;
  75. };