Nugget
Bare-metal libraries and examples for the original PlayStation
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() { head = 0xffffff; }
91 void set(ChainEntryPS1 *next, unsigned size) { head = (size << 24) | (next->head & 0xffffff); }
92};
93
94template <Primitive Prim>
96 constexpr size_t maxSize() const { return 1; }
97 template <typename... Args>
98 SimpleFragment(Args &&...args) : primitive(eastl::forward<Args>(args)...) {
99#ifndef PS1_PC_PORT
100 static_assert(sizeof(*this) == (sizeof(uint32_t) + sizeof(Prim)), "Spurious padding in simple fragment");
101#endif
102 }
103 explicit SimpleFragment(const SimpleFragment &) = default;
104 typedef Prim FragmentBaseType;
105 constexpr size_t getActualFragmentSize() const { return sizeof(Prim) / sizeof(uint32_t); }
107};
108
120template <Primitive Prim, size_t N>
122 constexpr size_t maxSize() const { return N; }
124#ifndef PS1_PC_PORT
125 static_assert(sizeof(*this) == (sizeof(unsigned) + sizeof(uintptr_t) + sizeof(Prim) * N),
126 "Spurious padding in fixed fragment");
127#endif
128 }
129 explicit FixedFragment(const FixedFragment &) = default;
130 typedef Prim FragmentBaseType;
131 size_t getActualFragmentSize() const { return (sizeof(Prim) * count) / sizeof(uint32_t); }
132 eastl::array<Prim, N> primitives;
133 unsigned count = N;
134};
135
150template <Primitive P, Primitive Prim, size_t N>
152 constexpr size_t maxSize() const { return N; }
154#ifndef PS1_PC_PORT
155 static_assert(sizeof(*this) == (sizeof(unsigned) + sizeof(uintptr_t) + sizeof(P) + sizeof(Prim) * N),
156 "Spurious padding in fixed fragment");
157#endif
158 }
160 typedef Prim FragmentBaseType;
161 size_t getActualFragmentSize() const { return (sizeof(P) + sizeof(Prim) * count) / sizeof(uint32_t); }
163 eastl::array<Prim, N> primitives;
164 unsigned count = N;
165};
166
167} // namespace Fragments
168
169} // namespace psyqo
static int size
Definition string.h:149
#define N
Definition main.c:37
Definition lua.hh:40
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:91
uintptr_t head
Definition fragments.hh:89
A maximum fixed sized fragment of similar primitives.
Definition fragments.hh:151
size_t getActualFragmentSize() const
Definition fragments.hh:161
FixedFragmentWithPrologue(const FixedFragmentWithPrologue &)=default
FixedFragmentWithPrologue()
Definition fragments.hh:153
unsigned count
Definition fragments.hh:164
eastl::array< Prim, N > primitives
Definition fragments.hh:163
P prologue
Definition fragments.hh:162
Prim FragmentBaseType
Definition fragments.hh:160
constexpr size_t maxSize() const
Definition fragments.hh:152
A maximum fixed sized fragment of similar primitives.
Definition fragments.hh:121
FixedFragment()
Definition fragments.hh:123
FixedFragment(const FixedFragment &)=default
constexpr size_t maxSize() const
Definition fragments.hh:122
size_t getActualFragmentSize() const
Definition fragments.hh:131
eastl::array< Prim, N > primitives
Definition fragments.hh:132
Prim FragmentBaseType
Definition fragments.hh:130
unsigned count
Definition fragments.hh:133
Definition fragments.hh:95
Prim primitive
Definition fragments.hh:106
constexpr size_t getActualFragmentSize() const
Definition fragments.hh:105
SimpleFragment(Args &&...args)
Definition fragments.hh:98
SimpleFragment(const SimpleFragment &)=default
constexpr size_t maxSize() const
Definition fragments.hh:96
Prim FragmentBaseType
Definition fragments.hh:104