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

d3d12_pipeline.h (2125B)


      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 #include "gpu_device.h"
      5 
      6 #include "common/windows_headers.h"
      7 
      8 #include <d3d12.h>
      9 #include <vector>
     10 #include <wrl/client.h>
     11 
     12 class D3D12Device;
     13 
     14 class D3D12Shader final : public GPUShader
     15 {
     16   friend D3D12Device;
     17 
     18 public:
     19   using Bytecode = std::vector<u8>;
     20 
     21   ~D3D12Shader() override;
     22 
     23   ALWAYS_INLINE const Bytecode& GetBytecode() const { return m_bytecode; }
     24   ALWAYS_INLINE D3D12_SHADER_BYTECODE GetD3DBytecode() const { return {m_bytecode.data(), m_bytecode.size()}; }
     25   ALWAYS_INLINE const u8* GetBytecodeData() const { return m_bytecode.data(); }
     26   ALWAYS_INLINE u32 GetBytecodeSize() const { return static_cast<u32>(m_bytecode.size()); }
     27 
     28   void SetDebugName(std::string_view name) override;
     29 
     30 private:
     31   D3D12Shader(GPUShaderStage stage, Bytecode bytecode);
     32 
     33   Bytecode m_bytecode;
     34 };
     35 
     36 class D3D12Pipeline final : public GPUPipeline
     37 {
     38   friend D3D12Device;
     39 
     40 public:
     41   ~D3D12Pipeline() override;
     42 
     43   ALWAYS_INLINE ID3D12PipelineState* GetPipeline() const { return m_pipeline.Get(); }
     44   ALWAYS_INLINE Layout GetLayout() const { return m_layout; }
     45   ALWAYS_INLINE D3D12_PRIMITIVE_TOPOLOGY GetTopology() const { return m_topology; }
     46   ALWAYS_INLINE u32 GetVertexStride() const { return m_vertex_stride; }
     47   ALWAYS_INLINE u32 GetBlendConstants() const { return m_blend_constants; }
     48   ALWAYS_INLINE const std::array<float, 4>& GetBlendConstantsF() const { return m_blend_constants_f; }
     49   ALWAYS_INLINE bool HasVertexStride() const { return (m_vertex_stride > 0); }
     50 
     51   void SetDebugName(std::string_view name) override;
     52 
     53   static std::string GetPipelineName(const GraphicsConfig& config);
     54 
     55 private:
     56   D3D12Pipeline(Microsoft::WRL::ComPtr<ID3D12PipelineState> pipeline, Layout layout, D3D12_PRIMITIVE_TOPOLOGY topology,
     57                 u32 vertex_stride, u32 blend_constants);
     58 
     59   Microsoft::WRL::ComPtr<ID3D12PipelineState> m_pipeline;
     60   Layout m_layout;
     61   D3D12_PRIMITIVE_TOPOLOGY m_topology;
     62   u32 m_vertex_stride;
     63   u32 m_blend_constants;
     64   std::array<float, 4> m_blend_constants_f;
     65 };