duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

d3d11_pipeline.h (2924B)


      1 // SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
      3 
      4 #pragma once
      5 
      6 #include "gpu_device.h"
      7 
      8 #include "common/windows_headers.h"
      9 
     10 #include <d3d11_1.h>
     11 #include <dxgi1_5.h>
     12 #include <string>
     13 #include <string_view>
     14 #include <vector>
     15 #include <wrl/client.h>
     16 
     17 class D3D11Device;
     18 
     19 class D3D11Shader final : public GPUShader
     20 {
     21   friend D3D11Device;
     22 
     23 public:
     24   ~D3D11Shader() override;
     25 
     26   ID3D11VertexShader* GetVertexShader() const;
     27   ID3D11PixelShader* GetPixelShader() const;
     28   ID3D11GeometryShader* GetGeometryShader() const;
     29   ID3D11ComputeShader* GetComputeShader() const;
     30 
     31   ALWAYS_INLINE const std::vector<u8>& GetBytecode() const { return m_bytecode; }
     32 
     33   void SetDebugName(std::string_view name) override;
     34 
     35 private:
     36   D3D11Shader(GPUShaderStage stage, Microsoft::WRL::ComPtr<ID3D11DeviceChild> shader, std::vector<u8> bytecode);
     37 
     38   Microsoft::WRL::ComPtr<ID3D11DeviceChild> m_shader;
     39   std::vector<u8> m_bytecode; // only for VS
     40 };
     41 
     42 class D3D11Pipeline final : public GPUPipeline
     43 {
     44   friend D3D11Device;
     45 
     46   template<typename T>
     47   using ComPtr = Microsoft::WRL::ComPtr<T>;
     48 
     49 public:
     50   ~D3D11Pipeline() override;
     51 
     52   void SetDebugName(std::string_view name) override;
     53 
     54   ALWAYS_INLINE ID3D11RasterizerState* GetRasterizerState() const { return m_rs.Get(); }
     55   ALWAYS_INLINE ID3D11DepthStencilState* GetDepthStencilState() const { return m_ds.Get(); }
     56   ALWAYS_INLINE ID3D11BlendState* GetBlendState() const { return m_bs.Get(); }
     57   ALWAYS_INLINE ID3D11InputLayout* GetInputLayout() const { return m_il.Get(); }
     58   ALWAYS_INLINE ID3D11VertexShader* GetVertexShader() const { return m_vs.Get(); }
     59   ALWAYS_INLINE ID3D11GeometryShader* GetGeometryShader() const { return m_gs.Get(); }
     60   ALWAYS_INLINE ID3D11PixelShader* GetPixelShader() const { return m_ps.Get(); }
     61   ALWAYS_INLINE D3D11_PRIMITIVE_TOPOLOGY GetPrimitiveTopology() const { return m_topology; }
     62   ALWAYS_INLINE u32 GetVertexStride() const { return m_vertex_stride; }
     63   ALWAYS_INLINE u32 GetBlendFactor() const { return m_blend_factor; }
     64   ALWAYS_INLINE const std::array<float, 4>& GetBlendFactorFloat() const { return m_blend_factor_float; }
     65 
     66 private:
     67   D3D11Pipeline(ComPtr<ID3D11RasterizerState> rs, ComPtr<ID3D11DepthStencilState> ds, ComPtr<ID3D11BlendState> bs,
     68                 ComPtr<ID3D11InputLayout> il, ComPtr<ID3D11VertexShader> vs, ComPtr<ID3D11GeometryShader> gs,
     69                 ComPtr<ID3D11PixelShader> ps, D3D11_PRIMITIVE_TOPOLOGY topology, u32 vertex_stride, u32 blend_factor);
     70 
     71   ComPtr<ID3D11RasterizerState> m_rs;
     72   ComPtr<ID3D11DepthStencilState> m_ds;
     73   ComPtr<ID3D11BlendState> m_bs;
     74   ComPtr<ID3D11InputLayout> m_il;
     75   ComPtr<ID3D11VertexShader> m_vs;
     76   ComPtr<ID3D11GeometryShader> m_gs;
     77   ComPtr<ID3D11PixelShader> m_ps;
     78   D3D11_PRIMITIVE_TOPOLOGY m_topology;
     79   u32 m_vertex_stride;
     80   u32 m_blend_factor;
     81   std::array<float, 4> m_blend_factor_float;
     82 };