Skip to content

Commit 110dd1f

Browse files
committed
Resolve to correct depth slice.
1 parent 4b3e180 commit 110dd1f

13 files changed

Lines changed: 761 additions & 355 deletions

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
1919

2020
project("MarathonRecomp-ALL")
2121

22+
if(APPLE)
23+
enable_language(OBJC OBJCXX)
24+
endif()
25+
2226
if (CMAKE_OSX_ARCHITECTURES)
2327
set(MARATHON_RECOMP_ARCHITECTURE ${CMAKE_OSX_ARCHITECTURES})
2428
elseif(CMAKE_SYSTEM_PROCESSOR)

MarathonRecomp/CMakeLists.txt

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project("MarathonRecomp")
22

33
if (WIN32)
4-
option(MARATHON_RECOMP_D3D12 "Add D3D12 support for rendering" OFF)
4+
option(MARATHON_RECOMP_D3D12 "Add D3D12 support for rendering" ON)
55
endif()
66

77
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
@@ -125,6 +125,12 @@ if (MARATHON_RECOMP_D3D12)
125125
)
126126
endif()
127127

128+
if (APPLE)
129+
list(APPEND MARATHON_RECOMP_GPU_CXX_SOURCES
130+
"gpu/rhi/plume_apple.mm"
131+
)
132+
endif()
133+
128134
set(MARATHON_RECOMP_APU_CXX_SOURCES
129135
"apu/audio.cpp"
130136
"apu/xma_decoder.cpp"
@@ -381,31 +387,28 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux")
381387
target_compile_definitions(MarathonRecomp PRIVATE SDL_VULKAN_ENABLED)
382388
endif()
383389

384-
#find_package(directx-dxc REQUIRED)
385390
find_package(CURL REQUIRED)
386391

387-
#if (MARATHON_RECOMP_D3D12)
388-
# file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/D3D12)
389-
# add_custom_command(TARGET MarathonRecomp POST_BUILD
390-
# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:Microsoft::DirectX12-Core,IMPORTED_LOCATION_RELEASE> ${CMAKE_CURRENT_BINARY_DIR}/D3D12
391-
# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:Microsoft::DirectX12-Layers,IMPORTED_LOCATION_DEBUG> ${CMAKE_CURRENT_BINARY_DIR}/D3D12
392-
# COMMAND_EXPAND_LISTS
393-
# )
394-
#
395-
# find_file(DIRECTX_DXIL_LIBRARY "dxil.dll")
396-
# file(COPY ${DIRECTX_DXIL_LIBRARY} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
397-
#
398-
# target_link_libraries(MarathonRecomp PRIVATE
399-
# Microsoft::DirectX-Headers
400-
# Microsoft::DirectX-Guids
401-
# Microsoft::DirectX12-Agility
402-
# Microsoft::DirectXShaderCompiler
403-
# Microsoft::DXIL
404-
# dxgi
405-
# )
406-
#endif()
407-
408-
#file(CHMOD ${DIRECTX_DXC_TOOL} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
392+
393+
if (MARATHON_RECOMP_D3D12)
394+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/D3D12)
395+
add_custom_command(TARGET MarathonRecomp POST_BUILD
396+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:Microsoft::DirectX12-Core,IMPORTED_LOCATION_RELEASE> $<TARGET_FILE_DIR:MarathonRecomp>/D3D12
397+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:Microsoft::DirectX12-Layers,IMPORTED_LOCATION_DEBUG> $<TARGET_FILE_DIR:MarathonRecomp>/D3D12
398+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:Microsoft::DirectXShaderCompiler,IMPORTED_LOCATION> $<TARGET_FILE_DIR:MarathonRecomp>
399+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:Microsoft::DXIL,IMPORTED_LOCATION> $<TARGET_FILE_DIR:MarathonRecomp>
400+
COMMAND_EXPAND_LISTS
401+
)
402+
403+
target_link_libraries(MarathonRecomp PRIVATE
404+
Microsoft::DirectX-Headers
405+
Microsoft::DirectX-Guids
406+
Microsoft::DirectX12-Agility
407+
Microsoft::DirectXShaderCompiler
408+
Microsoft::DXIL
409+
dxgi
410+
)
411+
endif()
409412

