-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShaderMeta.h
More file actions
129 lines (111 loc) · 3.37 KB
/
Copy pathShaderMeta.h
File metadata and controls
129 lines (111 loc) · 3.37 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#pragma once
#include "RHI/RHIPipelineState.h"
#include "TypeTrait.h"
#include <array>
#include <cstdint>
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
#include <variant>
#include <vector>
enum class ShaderPropertyType : std::uint8_t
{
Float,
Float2,
Float3,
Float4,
Int,
Bool,
Float4x4,
Texture2D,
};
using ShaderPropertyDefault = std::variant<
std::monostate,
float,
std::array<float, 2>,
std::array<float, 3>,
std::array<float, 4>,
std::int32_t,
bool,
std::array<float, 16>,
FileGuid>;
struct ShaderPropertyDesc
{
std::string name;
std::string label;
ShaderPropertyType type{ ShaderPropertyType::Float };
ShaderPropertyDefault defaultValue;
};
struct ShaderKeywordAxis
{
std::string name;
std::vector<std::string> values;
};
struct ShaderStageEntry
{
std::string entry;
};
enum class ShaderPassQueue : std::uint8_t
{
Opaque,
Transparent,
Shadow,
Compute,
};
enum class ShaderBlendMode : std::uint8_t
{
Off,
Alpha,
Additive,
};
// ShaderMeta의 state 블록은 별도 그래픽 어휘를 만들지 않는다. 실제 PSO 기술과
// 같은 RHI 열거를 소유하고, 조립 시 bytecode/layout/format을 보존한 채 상태만 채운다.
struct ShaderRenderState
{
RHIFillMode fillMode{ RHIFillMode::Solid };
RHICullMode cullMode{ RHICullMode::Back };
ShaderBlendMode blendMode{ ShaderBlendMode::Off };
RHICompareOp depthTest{ RHICompareOp::Less };
bool depthWrite{ true };
RHITopologyType topologyType{ RHITopologyType::Triangle };
void ApplyTo(RHIGraphicsPipelineDesc& desc) const;
};
struct ShaderPassDesc
{
std::string name;
std::optional<ShaderStageEntry> vertex;
std::optional<ShaderStageEntry> pixel;
std::optional<ShaderStageEntry> compute;
ShaderRenderState state;
ShaderPassQueue queue{ ShaderPassQueue::Opaque };
bool IsCompute() const { return compute.has_value(); }
};
struct ShaderMeta
{
static constexpr std::uint32_t kSchemaVersion = 1;
FileGuid guid{};
std::uint32_t schemaVersion{ kSchemaVersion };
std::string name;
std::filesystem::path source;
// runtime-only loader context. authored source는 meta 파일 기준 상대 경로이므로
// immutable snapshot이 RenderThread로 넘어간 뒤에도 정식 경로를 재구성하려면
// origin이 함께 있어야 한다. 디스크 schema field는 아니다.
std::filesystem::path originPath;
std::vector<ShaderPropertyDesc> properties;
std::vector<ShaderKeywordAxis> keywords;
std::vector<ShaderPassDesc> passes;
std::filesystem::path ResolveSource(
const std::filesystem::path& metaPath) const;
};
namespace ShaderMetaLoader
{
// guid는 기존 AssetMetaRegistry가 해석한 sidecar 정체성이다. 이 로더는 .meta를
// 다시 읽거나 별도 registry를 만들지 않는다.
bool LoadFile(const std::filesystem::path& path, const FileGuid& guid,
ShaderMeta& outMeta, std::string& outError);
// Editor importer와 자가 검증이 디스크 게시 전에 같은 검증기를 쓸 수 있는 경계.
// originPath는 source 상대 경로의 기준이며 .shadermeta 파일명을 포함한다.
bool Parse(std::string_view text, const std::filesystem::path& originPath,
const FileGuid& guid, ShaderMeta& outMeta, std::string& outError);
}