xbmc
ShaderDX.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 "ShaderTextureDX.h"
12 #include "cores/RetroPlayer/shaders/IShader.h"
13 #include "cores/VideoPlayer/VideoRenderers/VideoShaders/WinVideoFilter.h"
14 #include "guilib/D3DResource.h"
15 
16 #include <stdint.h>
17 
18 namespace KODI
19 {
20 namespace RETRO
21 {
22 class CRenderContext;
23 }
24 
25 namespace SHADER
26 {
27 
28 // TODO: make renderer independent
29 // libretro's "Common shaders"
30 // Spec here: https://github.com/libretro/common-shaders/blob/master/docs/README
31 class CShaderDX : public CWinShader, public IShader
32 {
33 public:
35  ~CShaderDX() override;
36 
37  // implementation of IShader
38  bool Create(const std::string& shaderSource,
39  const std::string& shaderPath,
40  ShaderParameterMap shaderParameters,
41  IShaderSampler* sampler,
42  ShaderLutVec luts,
43  float2 viewPortSize,
44  unsigned frameCountMod = 0) override;
45  void Render(IShaderTexture* source, IShaderTexture* target) override;
46  void SetSizes(const float2& prevSize, const float2& nextSize) override;
47  void PrepareParameters(CPoint dest[4], bool isLastPass, uint64_t frameCount) override;
48  CD3DEffect& GetEffect();
49  void UpdateMVP() override;
50  bool CreateInputBuffer() override;
51  void UpdateInputBuffer(uint64_t frameCount);
52 
53  // expose these from CWinShader
54  bool CreateVertexBuffer(unsigned vertCount, unsigned vertSize) override;
55 
62  bool CreateInputLayout(D3D11_INPUT_ELEMENT_DESC* layout, unsigned numElements);
63 
64 protected:
65  void SetShaderParameters(CD3DTexture& sourceTexture);
66 
67 private:
68  struct cbInput
69  {
70  XMFLOAT2 video_size;
71  XMFLOAT2 texture_size;
72  XMFLOAT2 output_size;
73  float frame_count;
74  float frame_direction;
75  };
76 
77  // Currently loaded shader's source code
78  std::string m_shaderSource;
79 
80  // Currently loaded shader's relative path
81  std::string m_shaderPath;
82 
83  // Array of shader parameters
84  ShaderParameterMap m_shaderParameters;
85 
86  // Sampler state
87  ID3D11SamplerState* m_pSampler = nullptr;
88 
89  // Look-up textures that the shader uses
90  ShaderLutVec m_luts; // todo: back to DX maybe
91 
92  // Resolution of the input of the shader
93  float2 m_inputSize;
94 
95  // Resolution of the output of the shader
96  float2 m_outputSize;
97 
98  // Resolution of the viewport/window
99  float2 m_viewportSize;
100 
101  // Resolution of the texture that holds the input
102  // float2 m_textureSize;
103 
104  // Holds the data bount to the input cbuffer (cbInput here)
105  ID3D11Buffer* m_pInputBuffer = nullptr;
106 
107  // Projection matrix
108  XMFLOAT4X4 m_MVP;
109 
110  // Value to modulo (%) frame count with
111  // Unused if 0
112  unsigned m_frameCountMod = 0;
113 
114 private:
115  cbInput GetInputData(uint64_t frameCount = 0);
116 
117  // Construction parameters
118  RETRO::CRenderContext& m_context;
119 };
120 
121 } // namespace SHADER
122 } // namespace KODI
Definition: D3DResource.h:92
Definition: ShaderDX.h:31
Definition: D3DResource.h:176
Definition: WinVideoFilter.h:30
Definition: AudioDecoder.h:18
Definition: RenderContext.h:43
Definition: IShader.h:25
Definition: IShaderTexture.h:15
Definition: ShaderTypes.h:108
Definition: IShaderSampler.h:15