Skip to content

Commit

Permalink
3rdParty: rebase rt64 on latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Jul 8, 2024
1 parent 2ac0594 commit 9899df4
Show file tree
Hide file tree
Showing 36 changed files with 178 additions and 63 deletions.
9 changes: 8 additions & 1 deletion Source/3rdParty/rt64/include/rt64_extended_gbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
#define G_EX_PUSHGEOMETRYMODE_V1 0x000029
#define G_EX_POPGEOMETRYMODE_V1 0x00002A
#define G_EX_SETDITHERNOISESTRENGTH_V1 0x00002B
#define G_EX_MAX 0x00002C
#define G_EX_SETRDRAMEXTENDED_V1 0x00002C
#define G_EX_MAX 0x00002D

#define G_EX_ORIGIN_NONE 0x800
#define G_EX_ORIGIN_LEFT 0x0
Expand Down Expand Up @@ -508,4 +509,10 @@ typedef union {
PARAM((value) * 1024, 16, 0) \
)

#define gEXSetRDRAMExtended(cmd, isExtended) \
G_EX_COMMAND1(cmd, \
PARAM(RT64_EXTENDED_OPCODE, 8, 24) | PARAM(G_EX_SETRDRAMEXTENDED_V1, 24, 0), \
PARAM(isExtended, 1, 0) \
)

