Windows fixes & memory fixes

This commit is contained in:
Luke Street 2022-03-08 18:35:40 -05:00
parent 3fd0b1f23a
commit c7f05d0a59
16 changed files with 74 additions and 22 deletions

View File

@ -112,6 +112,7 @@ void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo, float alpha
SCOPED_GRAPHICS_DEBUG_GROUP("CMappableObject::Draw", zeus::skCyan); SCOPED_GRAPHICS_DEBUG_GROUP("CMappableObject::Draw", zeus::skCyan);
if (IsDoorType(x0_type)) { if (IsDoorType(x0_type)) {
std::pair<zeus::CColor, zeus::CColor> colors = GetDoorColors(curArea, mwInfo, alpha); std::pair<zeus::CColor, zeus::CColor> colors = GetDoorColors(curArea, mwInfo, alpha);
if (m_doorSurface) // TODO
for (int s = 0; s < 6; ++s) { for (int s = 0; s < 6; ++s) {
DoorSurface& ds = *m_doorSurface; DoorSurface& ds = *m_doorSurface;
ds.m_surface.draw(colors.first, s * 4, 4); ds.m_surface.draw(colors.first, s * 4, 4);

View File

@ -12,6 +12,14 @@
#include <memory> #include <memory>
#include <regex> #include <regex>
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
#endif
#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
#endif
namespace metaforce { namespace metaforce {
CVar* com_developer = nullptr; CVar* com_developer = nullptr;
@ -165,7 +173,13 @@ void CVarManager::serialize() {
textOut.WriteString(str); textOut.WriteString(str);
} }
auto* file = fopen(filename.c_str(), "wbe"); auto* file = fopen(filename.c_str(),
#ifdef _MSC_VER
"wb"
#else
"wbe"
#endif
);
if (file != nullptr) { if (file != nullptr) {
u32 writeLen = memOut.GetWritePosition(); u32 writeLen = memOut.GetWritePosition();
u32 offset = 0; u32 offset = 0;
@ -182,7 +196,13 @@ std::vector<StoreCVar::CVar> CVarManager::loadCVars(const std::string& filename)
CBasics::Sstat st; CBasics::Sstat st;
if (CBasics::Stat(filename.c_str(), &st) == 0 && S_ISREG(st.st_mode)) { if (CBasics::Stat(filename.c_str(), &st) == 0 && S_ISREG(st.st_mode)) {
auto* file = fopen(filename.c_str(), "rbe"); auto* file = fopen(filename.c_str(),
#ifdef _MSC_VER
"rb"
#else
"rbe"
#endif
);
if (file != nullptr) { if (file != nullptr) {
std::unique_ptr<u8[]> inBuf(new u8[st.st_size]); std::unique_ptr<u8[]> inBuf(new u8[st.st_size]);

View File

@ -593,7 +593,9 @@ void CCubeRenderer::EndScene() {
void CCubeRenderer::SetDebugOption(IRenderer::EDebugOption option, s32 value) { void CCubeRenderer::SetDebugOption(IRenderer::EDebugOption option, s32 value) {
if (option == EDebugOption::PVSState) { if (option == EDebugOption::PVSState) {
xc8_pvs->SetState(EPVSVisSetState(value)); if (xc8_pvs) {
xc8_pvs->SetState(EPVSVisSetState(value));
}
} else if (option == EDebugOption::PVSMode) { } else if (option == EDebugOption::PVSMode) {
xc0_pvsMode = EPVSMode(value); xc0_pvsMode = EPVSMode(value);
} else if (option == EDebugOption::FogDisabled) { } else if (option == EDebugOption::FogDisabled) {

View File

@ -6,11 +6,11 @@
#include "CToken.hpp" #include "CToken.hpp"
#include "GCNTypes.hpp" #include "GCNTypes.hpp"
#include "Graphics/CCubeModel.hpp" #include "Graphics/CCubeModel.hpp"
#include "Graphics/CCubeSurface.hpp"
#include "Graphics/CTexture.hpp" #include "Graphics/CTexture.hpp"
#include "IObjectStore.hpp" #include "IObjectStore.hpp"
namespace metaforce { namespace metaforce {
class CCubeSurface;
class CCubeMaterial; class CCubeMaterial;
enum class CModelFlagBits : u16 { enum class CModelFlagBits : u16 {

View File

@ -25,7 +25,7 @@ public:
void Execute(ERglTevStage stage) const; void Execute(ERglTevStage stage) const;
bool operator<=>(const CTevPass&) const = default; auto operator<=>(const CTevPass&) const = default;
}; };
extern const CTevPass skPassThru; extern const CTevPass skPassThru;

View File

@ -342,7 +342,7 @@ void CTexture::InvalidateTexMap(GX::TexMapID id) {
CFactoryFnReturn FTextureFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CFactoryFnReturn FTextureFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
CObjectReference* selfRef) { CObjectReference* selfRef) {
const auto label = fmt::format("{} {}", tag.type, tag.id); const auto label = fmt::format(FMT_STRING("{} {}"), tag.type, tag.id);
return TToken<CTexture>::GetIObjObjectFor(std::make_unique<CTexture>(in, label)); return TToken<CTexture>::GetIObjObjectFor(std::make_unique<CTexture>(in, label));
} }
} // namespace metaforce } // namespace metaforce

View File

@ -5,6 +5,7 @@
#include "Runtime/CToken.hpp" #include "Runtime/CToken.hpp"
#include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CGraphics.hpp"
#include "Runtime/Graphics/CModel.hpp"
#include "Runtime/RetroTypes.hpp" #include "Runtime/RetroTypes.hpp"
#include <zeus/CAABox.hpp> #include <zeus/CAABox.hpp>
@ -17,7 +18,6 @@ namespace metaforce {
class CAreaOctTree; class CAreaOctTree;
class CLight; class CLight;
class CMetroidModelInstance; class CMetroidModelInstance;
class CModel;
class CPVSVisSet; class CPVSVisSet;
class CParticleGen; class CParticleGen;
class CSkinnedModel; class CSkinnedModel;

View File

@ -704,6 +704,7 @@ void CMain::ShutdownSubsystems() {
// Metaforce additions // Metaforce additions
CMoviePlayer::Shutdown(); CMoviePlayer::Shutdown();
CFont::Shutdown(); CFont::Shutdown();
CFluidPlaneManager::Shutdown();
} }
void CMain::Shutdown() { void CMain::Shutdown() {

View File

@ -140,4 +140,8 @@ void CFluidPlaneManager::SetupRippleMap() {
"Ripple Map"); "Ripple Map");
} }
void CFluidPlaneManager::Shutdown() {
RippleMapTex.reset();
}
} // namespace metaforce } // namespace metaforce

View File

@ -60,6 +60,8 @@ public:
rstl::reserved_vector<CSplashRecord, 32>& SplashRecords() { return x18_splashes; } rstl::reserved_vector<CSplashRecord, 32>& SplashRecords() { return x18_splashes; }
const CRippleManager& GetRippleManager() const { return x0_rippleManager; } const CRippleManager& GetRippleManager() const { return x0_rippleManager; }
CRippleManager& RippleManager() { return x0_rippleManager; } CRippleManager& RippleManager() { return x0_rippleManager; }
static void Shutdown();
}; };
} // namespace metaforce } // namespace metaforce

View File

@ -178,7 +178,7 @@ struct WindowSize {
uint32_t fb_height; uint32_t fb_height;
float scale; float scale;
bool operator<=>(const WindowSize& rhs) const = default; auto operator<=>(const WindowSize& rhs) const = default;
}; };
enum class MouseButton { enum class MouseButton {
None = 0, None = 0,

View File

@ -161,7 +161,7 @@ struct CTevOp {
, xc_scale(static_cast<GX::TevScale>(compressedDesc >> 6 & 3)) , xc_scale(static_cast<GX::TevScale>(compressedDesc >> 6 & 3))
, x10_regId(static_cast<GX::TevRegID>(compressedDesc >> 9 & 3)) {} , x10_regId(static_cast<GX::TevRegID>(compressedDesc >> 9 & 3)) {}
bool operator<=>(const CTevOp&) const = default; auto operator<=>(const CTevOp&) const = default;
}; };
struct ColorPass { struct ColorPass {
GX::TevColorArg x0_a; GX::TevColorArg x0_a;
@ -177,7 +177,7 @@ struct ColorPass {
, x8_c(static_cast<GX::TevColorArg>(compressedDesc >> 10 & 0x1F)) , x8_c(static_cast<GX::TevColorArg>(compressedDesc >> 10 & 0x1F))
, xc_d(static_cast<GX::TevColorArg>(compressedDesc >> 15 & 0x1F)) {} , xc_d(static_cast<GX::TevColorArg>(compressedDesc >> 15 & 0x1F)) {}
bool operator<=>(const ColorPass&) const = default; auto operator<=>(const ColorPass&) const = default;
}; };
struct AlphaPass { struct AlphaPass {
GX::TevAlphaArg x0_a; GX::TevAlphaArg x0_a;
@ -193,7 +193,7 @@ struct AlphaPass {
, x8_c(static_cast<GX::TevAlphaArg>(compressedDesc >> 10 & 0x1F)) , x8_c(static_cast<GX::TevAlphaArg>(compressedDesc >> 10 & 0x1F))
, xc_d(static_cast<GX::TevAlphaArg>(compressedDesc >> 15 & 0x1F)) {} , xc_d(static_cast<GX::TevAlphaArg>(compressedDesc >> 15 & 0x1F)) {}
bool operator<=>(const AlphaPass&) const = default; auto operator<=>(const AlphaPass&) const = default;
}; };
} // namespace CTevCombiners } // namespace CTevCombiners
} // namespace metaforce } // namespace metaforce

View File

@ -19,7 +19,7 @@ static std::vector<std::string> g_Args;
// SDL // SDL
static SDL_Window* g_window; static SDL_Window* g_window;
static WindowSize g_windowSize; WindowSize g_windowSize;
// GPU // GPU
using gpu::g_depthBuffer; using gpu::g_depthBuffer;

View File

@ -129,8 +129,17 @@ void set_chan_mat_src(GX::ChannelID id, GX::ColorSrc src) noexcept {
gx::g_colorChannels[id - GX::COLOR0A0].matSrc = src; gx::g_colorChannels[id - GX::COLOR0A0].matSrc = src;
} }
void load_light(GX::LightID id, const Light& light) noexcept { gx::g_lights[id] = light; } static inline u8 light_idx(GX::LightID id) {
void load_light_ambient(GX::LightID id, const zeus::CColor& ambient) noexcept { gx::g_lights[id] = ambient; } #ifdef _MSC_VER
unsigned long r = 0;
_BitScanForward(&r, id);
return r;
#else
return __builtin_ctz(id);
#endif
}
void load_light(GX::LightID id, const Light& light) noexcept { gx::g_lights[light_idx(id)] = light; }
void load_light_ambient(GX::LightID id, const zeus::CColor& ambient) noexcept { gx::g_lights[light_idx(id)] = ambient; }
void set_light_state(std::bitset<MaxLights> bits) noexcept { gx::g_lightState = bits; } void set_light_state(std::bitset<MaxLights> bits) noexcept { gx::g_lightState = bits; }
namespace gx { namespace gx {
@ -187,6 +196,9 @@ static inline wgpu::BlendFactor to_blend_factor(metaforce::ERglBlendFactor fac)
return wgpu::BlendFactor::Dst; return wgpu::BlendFactor::Dst;
case metaforce::ERglBlendFactor::InvDstColor: case metaforce::ERglBlendFactor::InvDstColor:
return wgpu::BlendFactor::OneMinusDst; return wgpu::BlendFactor::OneMinusDst;
default:
Log.report(logvisor::Fatal, FMT_STRING("invalid blend factor {}"), fac);
unreachable();
} }
} }
@ -208,6 +220,9 @@ static inline wgpu::CompareFunction to_compare_function(metaforce::ERglEnum func
return wgpu::CompareFunction::GreaterEqual; return wgpu::CompareFunction::GreaterEqual;
case metaforce::ERglEnum::Always: case metaforce::ERglEnum::Always:
return wgpu::CompareFunction::Always; return wgpu::CompareFunction::Always;
default:
Log.report(logvisor::Fatal, FMT_STRING("invalid depth fn {}"), func);
unreachable();
} }
} }
@ -328,7 +343,8 @@ wgpu::RenderPipeline build_pipeline(const PipelineConfig& config, const ShaderIn
return g_device.CreateRenderPipeline(&descriptor); return g_device.CreateRenderPipeline(&descriptor);
} }
ShaderInfo populate_pipeline_config(PipelineConfig& config, GX::Primitive primitive, const BindGroupRanges& ranges) noexcept { ShaderInfo populate_pipeline_config(PipelineConfig& config, GX::Primitive primitive,
const BindGroupRanges& ranges) noexcept {
for (size_t idx = 0; const auto& item : g_tevStages) { for (size_t idx = 0; const auto& item : g_tevStages) {
// Copy until disabled TEV stage (indicating end) // Copy until disabled TEV stage (indicating end)
if (!item) { if (!item) {

View File

@ -116,7 +116,7 @@ void queue_surface(const u8* dlStart, u32 dlSize) noexcept {
std::vector<u32> indices; std::vector<u32> indices;
size_t offset = 0; size_t offset = 0;
while (offset < dlSize) { while (offset < dlSize - 6) {
const auto header = dlStart[offset]; const auto header = dlStart[offset];
const auto primitive = static_cast<GX::Primitive>(header & 0xF8); const auto primitive = static_cast<GX::Primitive>(header & 0xF8);
const auto vtxFmt = static_cast<VertexFormat>(header & 0x3); const auto vtxFmt = static_cast<VertexFormat>(header & 0x3);

View File

@ -1,5 +1,7 @@
#include "gpu.hpp" #include "gpu.hpp"
#include <aurora/aurora.hpp>
#include <SDL.h> #include <SDL.h>
#include <dawn/native/DawnNative.h> #include <dawn/native/DawnNative.h>
#include <dawn/webgpu_cpp.h> #include <dawn/webgpu_cpp.h>
@ -9,6 +11,11 @@
#include "dawn/BackendBinding.hpp" #include "dawn/BackendBinding.hpp"
// FIXME hack to avoid crash on Windows
namespace aurora {
extern WindowSize g_windowSize;
} // namespace aurora
namespace aurora::gpu { namespace aurora::gpu {
static logvisor::Module Log("aurora::gpu"); static logvisor::Module Log("aurora::gpu");
@ -192,18 +199,17 @@ void initialize(SDL_Window* window) {
g_swapChain = g_device.CreateSwapChain(nullptr, &descriptor); g_swapChain = g_device.CreateSwapChain(nullptr, &descriptor);
} }
{ {
int width = 0; const auto size = get_window_size();
int height = 0;
SDL_GL_GetDrawableSize(window, &width, &height);
g_graphicsConfig = GraphicsConfig{ g_graphicsConfig = GraphicsConfig{
.width = static_cast<uint32_t>(width), .width = size.fb_width,
.height = static_cast<uint32_t>(height), .height = size.fb_height,
.colorFormat = swapChainFormat, .colorFormat = swapChainFormat,
.depthFormat = wgpu::TextureFormat::Depth32Float, .depthFormat = wgpu::TextureFormat::Depth32Float,
.msaaSamples = 1, // TODO 4 .msaaSamples = 1, // TODO 4
.textureAnistropy = 16, .textureAnistropy = 16,
}; };
resize_swapchain(width, height); resize_swapchain(size.fb_width, size.fb_height);
g_windowSize = size;
} }
} }