Merge branch 'new-streams' of ssh+git://git.axiodl.com:6431/AxioDL/metaforce into new-streams

This commit is contained in:
Phillip Stephens 2022-02-21 23:00:09 -08:00
commit edf18d47d7
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
4 changed files with 46 additions and 17 deletions

View File

@ -21,6 +21,7 @@ add_library(aurora STATIC
lib/imgui.cpp
lib/input.cpp
lib/dawn/BackendBinding.cpp
lib/dawn/Hacks.cpp
lib/gfx/common.cpp
lib/gfx/texture.cpp
lib/gfx/movie_player/shader.cpp
@ -33,6 +34,10 @@ add_library(aurora STATIC
target_compile_definitions(aurora PRIVATE IMGUI_USER_CONFIG="imconfig_user.h") # IMGUI_USE_WCHAR32
target_include_directories(aurora PUBLIC include ../Runtime)
target_include_directories(aurora PRIVATE ../imgui ../extern/imgui)
target_include_directories(aurora PRIVATE
../extern/dawn/src
../extern/dawn/third_party/abseil-cpp
${CMAKE_CURRENT_BINARY_DIR}/dawn/gen/src) # for hacks :)
target_link_libraries(aurora PRIVATE dawn_native dawncpp webgpu_dawn zeus logvisor SDL2-static xxhash)
if (APPLE)
target_compile_definitions(aurora PRIVATE DAWN_ENABLE_BACKEND_METAL)

29
aurora/lib/dawn/Hacks.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "Hacks.hpp"
#include "dawn/native/Device.h"
#ifdef _WIN32
#include "dawn/native/d3d12/AdapterD3D12.h"
#include "dawn/native/d3d12/BackendD3D12.h"
#include "dawn/native/d3d12/DeviceD3D12.h"
#endif
namespace dawn::native {
class HackedDevice : public DeviceBase {
public:
void _ForceSetToggle(Toggle toggle, bool isEnabled) { ForceSetToggle(toggle, isEnabled); }
};
} // namespace dawn::native
namespace aurora::gpu::hacks {
void apply_toggles(WGPUDevice device) {
auto* hack = static_cast<dawn::native::HackedDevice*>(static_cast<void*>(device));
hack->_ForceSetToggle(dawn::native::Toggle::UseUserDefinedLabelsInBackend, true);
#if _WIN32
hack->_ForceSetToggle(dawn::native::Toggle::UseDXC, true);
auto* backend = dawn::native::d3d12::ToBackend(hack->GetAdapter())->GetBackend();
backend->EnsureDxcCompiler();
backend->EnsureDxcLibrary();
backend->EnsureDxcValidator();
#endif
}
} // namespace aurora::gpu::hacks

10
aurora/lib/dawn/Hacks.hpp Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include <dawn/webgpu.h>
/**
* Helpers to expose private Dawn APIs
*/
namespace aurora::gpu::hacks {
void apply_toggles(WGPUDevice device);
} // namespace aurora::gpu::hacks

View File

@ -8,18 +8,7 @@
#include <memory>
#include "dawn/BackendBinding.hpp"
// TODO this hack doesn't link on Windows?
#ifndef _WIN32
// TODO HACK: dawn doesn't expose device toggles
#include "../extern/dawn/src/dawn/native/Toggles.h"
namespace dawn::native {
class DeviceBase {
public:
void SetToggle(Toggle toggle, bool isEnabled);
};
} // namespace dawn::native
#endif
#include "dawn/Hacks.hpp"
namespace aurora::gpu {
static logvisor::Module Log("aurora::gpu");
@ -151,11 +140,7 @@ void initialize(SDL_Window* window) {
};
g_device = wgpu::Device::Acquire(g_Adapter.CreateDevice(&deviceDescriptor));
g_device.SetUncapturedErrorCallback(&error_callback, nullptr);
#ifndef _WIN32
// TODO HACK: dawn doesn't expose device toggles
static_cast<dawn::native::DeviceBase*>(static_cast<void*>(g_device.Get()))
->SetToggle(dawn::native::Toggle::UseUserDefinedLabelsInBackend, true);
#endif
hacks::apply_toggles(g_device.Get());
}
g_queue = g_device.GetQueue();