xbmc
ShaderPresetDX.h
1 /*
2  * Copyright (C) 2017-2020 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "ShaderDX.h"
12 #include "ShaderTextureDX.h"
13 #include "cores/RetroPlayer/shaders/IShaderPreset.h"
14 #include "cores/RetroPlayer/shaders/ShaderTypes.h"
15 #include "games/GameServices.h"
16 #include "utils/Geometry.h"
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include <d3d11.h>
23 
24 namespace ADDON
25 {
26 class CShaderPreset;
27 class CShaderPresetAddon;
28 } // namespace ADDON
29 
30 namespace KODI
31 {
32 namespace RETRO
33 {
34 class CRenderContext;
35 }
36 
37 namespace SHADER
38 {
39 
40 class IShaderTexture;
41 
43 {
44 public:
45  // Instance of CShaderPreset
46  explicit CShaderPresetDX(RETRO::CRenderContext& context,
47  unsigned videoWidth = 0,
48  unsigned videoHeight = 0);
49  ~CShaderPresetDX() override;
50 
51  // implementation of IShaderPreset
52  bool ReadPresetFile(const std::string& presetPath) override;
53  bool RenderUpdate(const CPoint dest[], IShaderTexture* source, IShaderTexture* target) override;
54  void SetSpeed(double speed) override { m_speed = speed; }
55  void SetVideoSize(const unsigned videoWidth, const unsigned videoHeight) override;
56  bool SetShaderPreset(const std::string& shaderPresetPath) override;
57  const std::string& GetShaderPreset() const override;
58  ShaderPassVec& GetPasses() override { return m_passes; }
59 
60  bool Update();
61  // CShaderTextureDX* GetFirstTexture();
62 
63 private:
64  bool CreateShaderTextures();
65  bool CreateShaders();
66  bool CreateSamplers();
67  bool CreateLayouts();
68  bool CreateBuffers();
69  void UpdateViewPort();
70  void UpdateViewPort(CRect viewPort);
71  void UpdateMVPs();
72  void DisposeShaders();
73  void PrepareParameters(const IShaderTexture* texture, const CPoint dest[]);
74  void RenderShader(IShader* shader, IShaderTexture* source, IShaderTexture* target) const;
75  bool HasPathFailed(const std::string& path) const;
76 
77  // Construction parameters
78  RETRO::CRenderContext& m_context;
79 
80  // Relative path of the currently loaded shader preset
81  // If empty, it means that a preset is not currently loaded
82  std::string m_presetPath;
83 
84  // Video shaders for the shader passes
85  std::vector<std::unique_ptr<CShaderDX>> m_pShaders;
86 
87  // Intermediate textures used for pixel shader passes
88  std::vector<std::unique_ptr<CShaderTextureCD3D>> m_pShaderTextures;
89 
90  // First texture (this won't be needed when we have RGB rendering
91  std::unique_ptr<CShaderTextureCD3D> firstTexture;
92 
93  // Was the shader preset changed during the last frame?
94  bool m_bPresetNeedsUpdate = true;
95 
96  // Size of the viewport
97  float2 m_outputSize;
98 
99  // The size of the input texture itself
100  // Power-of-two sized.
101  float2 m_textureSize;
102 
103  // Size of the actual source video data (ie. 160x144 for the Game Boy)
104  float2 m_videoSize;
105 
106  // Number of frames that have passed
107  float m_frameCount = 0.0f;
108 
109  // Point/nearest neighbor sampler
110  ID3D11SamplerState* m_pSampNearest = nullptr;
111 
112  // Linear sampler
113  ID3D11SamplerState* m_pSampLinear = nullptr;
114 
115  // Set of paths of presets that are known to not load correctly
116  // Should not contain "" (empty path) because this signifies that a preset is not loaded
117  std::set<std::string> m_failedPaths;
118 
119  // Array of vertices that comprise the full viewport
120  CPoint m_dest[4];
121 
122  // Playback speed
123  double m_speed = 0.0;
124 
125  ShaderParameterMap GetShaderParameters(const std::vector<ShaderParameter>& parameters,
126  const std::string& sourceStr) const;
127 
128  ShaderPassVec m_passes;
129 };
130 
131 } // namespace SHADER
132 } // namespace KODI
ShaderPassVec & GetPasses() override
Gets the passes of the loaded preset.
Definition: ShaderPresetDX.h:58
void SetSpeed(double speed) override
Informs about the speed of playback.
Definition: ShaderPresetDX.h:54
Definition: AudioDecoder.h:18
Definition: IShaderPreset.h:23
Definition: RenderContext.h:43
Definition: IShader.h:25
Definition: IShaderTexture.h:15
Definition: ShaderTypes.h:108
Definition: Addon.cpp:39
Definition: ShaderPresetDX.h:42