Debian Codegraph @

Source/Core/VideoCommon/Assets/ShaderAsset.h

raw symbols SCIP
1 // Copyright 2023 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7 #include <memory>
8 #include <span>
9 #include <string>
10 #include <string_view>
11 #include <variant>
12 #include <vector>
13
14 #include <picojson.h>
15
16 #include "VideoCommon/Assets/CustomAsset.h"
17 #include "VideoCommon/ShaderCompileUtils.h"
18 #include "VideoCommon/TextureConfig.h"
19
20 class ShaderCode;
21
22 namespace VideoCommon
23 {
24 struct ShaderProperty
25 {
26 struct RGB
27 {
28 std::array<float, 3> value;
29 };
30
31 struct RGBA
32 {
33 std::array<float, 4> value;
34 };
35
36 using Value = std::variant<s32, std::array<s32, 2>, std::array<s32, 3>, std::array<s32, 4>, float,
37 std::array<float, 2>, std::array<float, 3>, std::array<float, 4>, bool,
38 RGB, RGBA>;
39 static std::span<const std::string_view> GetValueTypeNames();
40 static Value GetDefaultValueFromTypeName(std::string_view name);
41 static void WriteAsShaderCode(ShaderCode& shader_source, const ShaderProperty& property);
42
43 Value default_value;
44 std::string name;
45 std::string description;
46 };
47
48 struct RasterSurfaceShaderData
49 {
50 RasterSurfaceShaderData() = default;
51 RasterSurfaceShaderData(const RasterSurfaceShaderData&) = delete;
52 RasterSurfaceShaderData(RasterSurfaceShaderData&&) = default;
53 ~RasterSurfaceShaderData() = default;
54 RasterSurfaceShaderData& operator=(const RasterSurfaceShaderData&) = delete;
55 RasterSurfaceShaderData& operator=(RasterSurfaceShaderData&&) = default;
56
57 static bool FromJson(const CustomAssetLibrary::AssetID& asset_id, const picojson::object& json,
58 RasterSurfaceShaderData* data);
59 static void ToJson(picojson::object& obj, const RasterSurfaceShaderData& data);
60
61 // These shader properties describe the input that the
62 // shader expects to expose. The key is text
63 // expected to be in the shader code and the property
64 // describes various details about the input
65 std::vector<ShaderProperty> uniform_properties;
66 std::string vertex_source;
67 std::string pixel_source;
68
69 struct SamplerData
70 {
71 AbstractTextureType type;
72 std::string name;
73
74 bool operator==(const SamplerData&) const = default;
75 };
76 std::vector<SamplerData> samplers;
77
78 std::unique_ptr<VideoCommon::ShaderIncluder> shader_includer;
79 };
80
81 class RasterSurfaceShaderAsset final : public CustomLoadableAsset<RasterSurfaceShaderData>
82 {
83 public:
84 using CustomLoadableAsset::CustomLoadableAsset;
85
86 private:
87 CustomAssetLibrary::LoadInfo LoadImpl(const CustomAssetLibrary::AssetID& asset_id) override;
88 };
89 } // namespace VideoCommon