410413
if (WIN32)
411414
target_link_libraries(MarathonRecomp PRIVATE
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// plume
3+
//
4+
// Copyright (c) 2024 renderbag and contributors. All rights reserved.
5+
// Licensed under the MIT license. See LICENSE file for details.
6+
//
7+
8+
#pragma once
9+
10+
#include <atomic>
11+
#include <mutex>
12+
#include "plume_render_interface_types.h"
13+
14+
namespace plume {
15+
RenderDeviceVendor getRenderDeviceVendor(uint64_t registryID);
16+
17+
struct CocoaWindowAttributes {
18+
int x, y;
19+
int width, height;
20+
};
21+
22+
class CocoaWindow {
23+
void* windowHandle;
24+
CocoaWindowAttributes cachedAttributes;
25+
std::atomic<int> cachedRefreshRate;
26+
mutable std::mutex attributesMutex;
27+
28+
void updateWindowAttributesInternal(bool forceSync = false);
29+
void updateRefreshRateInternal(bool forceSync = false);
30+
public:
31+
CocoaWindow(void* window);
32+
~CocoaWindow();
33+
34+
// Get cached window attributes, may trigger async update
35+
void getWindowAttributes(CocoaWindowAttributes* attributes) const;
36+
37+
// Get cached refresh rate, may trigger async update
38+
int getRefreshRate() const;
39+
40+
// Toggle fullscreen
41+
void toggleFullscreen();
42+
};
43+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
//
2+
// plume
3+
//
4+
// Copyright (c) 2024 renderbag and contributors. All rights reserved.
5+
// Licensed under the MIT license. See LICENSE file for details.
6+
//
7+
8+
#include "plume_apple.h"
9+
10+
#import <AppKit/AppKit.h>
11+
#import <Foundation/Foundation.h>
12+
#import <IOKit/IOKitLib.h>
13+
14+
static uint32_t plumeGetEntryProperty(io_registry_entry_t entry, CFStringRef propertyName) {
15+
uint32_t value = 0;
16+
CFTypeRef cfProp = IORegistryEntrySearchCFProperty(entry, kIOServicePlane, propertyName, kCFAllocatorDefault, kIORegistryIterateRecursively | kIORegistryIterateParents);
17+
18+
if (cfProp) {
19+
if (CFGetTypeID(cfProp) == CFDataGetTypeID()) {
20+
const uint32_t* pValue = reinterpret_cast<const uint32_t*>(CFDataGetBytePtr((CFDataRef)cfProp));
21+
if (pValue) {
22+
value = *pValue;
23+
}
24+
}
25+
CFRelease(cfProp);
26+
}
27+
28+
return value;
29+
}
30+
31+
namespace plume {
32+
RenderDeviceVendor getRenderDeviceVendor(uint64_t registryID) {
33+
io_service_t entry = IOServiceGetMatchingService(MACH_PORT_NULL, IORegistryEntryIDMatching(registryID));
34+
35+
if (entry) {
36+
io_registry_entry_t parent;
37+
if (IORegistryEntryGetParentEntry(entry, kIOServicePlane, &parent) == kIOReturnSuccess) {
38+
uint32_t vendorId = plumeGetEntryProperty(parent, CFSTR("vendor-id"));
39+
IOObjectRelease(parent); // Release the parent
40+
IOObjectRelease(entry); // Release the entry
41+
return RenderDeviceVendor(vendorId);
42+
}
43+
IOObjectRelease(entry); // Release the entry if we couldn't get parent
44+
}
45+
46+
return RenderDeviceVendor::UNKNOWN;
47+
}
48+
49+
// MARK: - CocoaWindow
50+
51+
CocoaWindow::CocoaWindow(void* window)
52+
: windowHandle(window), cachedRefreshRate(0) {
53+
cachedAttributes = {0, 0, 0, 0};
54+
55+
if ([NSThread isMainThread]) {
56+
NSWindow *nsWindow = (__bridge NSWindow *)windowHandle;
57+
NSRect contentFrame = [[nsWindow contentView] frame];
58+
CGFloat scaleFactor = [nsWindow backingScaleFactor];
59+
60+
cachedAttributes.x = (int)round(contentFrame.origin.x);
61+
cachedAttributes.y = (int)round(contentFrame.origin.y);
62+
cachedAttributes.width = (int)round(contentFrame.size.width * scaleFactor);
63+
cachedAttributes.height = (int)round(contentFrame.size.height * scaleFactor);
64+
65+
NSScreen *screen = [nsWindow screen];
66+
if (@available(macOS 12.0, *)) {
67+
cachedRefreshRate.store((int)[screen maximumFramesPerSecond]);
68+
}
69+
} else {
70+
updateWindowAttributesInternal(true);
71+
updateRefreshRateInternal(true);
72+
}
73+
}
74+
75+
CocoaWindow::~CocoaWindow() {}
76+
77+
void CocoaWindow::updateWindowAttributesInternal(bool forceSync) {
78+
auto updateBlock = ^{
79+
NSWindow *nsWindow = (__bridge NSWindow *)windowHandle;
80+
NSRect contentFrame = [[nsWindow contentView] frame];
81+
CGFloat scaleFactor = [nsWindow backingScaleFactor];
82+
83+
std::lock_guard<std::mutex> lock(attributesMutex);
84+
cachedAttributes.x = (int)round(contentFrame.origin.x);
85+
cachedAttributes.y = (int)round(contentFrame.origin.y);
86+
cachedAttributes.width = (int)round(contentFrame.size.width * scaleFactor);
87+
cachedAttributes.height = (int)round(contentFrame.size.height * scaleFactor);
88+
};
89+
90+
if (forceSync) {
91+
dispatch_sync(dispatch_get_main_queue(), updateBlock);
92+
} else {
93+
dispatch_async(dispatch_get_main_queue(), updateBlock);
94+
}
95+
}
96+
97+
void CocoaWindow::updateRefreshRateInternal(bool forceSync) {
98+
auto updateBlock = ^{
99+
NSWindow *nsWindow = (__bridge NSWindow *)windowHandle;
100+
NSScreen *screen = [nsWindow screen];
101+
if (@available(macOS 12.0, *)) {
102+
cachedRefreshRate.store((int)[screen maximumFramesPerSecond]);
103+
}
104+
};
105+
106+
if (forceSync) {
107+
dispatch_sync(dispatch_get_main_queue(), updateBlock);
108+
} else {
109+
dispatch_async(dispatch_get_main_queue(), updateBlock);
110+
}
111+
}
112+
113+
void CocoaWindow::getWindowAttributes(CocoaWindowAttributes* attributes) const {
114+
if ([NSThread isMainThread]) {
115+
NSWindow *nsWindow = (__bridge NSWindow *)windowHandle;
116+
NSRect contentFrame = [[nsWindow contentView] frame];
117+
CGFloat scaleFactor = [nsWindow backingScaleFactor];
118+
119+
{
120+
std::lock_guard<std::mutex> lock(attributesMutex);
121+
const_cast<CocoaWindow*>(this)->cachedAttributes.x = (int)round(contentFrame.origin.x);
122+
const_cast<CocoaWindow*>(this)->cachedAttributes.y = (int)round(contentFrame.origin.y);
123+
const_cast<CocoaWindow*>(this)->cachedAttributes.width = (int)round(contentFrame.size.width * scaleFactor);
124+
const_cast<CocoaWindow*>(this)->cachedAttributes.height = (int)round(contentFrame.size.height * scaleFactor);
125+
126+
*attributes = cachedAttributes;
127+
}
128+
} else {
129+
{
130+
std::lock_guard<std::mutex> lock(attributesMutex);
131+
*attributes = cachedAttributes;
132+
}
133+
134+
const_cast<CocoaWindow*>(this)->updateWindowAttributesInternal(false);
135+
}
136+
}
137+
138+
int CocoaWindow::getRefreshRate() const {
139+
if ([NSThread isMainThread]) {
140+
NSWindow *nsWindow = (__bridge NSWindow *)windowHandle;
141+
NSScreen *screen = [nsWindow screen];
142+
143+
if (@available(macOS 12.0, *)) {
144+
int freshRate = (int)[screen maximumFramesPerSecond];
145+
const_cast<CocoaWindow*>(this)->cachedRefreshRate.store(freshRate);
146+
return freshRate;
147+
}
148+
149+
return cachedRefreshRate.load();
150+
} else {
151+
int rate = cachedRefreshRate.load();
152+
153+
const_cast<CocoaWindow*>(this)->updateRefreshRateInternal(false);
154+
155+
return rate;
156+
}
157+
}
158+
159+
void CocoaWindow::toggleFullscreen() {
160+
if ([NSThread isMainThread]) {
161+
NSWindow *nsWindow = (__bridge NSWindow *)windowHandle;
162+
[nsWindow toggleFullScreen:NULL];
163+
} else {
164+
dispatch_async(dispatch_get_main_queue(), ^{
165+
NSWindow *nsWindow = (__bridge NSWindow *)windowHandle;
166+
[nsWindow toggleFullScreen:NULL];
167+
});
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)