Nugget
Loading...
Searching...
No Matches
fragments.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2022 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <EASTL/array.h>
30#include <EASTL/utility.h>
31#include <stdint.h>
32
34
35namespace psyqo {
36
56namespace Fragments {
57
66struct ChainEntryPS1;
67struct ChainEntryPC;
68
69#ifdef PS1_PC_PORT
71#else
73#endif
74
77 unsigned size;
78 void setEndMarker() {
79 next = nullptr;
80 size = 0;
81 }
82 void set(ChainEntry* next_, unsigned size_) {
83 next = next_;
84 size = size_;
85 }
86};
87
89 uintptr_t head;
90 void setEndMarker() {
91 head = 0xffffff;
92 }
93 void set(ChainEntryPS1* next, unsigned size) {
94 head = (size << 24) | (next->head & 0xffffff);
95 }
96};
97
98template <Primitive Prim>
100 constexpr size_t maxSize() const { return 1; }
101 template <typename... Args>
102 SimpleFragment(Args &&...args) : primitive(eastl::forward<Args>(args)...) {
103#ifndef PS1_PC_PORT
104 static_assert(sizeof(*this) == (sizeof(uint32_t) + sizeof(Prim)), "Spurious padding in simple fragment");
105#endif
106 }
107 explicit SimpleFragment(const SimpleFragment &) = default;
108 typedef Prim FragmentBaseType;
109 constexpr size_t getActualFragmentSize() const { return sizeof(Prim) / sizeof(uint32_t); }
111};
112
124template <Primitive Prim, size_t N>
126 constexpr size_t maxSize() const { return N; }
128#ifndef PS1_PC_PORT
129 static_assert(sizeof(*this) == (sizeof(unsigned) + sizeof(uintptr_t) + sizeof(Prim) * N),
130 "Spurious padding in fixed fragment");
131#endif
132 }
133 explicit FixedFragment(const FixedFragment &) = default;
134 typedef Prim FragmentBaseType;
135 size_t getActualFragmentSize() const { return (sizeof(Prim) * count) / sizeof(uint32_t); }
136 eastl::array<Prim, N> primitives;
137 unsigned count = N;
138};
139
154template <Primitive P, Primitive Prim, size_t N>
156 constexpr size_t maxSize() const { return N; }
158#ifndef PS1_PC_PORT
159 static_assert(sizeof(*this) == (sizeof(unsigned) + sizeof(uintptr_t) + sizeof(P) + sizeof(Prim) * N),
160 "Spurious padding in fixed fragment");
161#endif
162 }
164 typedef Prim FragmentBaseType;
165 size_t getActualFragmentSize() const { return (sizeof(P) + sizeof(Prim) * count) / sizeof(uint32_t); }
167 eastl::array<Prim, N> primitives;
168 unsigned count = N;
169};
170
171} // namespace Fragments
172
173} // namespace psyqo
Definition lua.hh:38
static int size
Definition string.h:32
Definition fragments.hh:75
void setEndMarker()
Definition fragments.hh:78
ChainEntry * next
Definition fragments.hh:76
unsigned size
Definition fragments.hh:77
void set(ChainEntry *next_, unsigned size_)
Definition fragments.hh:82
Definition fragments.hh:88
void setEndMarker()
Definition fragments.hh:90
void set(ChainEntryPS1 *next, unsigned size)
Definition fragments.hh:93
uintptr_t head
Definition fragments.hh:89
A maximum fixed sized fragment of similar primitives.
Definition fragments.hh:155
size_t getActualFragmentSize() const
Definition fragments.hh:165
FixedFragmentWithPrologue(const FixedFragmentWithPrologue &)=default
FixedFragmentWithPrologue()
Definition fragments.hh:157
unsigned count
Definition fragments.hh:168
eastl::array< Prim, N > primitives
Definition fragments.hh:167
P prologue
Definition fragments.hh:166
Prim FragmentBaseType
Definition fragments.hh:164
constexpr size_t maxSize() const
Definition fragments.hh:156
A maximum fixed sized fragment of similar primitives.
Definition fragments.hh:125
FixedFragment()
Definition fragments.hh:127
FixedFragment(const FixedFragment &)=default
constexpr size_t maxSize() const
Definition fragments.hh:126
size_t getActualFragmentSize() const
Definition fragments.hh:135
eastl::array< Prim, N > primitives
Definition fragments.hh:136
Prim FragmentBaseType
Definition fragments.hh:134
unsigned count
Definition fragments.hh:137
Definition fragments.hh:99
Prim primitive
Definition fragments.hh:110
constexpr size_t getActualFragmentSize() const
Definition fragments.hh:109
SimpleFragment(Args &&...args)
Definition fragments.hh:102
SimpleFragment(const SimpleFragment &)=default
constexpr size_t maxSize() const
Definition fragments.hh:100
Prim FragmentBaseType
Definition fragments.hh:108
void uint32_t(classId, spec)