Restore graphicsApi, msaa, and textureAniso cvars, fix a few deserialization bugs in CVar.cpp

This commit is contained in:
Phillip Stephens 2022-06-08 10:58:38 -07:00
parent af1814d3c7
commit 46a93166ef
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
10 changed files with 137 additions and 32 deletions

View File

@ -568,7 +568,9 @@ int main(int argc, char** argv) {
.width = icon.width,
.height = icon.height,
};
aurora::app_run(std::move(app), std::move(data), argc, argv, fileMgr.getStoreRoot());
aurora::app_run(std::move(app), std::move(data), argc, argv, fileMgr.getStoreRoot(),
aurora::translate_backend(cvarCmns.getGraphicsApi()), cvarCmns.getSamples(),
cvarCmns.getAnisotropy());
return 0;
}
#endif

View File

@ -434,7 +434,7 @@ void CVar::dispatch() {
bool isReal(std::string_view v) {
char* p;
std::strtod(v.data(), &p);
return *p == 0;
return p != nullptr && *p == 0;
}
bool isReal(const std::vector<std::string>& v) {
for (auto& s : v) {
@ -455,10 +455,10 @@ bool CVar::isValidInput(std::string_view input) const {
}
case EType::Signed:
std::strtol(input.data(), &p, 0);
return p == nullptr;
return p != nullptr && *p == 0;
case EType::Unsigned:
std::strtoul(input.data(), &p, 0);
return p == nullptr;
return p != nullptr && *p == 0;
case EType::Real: {
bool size = parts.size() == 1;
bool ret = isReal(input);

View File

@ -751,7 +751,20 @@ IMGUI_ENTITY_INSPECT(MP1::CBouncyGrenade, CPhysicsActor, BouncyGrenade, {})
IMGUI_ENTITY_INSPECT(CCollisionActor, CPhysicsActor, CollisionActor, {})
IMGUI_ENTITY_INSPECT(MP1::CGrenadeLauncher, CPhysicsActor, GrenadeLauncher, {})
IMGUI_ENTITY_INSPECT(MP1::CMetroidPrimeExo::CPhysicsDummy, CPhysicsActor, MetroidPrimeExoPhysicsDummy, {})
IMGUI_ENTITY_INSPECT(CPlayer, CPhysicsActor, Player, {})
IMGUI_ENTITY_INSPECT(CPlayer, CPhysicsActor, Player, {
if (ImGui::CollapsingHeader("Player Gun")) {
auto* gun = GetPlayerGun();
ImGui::Text("Last Fire Button States: 0x%08X", gun->x2ec_lastFireButtonStates);
ImGui::Text("Pressed Fire Button States: 0x%08X", gun->x2f0_pressedFireButtonStates);
ImGui::Text("Fire Button States: 0x%08X", gun->x2f4_fireButtonStates);
ImGui::Text("State Flags: 0x%08X", gun->x2f8_stateFlags);
ImGui::Text("Fidget Anim Bits: 0x%08X", gun->x2fc_fidgetAnimBits);
ImGui::Text("Remaining Missiles: %i", gun->x300_remainingMissiles);
ImGui::Text("Bomb Count: %i", gun->x308_bombCount);
ImGui::Text("Current Beam: %s", magic_enum::enum_name(gun->x310_currentBeam).data());
ImGui::Text("Next Beam: %s", magic_enum::enum_name(gun->x314_nextBeam).data());
}
})
IMGUI_ENTITY_INSPECT(CScriptActor, CPhysicsActor, ScriptActor, {
if (ImGui::Button("Edit Damage Vulnerability")) {
m_editingDamageVulnerability = true;

View File

@ -31,6 +31,8 @@ namespace metaforce {
struct CFinalInput;
class CPlayerGun {
// For ImGuiEntitySupport
friend class CPlayer;
public:
static float skTractorBeamFactor;
enum class EMissileMode { Inactive, Active };

View File

@ -36,7 +36,7 @@ if (DAWN_ENABLE_D3D12)
target_sources(aurora PRIVATE lib/dawn/D3D12Binding.cpp)
endif ()
if (DAWN_ENABLE_DESKTOP_GL)
target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_OPENGL DAWN_ENABLE_BACKEND_DESKTOP_GL)
target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_OPENGL DAWN_ENABLE_BACKEND_DESKTOP_GL DAWN_ENABLE_BACKEND_OPENGLES)
target_sources(aurora PRIVATE lib/dawn/OpenGLBinding.cpp)
endif ()
if (DAWN_ENABLE_NULL)

View File

@ -191,17 +191,17 @@ enum class MouseButton {
ENABLE_BITWISE_ENUM(MouseButton);
enum class Backend : uint8_t {
Invalid,
Vulkan,
Metal,
D3D12,
Null,
WebGPU,
D3D11,
D3D12,
Metal,
Vulkan,
OpenGL,
OpenGLES,
WebGPU,
Invalid = 0xFF,
};
struct App;
struct AppDelegate {
AppDelegate() = default;
virtual ~AppDelegate() noexcept = default;
@ -242,12 +242,14 @@ struct AppDelegate {
virtual void onControllerAxis(uint32_t which, ControllerAxis axis, int16_t value) noexcept = 0;
};
void app_run(std::unique_ptr<AppDelegate> app, Icon icon, int argc, char** argv, std::string_view configPath) noexcept;
void app_run(std::unique_ptr<AppDelegate> app, Icon icon, int argc, char** argv, std::string_view configPath,
Backend desiredBackend = Backend::Invalid, uint32_t msaa = 1, uint16_t aniso = 16) noexcept;
[[nodiscard]] std::vector<std::string> get_args() noexcept;
[[nodiscard]] WindowSize get_window_size() noexcept;
void set_window_title(zstring_view title) noexcept;
[[nodiscard]] Backend get_backend() noexcept;
[[nodiscard]] std::string_view get_backend_string() noexcept;
[[nodiscard]] Backend translate_backend(std::string_view name);
void set_fullscreen(bool fullscreen) noexcept;
[[nodiscard]] uint32_t get_which_controller_for_player(int32_t index) noexcept;
[[nodiscard]] int32_t get_controller_player_index(uint32_t which) noexcept;

View File

@ -1,10 +1,12 @@
#include <aurora/aurora.hpp>
#include "gfx/common.hpp"
#include "gfx/gx.hpp"
#include "gpu.hpp"
#include "input.hpp"
#include "imgui.hpp"
#include <algorithm>
#include <SDL.h>
#include <imgui.h>
#include <logvisor/logvisor.hpp>
@ -253,7 +255,29 @@ static SDL_Window* create_window(wgpu::BackendType type) {
return SDL_CreateWindow("Metaforce", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 960, flags);
}
void app_run(std::unique_ptr<AppDelegate> app, Icon icon, int argc, char** argv, std::string_view configPath) noexcept {
wgpu::BackendType to_wgpu_backend(Backend backend) {
switch (backend) {
case Backend::WebGPU:
return wgpu::BackendType::WebGPU;
case Backend::D3D11:
return wgpu::BackendType::D3D11;
case Backend::D3D12:
return wgpu::BackendType::D3D12;
case Backend::Metal:
return wgpu::BackendType::Metal;
case Backend::Vulkan:
return wgpu::BackendType::Vulkan;
case Backend::OpenGL:
return wgpu::BackendType::OpenGL;
case Backend::OpenGLES:
return wgpu::BackendType::OpenGLES;
default:
case Backend::Null:
return wgpu::BackendType::Null;
}
}
void app_run(std::unique_ptr<AppDelegate> app, Icon icon, int argc, char** argv, std::string_view configPath,
Backend desiredBackend, uint32_t msaa, uint16_t aniso) noexcept {
g_AppDelegate = std::move(app);
/* Lets gather arguments skipping the program filename */
for (size_t i = 1; i < argc; ++i) {
@ -280,18 +304,31 @@ void app_run(std::unique_ptr<AppDelegate> app, Icon icon, int argc, char** argv,
/* TODO: Make this an option rather than hard coding it */
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
for (const auto backendType : gpu::PreferredBackendOrder) {
auto* window = create_window(backendType);
if (window == nullptr) {
continue;
/* Attempt to create a window using the calling application's desired backend */
if (desiredBackend != Backend::Invalid) {
auto wgpuBackend = to_wgpu_backend(desiredBackend);
g_window = create_window(wgpuBackend);
if (g_window != nullptr && !gpu::initialize(g_window, wgpuBackend, msaa, aniso)) {
g_window = nullptr;
SDL_DestroyWindow(g_window);
}
g_window = window;
if (gpu::initialize(window, backendType)) {
break;
}
g_window = nullptr;
SDL_DestroyWindow(window);
}
if (g_window == nullptr) {
for (const auto backendType : gpu::PreferredBackendOrder) {
auto* window = create_window(backendType);
if (window == nullptr) {
continue;
}
g_window = window;
if (gpu::initialize(window, backendType, msaa, aniso)) {
break;
}
g_window = nullptr;
SDL_DestroyWindow(window);
}
}
if (g_window == nullptr) {
Log.report(logvisor::Fatal, FMT_STRING("Error creating window: {}"), SDL_GetError());
unreachable();
@ -438,6 +475,55 @@ Backend get_backend() noexcept {
std::string_view get_backend_string() noexcept { return magic_enum::enum_name(gpu::g_backendType); }
Backend translate_backend(std::string_view backend) {
if (backend.empty()) {
return Backend::Invalid;
}
std::string tmp = backend.data();
std::transform(tmp.begin(), tmp.end(), tmp.begin(), [](unsigned char c) { return std::tolower(c); });
#if DAWN_ENABLE_BACKEND_WEBGPU
if (tmp == "webgpu" || tmp == "wgpu") {
return Backend::WebGPU;
}
#endif
#if DAWN_ENABLE_BACKEND_D3D11
if (tmp == "d3d11") {
return Backend::D3D11;
}
#endif
#if DAWN_ENABLE_BACKEND_D3D12
if (tmp == "d3d12") {
return Backend::D3D12;
}
#endif
#if DAWN_ENABLE_BACKEND_METAL
if (tmp == "metal") {
return Backend::Metal;
}
#endif
#if DAWN_ENABLE_BACKEND_DESKTOP_GL || DAWN_ENABLE_BACKEND_OPENGL
if (tmp == "gl" || tmp == "opengl") {
return Backend::OpenGL;
}
#endif
#if DAWN_ENABLE_BACKEND_OPENGLES
if (tmp == "gles" || tmp == "opengles") {
return Backend::OpenGLES;
}
#endif
#if DAWN_ENABLE_BACKEND_VULKAN
if (tmp == "vulkan") {
return Backend::Vulkan;
}
#endif
#if DAWN_ENABLE_BACKEND_NULL
if (tmp == "null") {
return Backend::Null;
}
#endif
return Backend::Invalid;
}
void set_fullscreen(bool fullscreen) noexcept {
SDL_SetWindowFullscreen(g_window, fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
}

View File

@ -313,7 +313,8 @@ static void pipeline_worker() {
void initialize() {
// No async pipelines for OpenGL (ES)
if (gpu::g_backendType != wgpu::BackendType::OpenGL && gpu::g_backendType != wgpu::BackendType::OpenGLES) {
if (gpu::g_backendType != wgpu::BackendType::OpenGL && gpu::g_backendType != wgpu::BackendType::OpenGLES &&
gpu::g_backendType != wgpu::BackendType::Vulkan) {
g_pipelineThread = std::thread(pipeline_worker);
g_hasPipelineThread = true;
}
@ -758,9 +759,7 @@ const wgpu::Sampler& sampler_ref(const wgpu::SamplerDescriptor& descriptor) {
return it->second;
}
uint32_t align_uniform(uint32_t value) {
return ALIGN(value, g_cachedLimits.limits.minUniformBufferOffsetAlignment);
}
uint32_t align_uniform(uint32_t value) { return ALIGN(value, g_cachedLimits.limits.minUniformBufferOffsetAlignment); }
void push_debug_group(zstring_view label) noexcept {
#ifdef AURORA_GFX_DEBUG_GROUPS

View File

@ -240,7 +240,7 @@ static void device_callback(WGPURequestDeviceStatus status, WGPUDevice device, c
*static_cast<bool*>(userdata) = true;
}
bool initialize(SDL_Window* window, wgpu::BackendType backendType) {
bool initialize(SDL_Window* window, wgpu::BackendType backendType, uint32_t msaa, uint16_t aniso) {
if (!g_Instance) {
Log.report(logvisor::Info, FMT_STRING("Creating Dawn instance"));
g_Instance = std::make_unique<dawn::native::Instance>();
@ -343,6 +343,7 @@ bool initialize(SDL_Window* window, wgpu::BackendType backendType) {
}
g_device.SetUncapturedErrorCallback(&error_callback, nullptr);
}
g_device.SetDeviceLostCallback(nullptr, nullptr);
g_queue = g_device.GetQueue();
g_BackendBinding =
@ -372,8 +373,8 @@ bool initialize(SDL_Window* window, wgpu::BackendType backendType) {
.height = size.fb_height,
.colorFormat = swapChainFormat,
.depthFormat = wgpu::TextureFormat::Depth32Float,
.msaaSamples = 1,
.textureAnisotropy = 16,
.msaaSamples = msaa,
.textureAnisotropy = aniso,
};
create_copy_pipeline();
resize_swapchain(size.fb_width, size.fb_height);

View File

@ -63,7 +63,7 @@ extern TextureWithSampler g_depthBuffer;
extern wgpu::RenderPipeline g_CopyPipeline;
extern wgpu::BindGroup g_CopyBindGroup;
bool initialize(SDL_Window* window, wgpu::BackendType backendType);
bool initialize(SDL_Window* window, wgpu::BackendType backendType, uint32_t msaa, uint16_t aniso);
void shutdown();
void resize_swapchain(uint32_t width, uint32_t height);
TextureWithSampler create_render_texture(bool multisampled);