#endif // RT64_EXTENDED_GBI
1 change: 1 addition & 0 deletions Source/3rdParty/rt64/src/common/rt64_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace RT64 {
// that are available without root privileges are lower priority. Instead you can set the thread's "nice" value, which ranges
// from -20 to 19 (lower being higher priority). However, by strict POSIX spec "nice" is meant to be per-process instead of
// per-thread. Therefore to avoid issues in case Linux is modified to match the spec in the future, this function does nothing.
(void)priority;
# else
static_assert(false, "Unimplemented");
# endif
Expand Down
10 changes: 6 additions & 4 deletions Source/3rdParty/rt64/src/d3d12/rt64_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2966,12 +2966,9 @@ namespace RT64 {

// Pick this adapter and device if it has better feature support than the current one.
bool preferOverNothing = (adapter == nullptr) || (d3d == nullptr);
bool preferShaderModel = (dataShaderModel.HighestShaderModel > shaderModel);
bool preferRtSupport = rtSupportOption && !capabilities.raytracing;
bool preferRtStateUpdateSupport = rtStateUpdateSupportOption && !capabilities.raytracingStateUpdate;
bool preferVideoMemory = adapterDesc.DedicatedVideoMemory > dedicatedVideoMemory;
bool preferUserChoice = false;//wcsstr(adapterDesc.Description, L"AMD") != nullptr;
bool preferOption = preferOverNothing || preferShaderModel || preferRtSupport || preferRtStateUpdateSupport || preferVideoMemory || preferUserChoice;
bool preferOption = preferOverNothing || preferVideoMemory || preferUserChoice;
if (preferOption) {
if (d3d != nullptr) {
d3d->Release();
Expand All @@ -2987,6 +2984,7 @@ namespace RT64 {
capabilities.raytracing = rtSupportOption;
capabilities.raytracingStateUpdate = rtStateUpdateSupportOption;
capabilities.sampleLocations = samplePositionsOption;
description.name = win32::Utf16ToUtf8(adapterDesc.Description);
dedicatedVideoMemory = adapterDesc.DedicatedVideoMemory;

if (preferUserChoice) {
Expand Down Expand Up @@ -3290,6 +3288,10 @@ namespace RT64 {
return capabilities;
}

const RenderDeviceDescription &D3D12Device::getDescription() const {
return description;
}

RenderSampleCounts D3D12Device::getSampleCountsSupported(RenderFormat format) const {
HRESULT res;
RenderSampleCounts countsSupported = RenderSampleCount::COUNT_0;
Expand Down
4 changes: 3 additions & 1 deletion Source/3rdParty/rt64/src/d3d12/rt64_d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace RT64 {
struct D3D12Texture;

struct D3D12DescriptorHeapAllocator {
enum {
enum : uint32_t {
INVALID_OFFSET = 0xFFFFFFFFU
};

Expand Down Expand Up @@ -382,6 +382,7 @@ namespace RT64 {
std::unique_ptr<D3D12DescriptorHeapAllocator> colorTargetHeapAllocator;
std::unique_ptr<D3D12DescriptorHeapAllocator> depthTargetHeapAllocator;
RenderDeviceCapabilities capabilities;
RenderDeviceDescription description;

D3D12Device(D3D12Interface *renderInterface);
~D3D12Device() override;
Expand All @@ -404,6 +405,7 @@ namespace RT64 {
void setTopLevelASBuildInfo(RenderTopLevelASBuildInfo &buildInfo, const RenderTopLevelASInstance *instances, uint32_t instanceCount, bool preferFastBuild, bool preferFastTrace) override;
void setShaderBindingTableInfo(RenderShaderBindingTableInfo &tableInfo, const RenderShaderBindingGroups &groups, const RenderPipeline *pipeline, RenderDescriptorSet **descriptorSets, uint32_t descriptorSetCount) override;
const RenderDeviceCapabilities &getCapabilities() const override;
const RenderDeviceDescription &getDescription() const override;
RenderSampleCounts getSampleCountsSupported(RenderFormat format) const override;
void release();
bool isValid() const;
Expand Down
9 changes: 5 additions & 4 deletions Source/3rdParty/rt64/src/gbi/rt64_gbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "rt64_gbi.h"

#include <cassert>
#include <cinttypes>

#include "rt64_gbi_extended.h"
#include "rt64_gbi_f3d.h"
Expand Down Expand Up @@ -171,7 +172,7 @@ namespace RT64 {

// If we used an unknown value in the database, print the hash.
if (gbiSegment.hashValue == GBI_UNKNOWN_HASH_NUMB) {
fprintf(stdout, "HASH: 0x%016llXULL SIZE: 0x%X\n", rdramHash, rdramHashed);
fprintf(stdout, "HASH: 0x%016" PRIX64 "ULL SIZE: 0x%X\n", rdramHash, rdramHashed);
}
};

Expand Down Expand Up @@ -290,8 +291,8 @@ namespace RT64 {
const uint8_t *twoPointResult = std::search(searchResult, searchResultEnd, twoPointPattern, twoPointPattern + std::size(twoPointPattern) - 1);
if ((f3dexResult != searchResultEnd) && (twoPointResult != searchResultEnd)) {
const uint32_t lastOverlay = *reinterpret_cast<const uint32_t *>(&RDRAM[dataAddress + 0x410]);
const uint16_t lastOverlaySize = *reinterpret_cast<const uint16_t *>(&RDRAM[dataAddress + 0x414 ^ 2]);
const uint16_t estimatedDataSize = *reinterpret_cast<const uint16_t *>(&RDRAM[dataAddress + 0x380 ^ 2]);
const uint16_t lastOverlaySize = *reinterpret_cast<const uint16_t *>(&RDRAM[(dataAddress + 0x414) ^ 2]);
const uint16_t estimatedDataSize = *reinterpret_cast<const uint16_t *>(&RDRAM[(dataAddress + 0x380) ^ 2]);
const uint32_t textSize = lastOverlay + lastOverlaySize + 1;
fprintf(stderr, "Detected text size is 0x%X\n", textSize);
fprintf(stderr, "Estimated data size is 0x%X\n", estimatedDataSize);
Expand All @@ -300,7 +301,7 @@ namespace RT64 {
const uint8_t *s2dexResult = std::search(searchResult, searchResultEnd, s2dexPattern, s2dexPattern + std::size(s2dexPattern) - 1);
if ((s2dexResult != searchResultEnd) && (twoPointResult != searchResultEnd)) {
const uint32_t lastOverlay = *reinterpret_cast<const uint32_t *>(&RDRAM[dataAddress + 0x31C]);
const uint16_t lastOverlaySize = *reinterpret_cast<const uint16_t *>(&RDRAM[dataAddress + 0x320 ^ 2]);
const uint16_t lastOverlaySize = *reinterpret_cast<const uint16_t *>(&RDRAM[(dataAddress + 0x320) ^ 2]);
const uint32_t textSize = lastOverlay + lastOverlaySize + 1;
fprintf(stderr, "Detected text size is 0x%X\n", textSize);
}
Expand Down
10 changes: 8 additions & 2 deletions Source/3rdParty/rt64/src/gbi/rt64_gbi_extended.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,19 @@ namespace RT64 {
state->setDitherNoiseStrength(noiseStrength / 1024.0f);
}

void setRDRAMExtendedV1(State *state, DisplayList **dl) {
const uint8_t extended = (*dl)->p1(0, 1);
state->setExtendedRDRAM(extended);
}

void noOpHook(State *state, DisplayList **dl) {
uint32_t magicNumber = (*dl)->p0(0, 24);
if (magicNumber == RT64_HOOK_MAGIC_NUMBER) {
uint32_t hookValue = (*dl)->p1(0, 28);
uint32_t hookOp = (*dl)->p1(28, 4);
switch (hookOp) {
case RT64_HOOK_OP_GETVERSION: {
const uint32_t rdramAddress = state->rsp->fromSegmented(hookValue);
const uint32_t rdramAddress = state->rsp->fromSegmentedMasked(hookValue);
uint32_t *returnRDRAM = reinterpret_cast<uint32_t *>(state->fromRDRAM(rdramAddress));
*returnRDRAM = G_EX_VERSION;
break;
Expand All @@ -317,7 +322,7 @@ namespace RT64 {
state->pushReturnAddress(*dl);
}

const uint32_t rdramAddress = state->rsp->fromSegmented(hookValue);
const uint32_t rdramAddress = state->rsp->fromSegmentedMasked(hookValue);
*dl = reinterpret_cast<DisplayList *>(state->fromRDRAM(rdramAddress)) - 1;
break;
}
Expand Down Expand Up @@ -386,6 +391,7 @@ namespace RT64 {
Map[G_EX_PUSHGEOMETRYMODE_V1] = &pushGeometryModeV1;
Map[G_EX_POPGEOMETRYMODE_V1] = &popGeometryModeV1;
Map[G_EX_SETDITHERNOISESTRENGTH_V1] = &setDitherNoiseStrengthV1;
Map[G_EX_SETRDRAMEXTENDED_V1] = &setRDRAMExtendedV1;
MapInitialized = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/3rdParty/rt64/src/gbi/rt64_gbi_f3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace RT64 {
state->pushReturnAddress(*dl);
}

const uint32_t rdramAddress = state->rsp->fromSegmented((*dl)->w1);
const uint32_t rdramAddress = state->rsp->fromSegmentedMasked((*dl)->w1);
*dl = reinterpret_cast<DisplayList *>(state->fromRDRAM(rdramAddress)) - 1;
}

Expand Down Expand Up @@ -121,7 +121,7 @@ namespace RT64 {
// TODO
break;
case G_MW_SEGMENT:
state->rsp->setSegment((*dl)->p0(10, 4), (*dl)->w1 & 0x00FFFFFF);
state->rsp->setSegment((*dl)->p0(10, 4), (*dl)->w1);
break;
case G_MW_FOG:
state->rsp->setFog((int16_t)((*dl)->p1(16, 16)), (int16_t)((*dl)->p1(0, 16)));
Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/rt64/src/gbi/rt64_gbi_f3dex2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace RT64 {
state->rsp->setClipRatio((*dl)->w1);
break;
case G_MW_SEGMENT:
state->rsp->setSegment((*dl)->p0(2, 4), (*dl)->w1 & 0x00FFFFFF);
state->rsp->setSegment((*dl)->p0(2, 4), (*dl)->w1);
break;
case G_MW_FOG:
state->rsp->setFog((int16_t)((*dl)->p1(16, 16)), (int16_t)((*dl)->p1(0, 16)));
Expand Down
6 changes: 3 additions & 3 deletions Source/3rdParty/rt64/src/gbi/rt64_gbi_s2dex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace RT64 {

RDP *rdp = state->rdp.get();
RSP *rsp = state->rsp.get();
const uint32_t rdramAddress = state->rsp->fromSegmented((*dl)->w1);
const uint32_t rdramAddress = state->rsp->fromSegmentedMasked((*dl)->w1);
// TODO load this into the S2D struct buffer for a more accurate implementation in case there's ever command state bleed.
const uObjBg *bgObject = reinterpret_cast<const uObjBg *>(state->fromRDRAM(rdramAddress));
const uObjBg_t &bg = bgObject->bg;
Expand Down Expand Up @@ -398,7 +398,7 @@ namespace RT64 {

RDP *rdp = state->rdp.get();
RSP* rsp = state->rsp.get();
const uint32_t rdramAddress = state->rsp->fromSegmented((*dl)->w1);
const uint32_t rdramAddress = state->rsp->fromSegmentedMasked((*dl)->w1);
// TODO load this into the S2D struct buffer for a more accurate implementation in case there's ever command state bleed.
const uObjBg *bgObject = reinterpret_cast<const uObjBg *>(state->fromRDRAM(rdramAddress));
const uObjBg_t &bg = bgObject->bg;
Expand Down Expand Up @@ -451,7 +451,7 @@ namespace RT64 {

void readS2DStruct(State *state, uint32_t ptr, uint32_t loadSize) {
// Convert the segmented obj pointer
uint32_t rdramAddress = state->rsp->fromSegmented(ptr);
uint32_t rdramAddress = state->rsp->fromSegmentedMasked(ptr);
// Mask the address as the RSP DMA hardware would
rdramAddress &= RSP_DMA_MASK;
// Truncate the load size as the ucode does
Expand Down
6 changes: 3 additions & 3 deletions Source/3rdParty/rt64/src/gui/rt64_debugger_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ namespace RT64 {
uint32_t totalSyncCount = 0;
for (uint32_t f = 0; f < workload.fbPairCount; f++) {
auto &fbPair = workload.fbPairs[f];
if (renderer.framebufferIndex == f) {
if ((uint32_t)renderer.framebufferIndex == f) {
renderer.framebufferAddress = renderer.framebufferDepth ? fbPair.depthImage.address : fbPair.colorImage.address;
}

Expand Down Expand Up @@ -896,7 +896,7 @@ namespace RT64 {
ImGui::PushID(l);

if (openCall) {
bool open = (openLoadIndex == (callDesc.loadIndex + l));
bool open = ((uint32_t)openLoadIndex == (callDesc.loadIndex + l));
ImGui::SetNextItemOpen(open);
if (open) {
ImGui::SetScrollHereY(0.0f);
Expand Down Expand Up @@ -984,7 +984,7 @@ namespace RT64 {
const DrawCallTile &callTile = drawData.callTiles[callDesc.tileIndex + t];
const LoadTile &loadTile = callTile.loadTile;
if (openCall) {
bool open = (openTileIndex == (callDesc.tileIndex + t));
bool open = ((uint32_t)openTileIndex == (callDesc.tileIndex + t));
ImGui::SetNextItemOpen(open);
if (open) {
ImGui::SetScrollHereY(0.0f);
Expand Down
3 changes: 2 additions & 1 deletion Source/3rdParty/rt64/src/gui/rt64_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ namespace RT64 {

# if defined(_WIN32) && !defined(RT64_BUILD_PLUGIN)
ImGui_ImplWin32_NewFrame();
# else
# elif defined(RT64_BUILD_PLUGIN)
// ????????
// if mupen64plus == true, dont assert....
ImGuiIO &io = ImGui::GetIO();
io.DisplaySize = ImVec2((float)window_width, (float)window_height);
# else
//assert(false && "Unimplemented.");
# endif

Expand Down
23 changes: 23 additions & 0 deletions Source/3rdParty/rt64/src/hle/rt64_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,29 @@ namespace RT64 {
return SetupResult::GraphicsDeviceNotFound;
}

// Driver workarounds.
//
// Wireframe artifacts have been reported when using a high-precision color format on RDNA3 GPUs in D3D12. The workaround is to switch to Vulkan if this is the case.
bool isRDNA3 = device->getDescription().name.find("AMD Radeon RX 7") != std::string::npos;
bool useHDRinD3D12 = (userConfig.graphicsAPI == UserConfiguration::GraphicsAPI::D3D12) && (userConfig.internalColorFormat == UserConfiguration::InternalColorFormat::Automatic) && device->getCapabilities().preferHDR;
if (isRDNA3 && useHDRinD3D12) {
device.reset();
renderInterface.reset();
renderInterface = CreateVulkanInterface();
if (renderInterface == nullptr) {
fprintf(stderr, "Unable to initialize graphics API.\n");
return SetupResult::GraphicsAPINotFound;
}

createdGraphicsAPI = UserConfiguration::GraphicsAPI::Vulkan;

device = renderInterface->createDevice();
if (device == nullptr) {
fprintf(stderr, "Unable to find compatible graphics device.\n");
return SetupResult::GraphicsDeviceNotFound;
}
}

// Call the init hook if one was attached.
RenderHookInit *initHook = GetRenderHookInit();
if (initHook != nullptr) {
Expand Down
11 changes: 9 additions & 2 deletions Source/3rdParty/rt64/src/hle/rt64_application_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,18 @@ namespace RT64 {
RRMode activeModeID = 0;
for (int i = 0; i < screenResources->ncrtc; ++i) {
XRRCrtcInfo *crtcInfo = XRRGetCrtcInfo(windowHandle.display, screenResources, screenResources->crtcs[i]);
if ((crtcInfo != nullptr) && (crtcInfo->mode != 0L)) {
activeModeID = crtcInfo->mode;
if (crtcInfo != nullptr) {
if (crtcInfo->mode != 0L) {
activeModeID = crtcInfo->mode;
}

XRRFreeCrtcInfo(crtcInfo);
}
}

if (activeModeID == 0L) {
fprintf(stderr, "Unable to find active mode through XRRGetScreenResources and XRRGetCrtcInfo.\n");
XRRFreeScreenResources(screenResources);
return;
}

Expand All @@ -302,6 +307,8 @@ namespace RT64 {
break;
}
}

XRRFreeScreenResources(screenResources);
# endif
}

Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/rt64/src/hle/rt64_light_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace RT64 {
hlslpp::float3 sunCol = { 0.8f, 0.7f, 0.6f };
float biggestIntensity = 0;
int biggestDirLight = -1;
for (int i = 0; i < directionalLights.size(); i++) {
for (size_t i = 0; i < directionalLights.size(); i++) {
if (directionalLights[i].intensityTotal > biggestIntensity) {
biggestDirLight = i;
biggestIntensity = directionalLights[i].intensityTotal;
Expand Down
10 changes: 5 additions & 5 deletions Source/3rdParty/rt64/src/hle/rt64_present_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace RT64 {
presentThread = new std::thread(&PresentQueue::threadLoop, this);
}

void PresentQueue::threadPresent(const Present &present) {
void PresentQueue::threadPresent(const Present &present, bool &swapChainValid) {
FramebufferManager &fbManager = ext.sharedResources->framebufferManager;
RenderTargetManager &targetManager = ext.sharedResources->renderTargetManager;
const bool usingMSAA = (targetManager.multisampling.sampleCount > 1);
Expand Down Expand Up @@ -264,7 +264,6 @@ namespace RT64 {
}
}

bool swapChainValid = true;
for (int32_t i = 0; i < framesToPresent; i++) {
uint32_t frameCountersNextPresented = 0;
if ((framesToPresent > 1) && (usingMSAA || (i > 0))) {
Expand Down Expand Up @@ -432,6 +431,7 @@ namespace RT64 {
bool skipPresent = false;
uint32_t displayTimingRate = UINT32_MAX;
const bool displayTiming = ext.device->getCapabilities().displayTiming;
bool swapChainValid = false;
while (presentThreadRunning) {
{
std::unique_lock<std::mutex> cursorLock(cursorMutex);
Expand All @@ -448,13 +448,13 @@ namespace RT64 {

if (processCursor >= 0) {
std::unique_lock<std::mutex> threadLock(threadMutex);
const bool needsResize = ext.swapChain->needsResize();
const bool needsResize = ext.swapChain->needsResize() || !swapChainValid;
if (needsResize) {
ext.presentGraphicsWorker->commandList->begin();
ext.presentGraphicsWorker->commandList->end();
ext.presentGraphicsWorker->execute();
ext.presentGraphicsWorker->wait();
ext.swapChain->resize();
swapChainValid = ext.swapChain->resize();
swapChainFramebuffers.clear();
ext.sharedResources->setSwapChainSize(ext.swapChain->getWidth(), ext.swapChain->getHeight());
}
Expand Down Expand Up @@ -490,7 +490,7 @@ namespace RT64 {
notifyPresentId(present);
}
else {
threadPresent(present);
threadPresent(present, swapChainValid);
}

if (!present.fbOperations.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/rt64/src/hle/rt64_present_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace RT64 {
void waitForIdle();
void waitForPresentId(uint64_t waitId);
void setup(const External &ext);
void threadPresent(const Present &present);
void threadPresent(const Present &present, bool &swapChainValid);
void skipInterpolation();
void notifyPresentId(const Present &present);
void threadAdvanceBarrier();
Expand Down
Loading

0 comments on commit 9899df4

Please sign in to comment.