Skip to content

Commit

Permalink
Merge pull request #1739 from nicolasnoble/proper-no-unique-address
Browse files Browse the repository at this point in the history
Properly supporting no_unique_address.
  • Loading branch information
nicolasnoble authored Sep 19, 2024
2 parents 84ae758 + 50aae88 commit 731fe39
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
53 changes: 38 additions & 15 deletions src/core/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "support/file.h"
#include "support/list.h"
#include "support/opengl.h"
#include "support/polyfills.h"
#include "support/slice.h"

namespace PCSX {
Expand Down Expand Up @@ -291,7 +292,7 @@ class GPU {
};
enum class TexDepth { Tex4Bits, Tex8Bits, Tex16Bits };

struct Empty {};
struct EmptyColor {};

struct ClearCache final : public Logged {
std::string_view getName() override { return "Clear Cache"; }
Expand Down Expand Up @@ -546,12 +547,22 @@ class GPU {
}
uint32_t colors[count];
int x[count], y[count];
struct Empty {};
typedef typename std::conditional<textured == Textured::Yes, unsigned, Empty>::type TextureUnitType;
[[no_unique_address]] TextureUnitType u[count];
[[no_unique_address]] TextureUnitType v[count];
[[no_unique_address]] typename std::conditional<textured == Textured::Yes, TPage, Empty>::type tpage;
[[no_unique_address]] typename std::conditional<textured == Textured::Yes, TWindow, Empty>::type twindow;
[[no_unique_address]] typename std::conditional<textured == Textured::Yes, uint16_t, Empty>::type clutraw;
struct EmptyU {};
typedef typename std::conditional<textured == Textured::Yes, unsigned, EmptyU>::type TextureUnitTypeU;
struct EmptyV {};
typedef typename std::conditional<textured == Textured::Yes, unsigned, EmptyV>::type TextureUnitTypeV;
POLYFILL_NO_UNIQUE_ADDRESS TextureUnitTypeU u[count];
POLYFILL_NO_UNIQUE_ADDRESS TextureUnitTypeV v[count];
struct EmptyTPage {};
POLYFILL_NO_UNIQUE_ADDRESS typename std::conditional<textured == Textured::Yes, TPage, EmptyTPage>::type tpage;
struct EmptyTWindow {};
POLYFILL_NO_UNIQUE_ADDRESS
typename std::conditional<textured == Textured::Yes, TWindow, EmptyTWindow>::type twindow;
struct EmptyClutRAW {};
POLYFILL_NO_UNIQUE_ADDRESS
typename std::conditional<textured == Textured::Yes, uint16_t, EmptyClutRAW>::type clutraw;
DrawingOffset offset;
TextureUnitType clutX() {
if constexpr (textured == Textured::Yes) {
Expand Down Expand Up @@ -620,7 +631,9 @@ class GPU {

private:
GPUStats stats;
[[no_unique_address]] typename std::conditional<lineType == LineType::Simple, unsigned, Empty>::type m_count;
struct Empty {};
POLYFILL_NO_UNIQUE_ADDRESS
typename std::conditional<lineType == LineType::Simple, unsigned, Empty>::type m_count;
enum { READ_COLOR, READ_XY } m_state = READ_COLOR;
};

Expand All @@ -641,15 +654,25 @@ class GPU {
}

int x, y, w, h;
struct Empty {};
typedef typename std::conditional<textured == Textured::Yes, unsigned, Empty>::type TextureUnitType;
[[no_unique_address]]
typename std::conditional<(textured == Textured::No) || (modulation == Modulation::On), uint32_t, Empty>::type
color;
[[no_unique_address]] TextureUnitType u;
[[no_unique_address]] TextureUnitType v;
[[no_unique_address]] typename std::conditional<textured == Textured::Yes, TPage, Empty>::type tpage;
[[no_unique_address]] typename std::conditional<textured == Textured::Yes, TWindow, Empty>::type twindow;
[[no_unique_address]] typename std::conditional<textured == Textured::Yes, uint16_t, Empty>::type clutraw;
struct EmptyU {};
typedef typename std::conditional<textured == Textured::Yes, unsigned, EmptyU>::type TextureUnitTypeU;
struct EmptyV {};
typedef typename std::conditional<textured == Textured::Yes, unsigned, EmptyV>::type TextureUnitTypeV;
POLYFILL_NO_UNIQUE_ADDRESS
typename std::conditional<(textured == Textured::No) || (modulation == Modulation::On), uint32_t,
EmptyColor>::type color;
POLYFILL_NO_UNIQUE_ADDRESS TextureUnitTypeU u;
POLYFILL_NO_UNIQUE_ADDRESS TextureUnitTypeV v;
struct EmptyTPage {};
POLYFILL_NO_UNIQUE_ADDRESS typename std::conditional<textured == Textured::Yes, TPage, EmptyTPage>::type tpage;
struct EmptyTWindow {};
POLYFILL_NO_UNIQUE_ADDRESS
typename std::conditional<textured == Textured::Yes, TWindow, EmptyTWindow>::type twindow;
struct EmptyClutRAW {};
POLYFILL_NO_UNIQUE_ADDRESS
typename std::conditional<textured == Textured::Yes, uint16_t, EmptyClutRAW>::type clutraw;
DrawingOffset offset;
TextureUnitType clutX() {
if constexpr (textured == Textured::Yes) {
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/soft/gpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ static constexpr inline uint16_t BGR24to16(uint32_t BGR) {
return (uint16_t)(((BGR >> 3) & 0x1f) | ((BGR & 0xf80000) >> 9) | ((BGR & 0xf800) >> 6));
}

static constexpr inline uint16_t BGR24to16(PCSX::GPU::Empty) { return 0; }
static constexpr inline uint16_t BGR24to16(PCSX::GPU::EmptyColor) { return 0; }

void PCSX::SoftGPU::impl::write0(ClearCache *) {}

Expand Down
6 changes: 6 additions & 0 deletions src/support/polyfills.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ SOFTWARE.
#include <concepts>
#include <version>

#ifdef _MSC_VER
#define POLYFILL_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#else
#define POLYFILL_NO_UNIQUE_ADDRESS [[no_unique_address]]
#endif

namespace PCSX {

namespace PolyFill {
Expand Down

0 comments on commit 731fe39

Please sign in to comment.