This commit is contained in:
1 parent
2cff35f215
commit
8dcee1bb46
355 files changed
+253629
-1
No files matched your search
@@ -0,0 +1,212 @@
|
||||
|
||||
|
||||
use std::ffi::c_void;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
use eonacat_xsbox_gpu::device;
|
||||
use eonacat_xsbox_gpu::object::{HRESULT, Iid, Object, guid};
|
||||
|
||||
use crate::hle::{HleExport, HleModule};
|
||||
|
||||
fn prepare_device() {
|
||||
eonacat_xsbox_gpu::resource::use_allocator(super::xmem::XMemAlloc, super::xmem::XMemFree);
|
||||
eonacat_xsbox_gpu::resource::use_page_mapper(super::xmem::map_alias);
|
||||
eonacat_xsbox_gpu::resource::use_many_page_mapper(super::xmem::map_aliases);
|
||||
#[cfg(windows)]
|
||||
eonacat_xsbox_gpu::on_failure(host_gpu_failed);
|
||||
}
|
||||
|
||||
extern "system" fn create_device(
|
||||
adapter: *const c_void,
|
||||
parameters: *const u32,
|
||||
iid: *const Iid,
|
||||
out: *mut *const Object,
|
||||
) -> HRESULT {
|
||||
prepare_device();
|
||||
device::create(adapter, parameters, iid, out)
|
||||
}
|
||||
|
||||
extern "system" fn create_device_with_level(
|
||||
adapter: *const c_void,
|
||||
minimum: u32,
|
||||
iid: *const Iid,
|
||||
out: *mut *const Object,
|
||||
) -> HRESULT {
|
||||
prepare_device();
|
||||
device::create_with_level(adapter, minimum, iid, out)
|
||||
}
|
||||
|
||||
const E_NOINTERFACE: HRESULT = 0x8000_4002_u32 as i32;
|
||||
const S_OK: HRESULT = 0;
|
||||
|
||||
extern "system" fn get_debug_interface(iid: *const Iid, out: *mut *mut c_void) -> HRESULT {
|
||||
if !out.is_null() {
|
||||
|
||||
unsafe { out.write(std::ptr::null_mut()) };
|
||||
}
|
||||
|
||||
let iid = unsafe { iid.as_ref() }.map(eonacat_xsbox_gpu::object::guid_text);
|
||||
tracing::info!(?iid, "D3D12GetDebugInterface: no debug layer");
|
||||
E_NOINTERFACE
|
||||
}
|
||||
|
||||
static DEBUG_FLAGS: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
extern "system" fn set_process_debug_flags(flags: u32) -> HRESULT {
|
||||
DEBUG_FLAGS.store(flags, Ordering::Relaxed);
|
||||
if flags != 0 {
|
||||
tracing::warn!(
|
||||
flags = format_args!("{flags:#x}"),
|
||||
"D3D12 process debug flags kept but not acted on (no debug layer)"
|
||||
);
|
||||
}
|
||||
S_OK
|
||||
}
|
||||
|
||||
extern "system" fn get_process_debug_flags() -> u32 {
|
||||
DEBUG_FLAGS.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
extern "system" fn unload_driver_module() {}
|
||||
|
||||
extern "system" fn flush_entire_cpu_cache() {
|
||||
std::sync::atomic::fence(Ordering::SeqCst);
|
||||
}
|
||||
|
||||
static DATA_IDS: [(&str, Iid); 31] = [
|
||||
("IID_ID3D12CommandAllocator", guid(0x6102dee4, 0xaf59, 0x4b09, [0xb9, 0x99, 0xb4, 0x4d, 0x73, 0xf0, 0x9b, 0x24])),
|
||||
("IID_ID3D12CommandList", guid(0x7116d91c, 0xe7e4, 0x47ce, [0xb8, 0xc6, 0xec, 0x81, 0x68, 0xf4, 0x37, 0xe5])),
|
||||
("IID_ID3D12CommandQueue", guid(0x0ec870a6, 0x5d7e, 0x4c22, [0x8c, 0xfc, 0x5b, 0xaa, 0xe0, 0x76, 0x16, 0xed])),
|
||||
("IID_ID3D12Debug", guid(0x344488b7, 0x6846, 0x474b, [0xb9, 0x89, 0xf0, 0x27, 0x44, 0x82, 0x45, 0xe0])),
|
||||
("IID_ID3D12DescriptorHeap", guid(0x8efb471d, 0x616c, 0x4f49, [0x90, 0xf7, 0x12, 0x7b, 0xb7, 0x63, 0xfa, 0x51])),
|
||||
("IID_ID3D12DeviceChild", guid(0x905db94b, 0xa00c, 0x4140, [0x9d, 0xf5, 0x2b, 0x64, 0xca, 0x9e, 0xa3, 0x57])),
|
||||
("IID_ID3D12Fence", guid(0x0a753dcf, 0xc4d8, 0x4b91, [0xad, 0xf6, 0xbe, 0x5a, 0x60, 0xd9, 0x5a, 0x76])),
|
||||
("IID_ID3D12GraphicsCommandList", guid(0x5b160d0f, 0xac1b, 0x4185, [0x8b, 0xa8, 0xb3, 0xae, 0x42, 0xa5, 0xa4, 0x55])),
|
||||
("IID_ID3D12Heap", guid(0x6b3b2502, 0x6e51, 0x45b3, [0x90, 0xee, 0x98, 0x84, 0x26, 0x5e, 0x8d, 0xf3])),
|
||||
("IID_ID3D12Object", guid(0xc4fec28f, 0x7966, 0x4e95, [0x9f, 0x94, 0xf4, 0x31, 0xcb, 0x56, 0xc3, 0xb8])),
|
||||
("IID_ID3D12Pageable", guid(0x63ee58fb, 0x1268, 0x4835, [0x86, 0xda, 0xf0, 0x08, 0xce, 0x62, 0xf0, 0xd6])),
|
||||
("IID_ID3D12PipelineState", guid(0x765a30f3, 0xf624, 0x4c6f, [0xa8, 0x28, 0xac, 0xe9, 0x48, 0x62, 0x24, 0x45])),
|
||||
("IID_ID3D12Resource", guid(0x696442be, 0xa72e, 0x4059, [0xbc, 0x79, 0x5b, 0x5c, 0x98, 0x04, 0x0f, 0xad])),
|
||||
("IID_ID3D12RootSignature", guid(0xc54a6b66, 0x72df, 0x4ee8, [0x8b, 0xe5, 0xa9, 0x46, 0xa1, 0x42, 0x92, 0x14])),
|
||||
("IID_ID3D12RootSignatureDeserializer", guid(0x34ab647b, 0x3cc8, 0x46ac, [0x84, 0x1b, 0xc0, 0x96, 0x56, 0x45, 0xc0, 0x46])),
|
||||
("IID_ID3D12XboxDmaCommandList", guid(0x30bc77b9, 0x8379, 0x4b25, [0x95, 0xde, 0xb8, 0x58, 0x8c, 0x42, 0x27, 0x5d])),
|
||||
("IID_IDXGIAdapter", guid(0x2411e7e1, 0x12ac, 0x4ccf, [0xbd, 0x14, 0x97, 0x98, 0xe8, 0x53, 0x4d, 0xc0])),
|
||||
("IID_IDXGIAdapter1", guid(0x29038f61, 0x3839, 0x4626, [0x91, 0xfd, 0x08, 0x68, 0x79, 0x01, 0x1a, 0x05])),
|
||||
("IID_IDXGIAdapter2", guid(0x0aa1ae0a, 0xfa0e, 0x4b84, [0x86, 0x44, 0xe0, 0x5f, 0xf8, 0xe5, 0xac, 0xb5])),
|
||||
("IID_IDXGIDevice", guid(0x54ec77fa, 0x1377, 0x44e6, [0x8c, 0x32, 0x88, 0xfd, 0x5f, 0x44, 0xc8, 0x4c])),
|
||||
("IID_IDXGIDevice1", guid(0x77db970f, 0x6276, 0x48ba, [0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c])),
|
||||
("IID_IDXGIDevice2", guid(0x05008617, 0xfbfd, 0x4051, [0xa7, 0x90, 0x14, 0x48, 0x84, 0xb4, 0xf6, 0xa9])),
|
||||
("IID_IDXGIDeviceSubObject", guid(0x3d3e0379, 0xf9de, 0x4d58, [0xbb, 0x6c, 0x18, 0xd6, 0x29, 0x92, 0xf1, 0xa6])),
|
||||
("IID_IDXGIFactory", guid(0x7b7166ec, 0x21c7, 0x44ae, [0xb2, 0x1a, 0xc9, 0xae, 0x32, 0x1a, 0xe3, 0x69])),
|
||||
("IID_IDXGIFactory1", guid(0x770aae78, 0xf26f, 0x4dba, [0xa8, 0x29, 0x25, 0x3c, 0x83, 0xd1, 0xb3, 0x87])),
|
||||
("IID_IDXGIFactory2", guid(0x50c83a1c, 0xe072, 0x4c48, [0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0])),
|
||||
("IID_IDXGIObject", guid(0xaec22fb8, 0x76f3, 0x4639, [0x9b, 0xe0, 0x28, 0xeb, 0x43, 0xa6, 0x7a, 0x2e])),
|
||||
("IID_IDXGISwapChain", guid(0x310d36a0, 0xd2e7, 0x4c0a, [0xaa, 0x04, 0x6a, 0x9d, 0x23, 0xb8, 0x88, 0x6a])),
|
||||
("IID_IDXGISwapChain1", guid(0x790a45f7, 0x0d42, 0x4876, [0x98, 0x3a, 0x0a, 0x55, 0xcf, 0xe6, 0xf4, 0xaa])),
|
||||
("IID_IGraphicsUnknown", guid(0xaceeea63, 0xe0a9, 0x4a1c, [0xbb, 0xec, 0x71, 0xb2, 0xf4, 0x85, 0xf7, 0x58])),
|
||||
("WKPDID_D3DDebugObjectNameW", guid(0x4cca5fd8, 0x921f, 0x42c8, [0x85, 0x66, 0x70, 0xca, 0xf2, 0xa9, 0xb7, 0x41])),
|
||||
];
|
||||
|
||||
#[cfg(windows)]
|
||||
fn host_gpu_failed(what: &str) -> ! {
|
||||
use windows_sys::Win32::System::Threading::{GetCurrentProcess, TerminateProcess};
|
||||
eonacat_xsbox_gpu::loader::log_crash(&format!("eonacat-xs: host GPU failure: {what}"));
|
||||
|
||||
eonacat_xsbox_gpu::core::logging::flush(std::time::Duration::from_secs(2));
|
||||
const DXGI_ERROR_DEVICE_REMOVED: u32 = 0x887A_0005;
|
||||
|
||||
unsafe { TerminateProcess(GetCurrentProcess(), DXGI_ERROR_DEVICE_REMOVED) };
|
||||
unreachable!("the process has ended")
|
||||
}
|
||||
|
||||
pub fn precompile(container: &[u8]) -> Result<bool, String> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
eonacat_xsbox_gpu::shader_cache::precompile(container)
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let _ = container;
|
||||
Err("no host".into())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn warm_shader(container: &[u8]) -> Result<bool, String> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
eonacat_xsbox_gpu::shader_cache::precompile(container).map(|was_there| !was_there)
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let _ = container;
|
||||
Err("no shader cache on this host".into())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shader_translator_id() -> Option<String> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
Some(eonacat_xsbox_gpu::shader_cache::translator_id())
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn use_shader_cache(dir: std::path::PathBuf) {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
eonacat_xsbox_gpu::pipeline::use_pipeline_cache(dir.with_file_name("pipelines"));
|
||||
eonacat_xsbox_gpu::shader_cache::use_shader_cache(dir);
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
let _ = dir;
|
||||
}
|
||||
|
||||
pub(crate) fn module() -> HleModule {
|
||||
let function = |name, address: *const ()| HleExport {
|
||||
name,
|
||||
address: address as usize,
|
||||
};
|
||||
let mut exports = vec![
|
||||
function("D3D12ConfigureVirtualMemoryX", device::configure_virtual_memory as *const ()),
|
||||
function("D3D12XboxCreateDevice", create_device as *const ()),
|
||||
function("D3D12CreateDevice", create_device_with_level as *const ()),
|
||||
function("D3D12SerializeRootSignature", eonacat_xsbox_gpu::root::serialize as *const ()),
|
||||
function(
|
||||
"D3D12SerializeVersionedRootSignature",
|
||||
eonacat_xsbox_gpu::root::serialize_versioned as *const (),
|
||||
),
|
||||
|
||||
function(
|
||||
"D3D12CreateRootSignatureDeserializer",
|
||||
eonacat_xsbox_gpu::root::create_deserializer as *const (),
|
||||
),
|
||||
function(
|
||||
"D3D12CreateVersionedRootSignatureDeserializer",
|
||||
eonacat_xsbox_gpu::root::create_versioned_deserializer as *const (),
|
||||
),
|
||||
function("D3D10CreateBlob", eonacat_xsbox_gpu::root::create_blob as *const ()),
|
||||
function("D3D12GetDebugInterface", get_debug_interface as *const ()),
|
||||
function("D3D12XboxSetProcessDebugFlags", set_process_debug_flags as *const ()),
|
||||
function("D3D12XboxGetProcessDebugFlags", get_process_debug_flags as *const ()),
|
||||
function("D3D12XboxUnloadDriverModule", unload_driver_module as *const ()),
|
||||
function("D3DFlushEntireCpuCache", flush_entire_cpu_cache as *const ()),
|
||||
|
||||
HleExport {
|
||||
name: "IID_ID3D12Device",
|
||||
address: (&raw const device::IID) as usize,
|
||||
},
|
||||
];
|
||||
exports.extend(DATA_IDS.iter().map(|(name, id)| HleExport {
|
||||
name,
|
||||
address: (id as *const Iid) as usize,
|
||||
}));
|
||||
HleModule {
|
||||
name: "d3d12x",
|
||||
dlls: &["d3d12_xs.dll"],
|
||||
exports,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user