summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Resources/ShaderResource.h
blob: 1e59a1b11d53f39f06103dfebe12504856fc6e4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2025 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <atomic>
#include <optional>

#include "VideoCommon/Resources/Resource.h"

#include "VideoCommon/Assets/ShaderAsset.h"
#include "VideoCommon/GXPipelineTypes.h"
#include "VideoCommon/ShaderGenCommon.h"

namespace VideoCommon
{
class ShaderResource final : public Resource
{
public:
  ShaderResource(Resource::ResourceContext resource_context,
                 std::optional<GXPipelineUid> pipeline_uid, std::string preprocessor_setting,
                 const ShaderHostConfig& shader_host_config);

  class Data
  {
  public:
    AbstractShader* GetVertexShader() const;
    AbstractShader* GetPixelShader() const;
    AbstractShader* GetGeometryShader() const;

    bool IsCompiled() const;
    AbstractTextureType GetTextureType(std::size_t index);

  private:
    friend class ShaderResource;
    std::unique_ptr<AbstractShader> m_vertex_shader;
    std::unique_ptr<AbstractShader> m_pixel_shader;
    std::unique_ptr<AbstractShader> m_geometry_shader;
    std::shared_ptr<RasterSurfaceShaderData> m_shader_data;
    bool m_needs_geometry_shader = false;
    std::atomic_bool m_processing_finished;
  };

  // Changes the shader host config. Shaders should be reloaded afterwards.
  void SetHostConfig(const ShaderHostConfig& host_config);
  const std::shared_ptr<Data>& GetData() const { return m_current_data; }

  void MarkAsActive() override;
  void MarkAsPending() override;

private:
  void ResetData() override;
  Resource::TaskComplete CollectPrimaryData() override;
  TaskComplete ProcessData() override;

  // Note: asset cache owns the asset, we access as a reference
  RasterSurfaceShaderAsset* m_shader_asset = nullptr;

  std::shared_ptr<Data> m_current_data;
  std::shared_ptr<Data> m_load_data;

  bool m_processing_load_data = false;

  ShaderHostConfig m_shader_host_config;

  // If provided, denotes this shader will be used as a custom draw shader.
  // If not provided, denotes this will be used as an efb post processing shader.
  std::optional<GXPipelineUid> m_uid;
  std::string m_preprocessor_settings;
};
}  // namespace VideoCommon