summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/varying_state.h
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-06-24 02:41:09 -0300
committerGravatar ameerj2021-07-22 21:51:39 -0400
commit7dafa96ab59892b7f1fbffdb61e4326e6443955f (patch)
tree5ab58d56860db635542ea1ec24be258bd86b40b9 /src/shader_recompiler/varying_state.h
parentvk_graphics_pipeline: Implement conservative rendering (diff)
downloadyuzu-7dafa96ab59892b7f1fbffdb61e4326e6443955f.tar.gz
yuzu-7dafa96ab59892b7f1fbffdb61e4326e6443955f.tar.xz
yuzu-7dafa96ab59892b7f1fbffdb61e4326e6443955f.zip
shader: Rework varyings and implement passthrough geometry shaders
Put all varyings into a single std::bitset with helpers to access it. Implement passthrough geometry shaders using host's.
Diffstat (limited to '')
-rw-r--r--src/shader_recompiler/varying_state.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/shader_recompiler/varying_state.h b/src/shader_recompiler/varying_state.h
new file mode 100644
index 000000000..9d7b24a76
--- /dev/null
+++ b/src/shader_recompiler/varying_state.h
@@ -0,0 +1,69 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <bitset>
8#include <cstddef>
9
10#include "shader_recompiler/frontend/ir/attribute.h"
11
12namespace Shader {
13
14struct VaryingState {
15 std::bitset<256> mask{};
16
17 void Set(IR::Attribute attribute, bool state = true) {
18 mask[static_cast<size_t>(attribute)] = state;
19 }
20
21 [[nodiscard]] bool operator[](IR::Attribute attribute) const noexcept {
22 return mask[static_cast<size_t>(attribute)];
23 }
24
25 [[nodiscard]] bool AnyComponent(IR::Attribute base) const noexcept {
26 return mask[static_cast<size_t>(base) + 0] || mask[static_cast<size_t>(base) + 1] ||
27 mask[static_cast<size_t>(base) + 2] || mask[static_cast<size_t>(base) + 3];
28 }
29
30 [[nodiscard]] bool AllComponents(IR::Attribute base) const noexcept {
31 return mask[static_cast<size_t>(base) + 0] && mask[static_cast<size_t>(base) + 1] &&
32 mask[static_cast<size_t>(base) + 2] && mask[static_cast<size_t>(base) + 3];
33 }
34
35 [[nodiscard]] bool IsUniform(IR::Attribute base) const noexcept {
36 return AnyComponent(base) == AllComponents(base);
37 }
38
39 [[nodiscard]] bool Generic(size_t index, size_t component) const noexcept {
40 return mask[static_cast<size_t>(IR::Attribute::Generic0X) + index * 4 + component];
41 }
42
43 [[nodiscard]] bool Generic(size_t index) const noexcept {
44 return Generic(index, 0) || Generic(index, 1) || Generic(index, 2) || Generic(index, 3);
45 }
46
47 [[nodiscard]] bool ClipDistances() const noexcept {
48 return AnyComponent(IR::Attribute::ClipDistance0) ||
49 AnyComponent(IR::Attribute::ClipDistance4);
50 }
51
52 [[nodiscard]] bool Legacy() const noexcept {
53 return AnyComponent(IR::Attribute::ColorFrontDiffuseR) ||
54 AnyComponent(IR::Attribute::ColorFrontSpecularR) ||
55 AnyComponent(IR::Attribute::ColorBackDiffuseR) ||
56 AnyComponent(IR::Attribute::ColorBackSpecularR) || FixedFunctionTexture();
57 }
58
59 [[nodiscard]] bool FixedFunctionTexture() const noexcept {
60 for (size_t index = 0; index < 10; ++index) {
61 if (AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
62 return true;
63 }
64 }
65 return false;
66 }
67};
68
69} // namespace Shader