TsundereStation/Makefile.libretro

774 lines
27 KiB
Text
Raw Normal View History

# swanstation libretro core - static Makefile (Makefile.libretro)
#
# Modeled on the Beetle PSX libretro Makefile:
# https://github.com/libretro/beetle-psx-libretro
#
# This Makefile is dedicated to building the libretro core only and
# always assumes the libretro defines (LIBRETRO, __LIBRETRO__) are on.
# It is intended to coexist with the existing CMake build system; the
# CMake build continues to work and is unaffected by this Makefile.
#
# Invoke explicitly via -f:
# make -f Makefile.libretro # native build
# make -f Makefile.libretro platform=unix
# make -f Makefile.libretro platform=osx
# make -f Makefile.libretro platform=win
# make -f Makefile.libretro DEBUG=1
#
# Supported host platforms: Linux, macOS, Windows (MinGW / MSYS2).
# Cross-compilation flavours are also accepted via the standard
# libretro `platform=` knob (e.g. unix-armv7-neon-hardfloat, etc.).
DEBUG ?= 0
SILENT ?= 0
LINK_STATIC_LIBCPLUSPLUS ?= 1
CORE_DIR := .
TARGET_NAME := swanstation
# ---------------------------------------------------------------------
# Helpers and version info
# ---------------------------------------------------------------------
SPACE :=
SPACE := $(SPACE) $(SPACE)
BACKSLASH :=
BACKSLASH := \$(BACKSLASH)
filter_out1 = $(filter-out $(firstword $1),$1)
filter_out2 = $(call filter_out1,$(call filter_out1,$1))
GIT_VERSION ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
GIT_HASH ?= $(GIT_VERSION)
BUILD_DATE ?= $(shell date -u "+%Y-%m-%d %H:%M:%S")
# ---------------------------------------------------------------------
# Platform detection
# ---------------------------------------------------------------------
ifeq ($(platform),)
platform = unix
ifeq ($(shell uname -s),)
platform = win
else ifneq ($(findstring Darwin,$(shell uname -s)),)
platform = osx
arch = intel
ifeq ($(shell uname -m),arm64)
arch = arm64
endif
else ifneq ($(findstring MINGW,$(shell uname -s)),)
platform = win
else ifneq ($(findstring MSYS,$(shell uname -s)),)
platform = win
endif
else ifneq (,$(findstring armv,$(platform)))
override platform += unix
endif
ifneq ($(platform), osx)
ifeq ($(findstring Haiku,$(shell uname -s)),)
PTHREAD_FLAGS = -lpthread
endif
endif
# ---------------------------------------------------------------------
# CPU architecture detection (mirrors CMakeLists.txt logic)
# ---------------------------------------------------------------------
# CPU_ARCH may be one of: x64, x86, aarch64, aarch32
CPU_ARCH ?=
ifeq ($(CPU_ARCH),)
ifeq ($(platform), osx)
ifeq ($(arch),arm64)
CPU_ARCH := aarch64
else
CPU_ARCH := x64
endif
else
UNAME_M := $(shell uname -m 2>/dev/null)
ifneq (,$(filter $(UNAME_M),x86_64 amd64 AMD64))
CPU_ARCH := x64
else ifneq (,$(filter $(UNAME_M),i386 i686 x86))
CPU_ARCH := x86
else ifneq (,$(filter $(UNAME_M),aarch64 arm64))
CPU_ARCH := aarch64
else ifneq (,$(findstring arm,$(UNAME_M)))
CPU_ARCH := aarch32
else
# Fall back to 64-bit on Windows where uname may be unavailable
CPU_ARCH := x64
endif
endif
endif
ifeq ($(CPU_ARCH),x64)
WITH_RECOMPILER := 1
WITH_MMAP_FASTMEM := 1
endif
ifeq ($(CPU_ARCH),aarch64)
WITH_RECOMPILER := 1
WITH_MMAP_FASTMEM := 1
endif
ifeq ($(CPU_ARCH),aarch32)
WITH_RECOMPILER := 1
endif
# ---------------------------------------------------------------------
# Per-platform target / shared-library / linker flags
# ---------------------------------------------------------------------
# Unix / Linux / *BSD
ifneq (,$(findstring unix,$(platform)))
TARGET := $(TARGET_NAME)_libretro.so
fpic := -fPIC
ifneq ($(findstring SunOS,$(shell uname -s)),)
SHARED := -shared -z defs
else
SHARED := -shared -Wl,--no-undefined -Wl,--version-script=link.T
endif
ifeq ($(LINK_STATIC_LIBCPLUSPLUS),1)
LDFLAGS += -static-libgcc -static-libstdc++
endif
LDFLAGS += $(PTHREAD_FLAGS) -ldl -lrt
ifneq ($(findstring Haiku,$(shell uname -s)),)
LDFLAGS := $(filter-out -ldl -lrt,$(LDFLAGS)) -lroot
endif
ifeq ($(CPU_ARCH),aarch32)
FLAGS += -marm -march=armv7-a
endif
# macOS
else ifeq ($(platform), osx)
TARGET := $(TARGET_NAME)_libretro.dylib
fpic := -fPIC
SHARED := -dynamiclib -Wl,-exported_symbols_list,libretro.osx.def
LDFLAGS += $(PTHREAD_FLAGS)
FLAGS += $(PTHREAD_FLAGS)
# Link the few macOS frameworks/libraries the core needs.
# `objc` is required by the Vulkan swap chain helper used on macOS.
LDFLAGS += -lobjc -framework CoreFoundation
ifeq ($(arch),arm64)
MINOS := -mmacosx-version-min=11.0
else
MINOS := -mmacosx-version-min=10.14
endif
FLAGS += $(MINOS)
LDFLAGS += $(MINOS)
ifeq ($(CROSS_COMPILE),1)
TARGET_RULE := -target $(LIBRETRO_APPLE_PLATFORM) -isysroot $(LIBRETRO_APPLE_ISYSROOT)
CFLAGS += $(TARGET_RULE)
CXXFLAGS += $(TARGET_RULE)
LDFLAGS += $(TARGET_RULE)
endif
# Windows (MinGW / MSYS2 / cross gcc)
else ifeq ($(platform), win)
TARGET := $(TARGET_NAME)_libretro.dll
CC ?= gcc
CXX ?= g++
SHARED := -shared -Wl,--no-undefined -Wl,--version-script=link.T
LDFLAGS += -static-libgcc -static-libstdc++
# winmm: timeBeginPeriod (used by core), d3dcompiler/d3d11/dxgi for D3D11
# The bundled vulkan-loader resolves the Vulkan ICD at runtime through
# LoadLibrary, so no -lvulkan-1 is required at link time.
LDFLAGS += -lwinmm -ld3d11 -ld3dcompiler -ldxgi -lopengl32 -lgdi32 -luser32 -lkernel32
# Generic Windows fallback (covers e.g. `make platform=win-x86_64`)
else ifneq (,$(findstring win,$(platform)))
TARGET := $(TARGET_NAME)_libretro.dll
CC ?= gcc
CXX ?= g++
SHARED := -shared -Wl,--no-undefined -Wl,--version-script=link.T
LDFLAGS += -static-libgcc -static-libstdc++
LDFLAGS += -lwinmm -ld3d11 -ld3dcompiler -ldxgi -lopengl32 -lgdi32 -luser32 -lkernel32
# Unrecognised platform - emit a clear error rather than silently building
# something broken.
else
$(error Unsupported platform '$(platform)'. Supported: unix, osx, win)
endif
# Detect Windows-ness of the *target* (used to gate D3D sources etc.)
ifneq (,$(findstring win,$(platform)))
IS_WINDOWS := 1
else
IS_WINDOWS := 0
endif
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# Source manifest
# ---------------------------------------------------------------------
# Every translation unit and every include path the libretro core
# needs is listed here, in source order matching the corresponding
# CMakeLists.txt files in src/ and dep/. When a file is added to a
# CMakeLists.txt it must be added here too.
SOURCES_C :=
SOURCES_CC :=
SOURCES_CXX :=
CORE_DIR ?= .
DEPS_DIR := $(CORE_DIR)/dep
SRC_DIR := $(CORE_DIR)/src
LIBRETRO_COMM_DIR := $(DEPS_DIR)/libretro-common
LIBCHDR_DIR := $(DEPS_DIR)/libchdr
GLAD_DIR := $(DEPS_DIR)/glad
GLSLANG_DIR := $(DEPS_DIR)/glslang
VULKAN_LOADER_DIR := $(DEPS_DIR)/vulkan-loader
STB_DIR := $(DEPS_DIR)/stb
XXHASH_DIR := $(DEPS_DIR)/xxhash
OPENBIOS_DIR := $(DEPS_DIR)/openbios
XBYAK_DIR := $(DEPS_DIR)/xbyak
VIXL_DIR := $(DEPS_DIR)/vixl
# Include paths.
#
# Notes:
# - We only add `-Isrc`. Source files inside src/{common,core,libretro}
# use forms like `#include "common/byte_stream.h"` and same-directory
audio: devirtualize AudioStream, fold NullAudioStream into LibretroAudioStream The audio path used to be: - common/audio_stream.h declared an abstract AudioStream base with one pure virtual (FramesAvailable) and shared non-virtual BeginWrite/EndWrite/Reconfigure/Shutdown. - libretro/libretro_audio_stream.{h,cpp} overrode FramesAvailable with the real libretro frontend drain. - common/null_audio_stream.{h,cpp} overrode FramesAvailable to discard, and was constructed only to feed the SPU during internal-runahead replay so audio from those frames never reached the frontend. The SPU pointer-swapped between the host stream and the null stream around DoRunahead's replay loop. The base class buys nothing here. There is exactly one runtime audio stream in swanstation - LibretroAudioStream - and the second subclass exists only to express 'discard everything' behaviour, which is trivially representable as a flag on the real one. EndWrite ran a virtual call to FramesAvailable on every SPU update (~150-300 times per frame), the indirection resolving to the same place every time. Drop the base class and the null subclass: - Delete common/audio_stream.{h,cpp} and common/null_audio_stream.{h,cpp}. - LibretroAudioStream becomes a plain class with no inheritance, absorbing the BeginWrite/EndWrite/Reconfigure/Shutdown bodies and the SampleType/MaxSamples/etc. constants from the old base. - FramesAvailable's contents are inlined into EndWrite (it was the only caller), with an early-return for fast-hook mode that matches the previous behaviour exactly. - The 'discard' role of NullAudioStream becomes a m_silent_mode flag and a SetSilentMode() setter on LibretroAudioStream. EndWrite drains the FIFO immediately when silent, so the SPU keeps ticking state-machines (envelope counters, ADPCM phase, etc.) for correctness, the FIFO does not build up backpressure across the runahead window, and nothing reaches the frontend. - System::DoRunahead replaces the SPU pointer-swap with a SetSilentMode(true)/SetSilentMode(false) toggle on the host's existing LibretroAudioStream. s_runahead_audio_stream (std::unique_ptr<AudioStream>) and the matching reset() in System::Shutdown go away entirely. - HostInterface drops the virtual CreateAudioStream() factory method; its single override in LibretroHostInterface returned std::make_unique<LibretroAudioStream>() which is now inlined at the only call site (HostInterface::BootSystem). - HostInterface::m_audio_stream and HostInterface::GetAudioStream become typed as LibretroAudioStream (forward-declared in host_interface.h, the libretro header included from the cpp). SPU::SetAudioStream and SPU::m_audio_stream similarly get the concrete type. The static_cast in retro_run_frame's UploadToFrontend call goes away. - Makefile.libretro and src/common/CMakeLists.txt drop the deleted source files from their lists. Linux x64 build still warning-clean. .so size drops from 8047800 to 8046184 bytes (-1616) - the AudioStream and NullAudioStream vtables/typeinfo, the virtual destructor and FramesAvailable, the indirect-call sites in EndWrite, and the second runahead audio stream instance and its construction code are all gone. 25 retro_* exports unchanged. Behaviour is identical: the SetSilentMode toggle produces exactly the same observable result as the swap-to-NullAudioStream pattern (the SPU's frame output is discarded during the replay window in both cases).
2026-05-08 12:58:10 +00:00
# `#include "byte_stream.h"`; the latter resolves source-relative
# automatically. Adding `-Isrc/common` would shadow the system
# `<string.h>` with `src/common/string.h` and break `<cstring>`.
INCFLAGS := \
-I$(SRC_DIR) \
-I$(LIBRETRO_COMM_DIR)/include \
-I$(LIBCHDR_DIR)/include \
-I$(LIBCHDR_DIR)/deps/lzma-25.01/include \
-I$(LIBCHDR_DIR)/deps/miniz-3.1.1 \
-I$(LIBCHDR_DIR)/deps/zstd-1.5.7 \
-I$(GLAD_DIR)/include \
-I$(GLSLANG_DIR) \
-I$(VULKAN_LOADER_DIR)/include \
-I$(STB_DIR)/include \
-I$(XXHASH_DIR)/include \
-I$(OPENBIOS_DIR)
ifeq ($(CPU_ARCH),x64)
INCFLAGS += -I$(XBYAK_DIR)/xbyak
endif
ifneq (,$(filter $(CPU_ARCH),aarch64 aarch32))
build: add vixl PRIVATE include paths for aarch64 / aarch32 builds Apple Silicon (and any other aarch64/aarch32 host) currently fails the static Makefile build with: dep/vixl/src/code-buffer-vixl.cc:33:10: fatal error: 'code-buffer-vixl.h' file not found vixl uses a CMake idiom that splits its include directories: it exposes ${SRC}/include as PUBLIC for consumers and ${SRC}/include/vixl plus the per-target subdir as PRIVATE for vixl's own translation units. Concretely: - Consumers in src/core/ write #include "vixl/aarch64/foo.h" and need only -I.../vixl/include. - vixl's own .cc files write #include "code-buffer-vixl.h" and need -I.../vixl/include/vixl. - vixl's aarch64 .cc files write #include "assembler-aarch64.h" and need -I.../vixl/include/vixl/aarch64. - vixl's aarch64 .cc files also write #include "../globals-vixl.h" which resolves through the same -I via the parent path. Makefile.libretro was only adding the consumer (PUBLIC) include for both aarch architectures, which is enough for src/core to compile but not enough for vixl's own translation units. x64 builds were unaffected because they use xbyak instead of vixl. Add the missing PRIVATE includes for both aarch architectures, gated by CPU_ARCH so we don't drag in both aarch32 and aarch64 internal headers at once. The vixl bare-name headers (code-buffer-vixl.h, cpu-features.h, globals-vixl.h, ...) do not collide with anything else in the tree - verified by searching for each of the 25 bare names across src/ and dep/, with no matches outside dep/vixl/. Verified by cross-compiling each vixl source file with aarch64-linux-gnu-g++ -DVIXL_INCLUDE_TARGET_A64 and the new -I set: 22/22 base+aarch64 sources compile cleanly. Same check with -DVIXL_INCLUDE_TARGET_A32 and the aarch32 -I set: 11/11 base+aarch32 sources compile cleanly. Linux x64 build is unchanged (vixl block doesn't fire) - .so still 8048480 bytes, 25 retro_* exports.
2026-05-08 03:41:48 +00:00
# vixl's own sources include their headers without the "vixl/" prefix
# (e.g. #include "code-buffer-vixl.h"), while consumers in src/core use
# the "vixl/..." prefix. vixl's CMake makes ${SRC}/include "PUBLIC" and
# ${SRC}/include/vixl plus the per-target subdir "PRIVATE". This single
# %.o pattern rule has no notion of PRIVATE/PUBLIC, so add all three to
# INCFLAGS - the per-target subdir is selected here so we don't pull in
# both aarch32 and aarch64 internal headers at once. The vixl bare-name
# headers (code-buffer-vixl.h, cpu-features.h, ...) do not collide with
# anything else in the tree (verified by name search).
INCFLAGS += -I$(VIXL_DIR)/include
build: add vixl PRIVATE include paths for aarch64 / aarch32 builds Apple Silicon (and any other aarch64/aarch32 host) currently fails the static Makefile build with: dep/vixl/src/code-buffer-vixl.cc:33:10: fatal error: 'code-buffer-vixl.h' file not found vixl uses a CMake idiom that splits its include directories: it exposes ${SRC}/include as PUBLIC for consumers and ${SRC}/include/vixl plus the per-target subdir as PRIVATE for vixl's own translation units. Concretely: - Consumers in src/core/ write #include "vixl/aarch64/foo.h" and need only -I.../vixl/include. - vixl's own .cc files write #include "code-buffer-vixl.h" and need -I.../vixl/include/vixl. - vixl's aarch64 .cc files write #include "assembler-aarch64.h" and need -I.../vixl/include/vixl/aarch64. - vixl's aarch64 .cc files also write #include "../globals-vixl.h" which resolves through the same -I via the parent path. Makefile.libretro was only adding the consumer (PUBLIC) include for both aarch architectures, which is enough for src/core to compile but not enough for vixl's own translation units. x64 builds were unaffected because they use xbyak instead of vixl. Add the missing PRIVATE includes for both aarch architectures, gated by CPU_ARCH so we don't drag in both aarch32 and aarch64 internal headers at once. The vixl bare-name headers (code-buffer-vixl.h, cpu-features.h, globals-vixl.h, ...) do not collide with anything else in the tree - verified by searching for each of the 25 bare names across src/ and dep/, with no matches outside dep/vixl/. Verified by cross-compiling each vixl source file with aarch64-linux-gnu-g++ -DVIXL_INCLUDE_TARGET_A64 and the new -I set: 22/22 base+aarch64 sources compile cleanly. Same check with -DVIXL_INCLUDE_TARGET_A32 and the aarch32 -I set: 11/11 base+aarch32 sources compile cleanly. Linux x64 build is unchanged (vixl block doesn't fire) - .so still 8048480 bytes, 25 retro_* exports.
2026-05-08 03:41:48 +00:00
INCFLAGS += -I$(VIXL_DIR)/include/vixl
endif
ifeq ($(CPU_ARCH),aarch64)
INCFLAGS += -I$(VIXL_DIR)/include/vixl/aarch64
endif
ifeq ($(CPU_ARCH),aarch32)
INCFLAGS += -I$(VIXL_DIR)/include/vixl/aarch32
endif
# ---------------------------------------------------------------------
# src/common
# ---------------------------------------------------------------------
COMMON_DIR := $(SRC_DIR)/common
SOURCES_CXX += \
$(COMMON_DIR)/byte_stream.cpp \
$(COMMON_DIR)/cd_image.cpp \
$(COMMON_DIR)/cd_image_bin.cpp \
$(COMMON_DIR)/cd_image_cue.cpp \
$(COMMON_DIR)/cd_image_chd.cpp \
$(COMMON_DIR)/cd_image_ecm.cpp \
$(COMMON_DIR)/cd_image_m3u.cpp \
$(COMMON_DIR)/cd_image_memory.cpp \
$(COMMON_DIR)/cd_image_mds.cpp \
$(COMMON_DIR)/cd_image_pbp.cpp \
$(COMMON_DIR)/cd_image_ppf.cpp \
$(COMMON_DIR)/cd_subchannel_replacement.cpp \
$(COMMON_DIR)/cd_xa.cpp \
$(COMMON_DIR)/cue_parser.cpp \
$(COMMON_DIR)/error.cpp \
$(COMMON_DIR)/event.cpp \
$(COMMON_DIR)/file_system.cpp \
$(COMMON_DIR)/image.cpp \
$(COMMON_DIR)/iso_reader.cpp \
$(COMMON_DIR)/jit_code_buffer.cpp \
$(COMMON_DIR)/log.cpp \
$(COMMON_DIR)/md5_digest.cpp \
$(COMMON_DIR)/memory_arena.cpp \
$(COMMON_DIR)/page_fault_handler.cpp \
$(COMMON_DIR)/progress_callback.cpp \
$(COMMON_DIR)/state_wrapper.cpp \
$(COMMON_DIR)/string.cpp \
$(COMMON_DIR)/string_util.cpp \
$(COMMON_DIR)/timer.cpp \
$(COMMON_DIR)/gl/program.cpp \
$(COMMON_DIR)/gl/shader_cache.cpp \
$(COMMON_DIR)/gl/stream_buffer.cpp \
$(COMMON_DIR)/gl/texture.cpp \
$(COMMON_DIR)/vulkan/builders.cpp \
$(COMMON_DIR)/vulkan/context.cpp \
common/vulkan, core: pre-bake screen-quad VS, no glslang at runtime This is the probe patch in a series that eliminates dep/glslang from the libretro core build. It establishes the infrastructure - the GLSL source tree, the embedded-SPIR-V loader, the regeneration tool, and the build wiring - by converting exactly one call site so the pattern can be smoke-tested in isolation before the rest of Bucket A and then Bucket B follow in subsequent patches. glslang stays in the tree until the final patch in the series, which removes dep/glslang and the surrounding shader_compiler.cpp. What this patch does: - Adds data/shaders/vulkan/screen_quad.vert.glsl - the GLSL source for the screen-quad VS, kept in the tree for human readability. The build does NOT see this file; it is consumed only by the offline regen tool. - Adds src/common/vulkan/embedded_spirv/screen_quad_vs.inc - the pre-compiled SPIR-V blob as a 'const uint32_t[]' (367 words, 1.4 KiB), generated offline from the .glsl by glslangValidator targeting vulkan1.0. The .inc is checked in and #include'd by embedded_shaders.cpp inside namespace Vulkan::EmbeddedShaders. spirv-val confirms the blob is valid Vulkan 1.0 SPIR-V (magic 0x07230203, version 1.0). - Adds src/common/vulkan/embedded_shaders.{h,cpp}. The header exposes a pair of extern declarations per blob and a single CreateShaderModule(const uint32_t*, size_t) loader. The loader intentionally bypasses Vulkan::ShaderCache - pre-baked SPIR-V is already final, so there is nothing to compile and nothing worth caching on disk. Just a sized-and-checked vkCreateShaderModule call. - Adds tools/regen_vulkan_spirv.py - the offline workflow for contributors who edit shader .glsl sources. It invokes glslangValidator on each .glsl under data/shaders/vulkan/ and rewrites the matching .inc. CRITICAL: this tool is NEVER invoked by Make or CMake. The build sees only .h/.cpp/.inc files and has no shader- compiler dependency. Contributors run the script manually after editing .glsl, commit both files together. - Adds data/shaders/vulkan/README.md documenting the workflow and the invariant that the build must never invoke an external shader compiler. - Switches GPU_HW_Vulkan::GetFullscreenQuadVertexShader() (in src/core/gpu_hw_vulkan.cpp) from g_vulkan_shader_cache->GetVertexShader(m_shadergen->Generate...) to Vulkan::EmbeddedShaders::CreateShaderModule(k_screen_quad_vs, ...). The m_shadergen null-check is removed since the embedded path has no such ordering dependency. The function's contract (lazy creation, stored in m_fullscreen_quad_vertex_shader, returned to multiple pipeline builders) is unchanged. - Registers src/common/vulkan/embedded_shaders.cpp in both Makefile.libretro (alphabetical order in the vulkan/ SOURCES_CXX block) and src/common/CMakeLists.txt (alphabetical order in the common target's source list). Neither change adds any build-tool dependency; the new .cpp compiles like any other. What this patch does NOT do: - It does not remove dep/glslang or the SOURCES_CXX entries that pull in its 99 translation units. glslang is still needed for every shader generator that has not yet been converted - in particular all of GPU_HW_ShaderGen, plus the remaining utility shaders (UV quad VS, VRAM read/copy/write/fill/update-depth FS, display FS, adaptive downsample mip/blur/composite FS, box-sample downsample FS). Subsequent patches in this series convert those one bucket at a time. The final patch removes dep/glslang, src/common/vulkan/shader_compiler.{h,cpp}, the glslang link line in CMake, and the Makefile entries. - It does not touch the disk-backed Vulkan::ShaderCache. That cache still serves the runtime-glslang path for remaining shaders. Smoke tests performed in isolation: - glslangValidator --target-env vulkan1.0 succeeds on the .glsl source, producing 367 32-bit words of SPIR-V. - spirv-val --target-env vulkan1.0 reports VALID on the blob. - spirv-dis confirms the entry point, VertexData block, and Position/ VertexIndex built-ins are correctly emitted. - A standalone harness including the .inc inside the Vulkan::EmbeddedShaders namespace and calling CreateShaderModule through a stubbed vkCreateShaderModule reads back the correct magic word and size. - g++ -fsyntax-only on embedded_shaders.cpp against the real headers in the tree (excluding only the platform-specific X11 surface define not used by this TU) is clean. Smoke tests that require the user's setup: - Real build on Windows (RTX 5090) and macOS. - Vulkan core boots, RetroArch's pipeline cache populates, and at least one game renders past the first frame using the screen-quad pipeline (VRAM ops, display, downsample - all of which call GetFullscreenQuadVertexShader internally).
2026-05-17 17:49:19 +00:00
$(COMMON_DIR)/vulkan/embedded_shaders.cpp \
$(COMMON_DIR)/vulkan/shader_cache.cpp \
$(COMMON_DIR)/vulkan/shader_compiler.cpp \
$(COMMON_DIR)/vulkan/staging_buffer.cpp \
$(COMMON_DIR)/vulkan/staging_texture.cpp \
$(COMMON_DIR)/vulkan/stream_buffer.cpp \
$(COMMON_DIR)/vulkan/texture.cpp \
$(COMMON_DIR)/vulkan/util.cpp
# Direct3D 11 backend - Windows only.
ifeq ($(IS_WINDOWS),1)
SOURCES_CXX += \
$(COMMON_DIR)/d3d11/shader_cache.cpp \
$(COMMON_DIR)/d3d11/shader_compiler.cpp \
$(COMMON_DIR)/d3d11/staging_texture.cpp \
$(COMMON_DIR)/d3d11/stream_buffer.cpp \
$(COMMON_DIR)/d3d11/texture.cpp
core, libretro, common: wire up D3D12 renderer for libretro Wires the existing D3D12 hardware renderer (src/core/gpu_hw_d3d12.cpp, src/common/d3d12/*) into the libretro frontend, behind a USE_D3D12=1 gate. The opt-in is because: 1. retro_hw_render_interface_d3d12 is supported by recent RetroArch builds but not all of them - the SET_HW_RENDER environment call will fail at runtime where unsupported. 2. Not every Windows target ships d3d12.lib in its toolchain; the gate keeps the existing default Windows build path working. When USE_D3D12=1 is set on the make command line, the libretro Makefile pulls in the seven common/d3d12 TUs, gpu_hw_d3d12.cpp, the new LibretroD3D12HostDisplay class, links against d3d12.lib, and exposes "D3D12" in the renderer dropdown next to D3D11. == src/common/d3d12 == D3D12::Context grew a CreateForLibretro(device, command_queue) static factory next to its existing Create(dxgi_factory, ...). The libretro path adopts the frontend's device + command queue (the frontend retains ownership; we just AddRef them via ComPtr) and then creates only the resources we own: fence, descriptor heaps, command lists, texture upload stream buffer. Feature level is pinned at FL11_0; the gpu_hw_d3d12 shader/PSO setup targets that baseline. CreateForLibretro still loads d3d12.dll because PFN_D3D12_SERIALIZE_ROOT_SIGNATURE is needed by Context::SerializeRootSignature, which gpu_hw_d3d12.cpp uses on initial root-signature creation. Destroy() is unchanged; the borrowed device/queue ComPtrs simply release their AddRef in the Context destructor and the frontend keeps the underlying objects alive. == src/core/gpu_hw_d3d12.h, .cpp == Added LibretroD3D12HostDisplay (declaration in the header above GPU_HW_D3D12, implementation appended ahead of GPU_HW_D3D12's constructor body in the .cpp). The class mirrors LibretroD3D11HostDisplay's surface and behaves identically on the libretro-API side, with two differences driven by the D3D12 libretro interface contract: 1. There is no analogue to ID3D11DeviceContext in D3D12 - work is recorded on command lists owned by D3D12::Context. The class therefore does not store m_device / m_context members; callers that need the device go through g_d3d12_context->GetDevice() as the rest of gpu_hw_d3d12.cpp already does. GetRenderDevice() returns g_d3d12_context->GetDevice() for HostDisplay-API callers; GetRenderContext() returns nullptr. 2. Present is the retro_hw_render_interface_d3d12::set_texture callback rather than a swapchain blit. LibretroD3D12HostDisplay ::Render() transitions the GPU_HW_D3D12-produced display texture into the frontend's required_state, flushes our pending command list via ExecuteCommandList(false), calls set_texture(frontend_handle, ID3D12Resource*, format), then signals the frontend a HW frame is ready via g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, width, height, 0). The frame-dupe (NULL) path for runahead / fast-forward video skip is identical to the D3D11 and SW renderer paths. The CreateTexture / BeginSetDisplayPixels / EndSetDisplayPixels paths return nullptr / false the same way LibretroHostDisplay does. They are not exercised on the libretro D3D12 path - GPU_HW _D3D12 owns its own D3D12::Texture instances directly, and the SW renderer (which is the only path that would BeginSetDisplay Pixels) uses LibretroHostDisplay rather than going through D3D12. An m_framebuffer member is reserved on the class for future software-cursor / lightgun-crosshair overlay work (which would composite over the display texture in an owned RTV before set_texture, the way gpu_hw_d3d11.cpp does it). For the initial wire-up the present path forwards the GPU_HW_D3D12 display texture directly. HAVE_D3D12 is #define'd before the libretro_d3d.h include to pull in the retro_hw_render_interface_d3d12 struct definition, matching the equivalent pattern in gpu_hw_d3d11.cpp. == src/libretro/libretro_host_interface.cpp == Four switch cases extended, all under #ifdef WIN32 + #ifdef USE _D3D12: - RetroHwContextToRenderer: maps RETRO_HW_CONTEXT_D3D12 = 9 to GPURenderer::HardwareD3D12 so the Auto-renderer path picks D3D12 when the frontend advertises it via GET_PREFERRED_HW_RENDER. - RenderAPIToRenderer: maps HostDisplay::RenderAPI::D3D12 to GPURenderer::HardwareD3D12 so reusing an existing hardware display across SwitchToHardwareRenderer rebinds correctly. - RequestHardwareRendererContext: calls LibretroD3D12HostDisplay::RequestHardwareRendererContext (sets context_type=RETRO_HW_CONTEXT_D3D12, version_major=12, version_minor=0). - SwitchToHardwareRenderer: instantiates LibretroD3D12HostDisplay when m_hw_render_callback.context_type indicates D3D12. Include line added for gpu_hw_d3d12.h alongside the existing gpu_hw_d3d11.h include. == src/libretro/libretro_core_options.h == Renderer dropdown gains {"D3D12", "Hardware (D3D12)"} entry, gated USE_D3D12 inside the existing WIN32 block. Settings ::ParseRendererName already had D3D12 in its s_gpu_renderer _names array (pre-existing), and Settings::GetRendererName reads from the same array, so the dropdown selection round-trips to/from GPURenderer::HardwareD3D12 correctly. == Makefile.libretro == Under the existing IS_WINDOWS guard, added a USE_D3D12=1 branch that: - Adds -DUSE_D3D12=1 to CXXFLAGS so the wiring under #ifdef USE _D3D12 in libretro_host_interface.cpp, libretro_core_options.h, gpu_hw_d3d12.cpp, and gpu_hw_d3d12.h gets compiled in. - Adds -ld3d12 to LDFLAGS so PFN_D3D12_SERIALIZE_ROOT_SIGNATURE resolves at link time (Context::SerializeRootSignature uses it). - Adds the seven common/d3d12 TUs (context, descriptor_heap_ manager, shader_cache, staging_texture, stream_buffer, texture, util) to SOURCES_CXX. - Adds src/core/gpu_hw_d3d12.cpp to SOURCES_CXX in the core section. Default (no USE_D3D12=1) keeps the existing Windows build unchanged. system.cpp's renderer dispatch already had the case GPURenderer::HardwareD3D12 case behind #ifdef USE_D3D12 and the forward declaration of GPU::CreateHardwareD3D12Renderer() was already in gpu.h, so no changes were needed there. == Build verification == Linux libretro build: clean, .so unchanged at 7,905,720 bytes (all new D3D12 code is gated under WIN32 + USE_D3D12 - no compiled-in effect on non-Windows targets), 25 retro_ exports preserved. Windows build with USE_D3D12=1 has not been verified in this environment - mingw cross-compile tools and the d3d12 SDK headers aren't available on the build host. Manual test on Windows required before pushing. 7 files changed, 414 insertions(+).
2026-05-14 23:07:01 +00:00
Makefile.libretro: compile D3D12 backend by default on Windows The previous wire-up commit (cf05cad) gated the D3D12 sources behind USE_D3D12=1 on the make command line. That gate had the side effect of leaving D3D12 entirely out of the default Windows build: - The seven common/d3d12 TUs were not compiled in - gpu_hw_d3d12.cpp was not compiled in - -ld3d12 was not on the link line - -DUSE_D3D12=1 was not in CXXFLAGS, so every #ifdef USE_D3D12 block in libretro_host_interface.cpp / libretro_core_options.h / gpu_hw_d3d12.h / gpu_hw_d3d12.cpp / system.cpp was inactive The user-visible consequence with a default Windows build: when RetroArch is set to the d3d12 video driver and the user starts the swanstation core, the auto-renderer path lands in RetroHwContextToRenderer() with retro_hw_context_type= RETRO_HW_CONTEXT_D3D12 (= 9), but the corresponding case label is #ifdef USE_D3D12'd out of the switch. The default branch returns std::nullopt, and RequestHardwareRendererContext falls back to DEFAULT_GPU_RENDERER which is HardwareD3D11. RetroArch's driver auto-switch logic then sees that the core requested a D3D11 context and silently switches its video driver from d3d12 to d3d11. The opt-in gate served no real purpose - d3d12.dll has shipped with every Windows 10 build and the mingw-w64 toolchain has had <d3d12.h> for years. The libretro frontend doesn't need to expose retro_hw_render_interface_d3d12 either; that determination happens at SET_HW_RENDER time and the existing m_hw_render_callback_valid =false fallback path handles a refusing frontend the same way it does for any other unsupported HW context type. Inline the D3D12 block into the existing IS_WINDOWS=1 guard so D3D12 compiles unconditionally on Windows alongside D3D11. The -DUSE_D3D12=1 define is still set the same way - so all of the #ifdef USE_D3D12 source-side gates keep working - but it no longer requires USE_D3D12=1 on the make command line. Both the common-section (src/common/d3d12/*.cpp) and the core- section (src/core/gpu_hw_d3d12.cpp) opt-in branches removed. == Build verification == make platform=win (no extra flags) now emits -DUSE_D3D12=1, links -ld3d12, and includes all eight d3d12 TUs. make platform=unix: clean, .so unchanged at 7,905,720 bytes, 25 retro_ exports preserved (IS_WINDOWS=0 skips the whole Windows block including the new always-on D3D12 lines). 1 file changed, 7 insertions(+), 14 deletions(-).
2026-05-14 23:13:09 +00:00
# Direct3D 12 backend - Windows only. d3d12 ships with Windows 10+ and
# the libretro frontend exposes it via retro_hw_render_interface_d3d12.
# Compiled in on every Windows build; the runtime requirement is just
# that RetroArch was built with D3D12 support and the user has the
# video driver set to d3d12 (or "Auto" with d3d12 preferred).
core, libretro, common: wire up D3D12 renderer for libretro Wires the existing D3D12 hardware renderer (src/core/gpu_hw_d3d12.cpp, src/common/d3d12/*) into the libretro frontend, behind a USE_D3D12=1 gate. The opt-in is because: 1. retro_hw_render_interface_d3d12 is supported by recent RetroArch builds but not all of them - the SET_HW_RENDER environment call will fail at runtime where unsupported. 2. Not every Windows target ships d3d12.lib in its toolchain; the gate keeps the existing default Windows build path working. When USE_D3D12=1 is set on the make command line, the libretro Makefile pulls in the seven common/d3d12 TUs, gpu_hw_d3d12.cpp, the new LibretroD3D12HostDisplay class, links against d3d12.lib, and exposes "D3D12" in the renderer dropdown next to D3D11. == src/common/d3d12 == D3D12::Context grew a CreateForLibretro(device, command_queue) static factory next to its existing Create(dxgi_factory, ...). The libretro path adopts the frontend's device + command queue (the frontend retains ownership; we just AddRef them via ComPtr) and then creates only the resources we own: fence, descriptor heaps, command lists, texture upload stream buffer. Feature level is pinned at FL11_0; the gpu_hw_d3d12 shader/PSO setup targets that baseline. CreateForLibretro still loads d3d12.dll because PFN_D3D12_SERIALIZE_ROOT_SIGNATURE is needed by Context::SerializeRootSignature, which gpu_hw_d3d12.cpp uses on initial root-signature creation. Destroy() is unchanged; the borrowed device/queue ComPtrs simply release their AddRef in the Context destructor and the frontend keeps the underlying objects alive. == src/core/gpu_hw_d3d12.h, .cpp == Added LibretroD3D12HostDisplay (declaration in the header above GPU_HW_D3D12, implementation appended ahead of GPU_HW_D3D12's constructor body in the .cpp). The class mirrors LibretroD3D11HostDisplay's surface and behaves identically on the libretro-API side, with two differences driven by the D3D12 libretro interface contract: 1. There is no analogue to ID3D11DeviceContext in D3D12 - work is recorded on command lists owned by D3D12::Context. The class therefore does not store m_device / m_context members; callers that need the device go through g_d3d12_context->GetDevice() as the rest of gpu_hw_d3d12.cpp already does. GetRenderDevice() returns g_d3d12_context->GetDevice() for HostDisplay-API callers; GetRenderContext() returns nullptr. 2. Present is the retro_hw_render_interface_d3d12::set_texture callback rather than a swapchain blit. LibretroD3D12HostDisplay ::Render() transitions the GPU_HW_D3D12-produced display texture into the frontend's required_state, flushes our pending command list via ExecuteCommandList(false), calls set_texture(frontend_handle, ID3D12Resource*, format), then signals the frontend a HW frame is ready via g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, width, height, 0). The frame-dupe (NULL) path for runahead / fast-forward video skip is identical to the D3D11 and SW renderer paths. The CreateTexture / BeginSetDisplayPixels / EndSetDisplayPixels paths return nullptr / false the same way LibretroHostDisplay does. They are not exercised on the libretro D3D12 path - GPU_HW _D3D12 owns its own D3D12::Texture instances directly, and the SW renderer (which is the only path that would BeginSetDisplay Pixels) uses LibretroHostDisplay rather than going through D3D12. An m_framebuffer member is reserved on the class for future software-cursor / lightgun-crosshair overlay work (which would composite over the display texture in an owned RTV before set_texture, the way gpu_hw_d3d11.cpp does it). For the initial wire-up the present path forwards the GPU_HW_D3D12 display texture directly. HAVE_D3D12 is #define'd before the libretro_d3d.h include to pull in the retro_hw_render_interface_d3d12 struct definition, matching the equivalent pattern in gpu_hw_d3d11.cpp. == src/libretro/libretro_host_interface.cpp == Four switch cases extended, all under #ifdef WIN32 + #ifdef USE _D3D12: - RetroHwContextToRenderer: maps RETRO_HW_CONTEXT_D3D12 = 9 to GPURenderer::HardwareD3D12 so the Auto-renderer path picks D3D12 when the frontend advertises it via GET_PREFERRED_HW_RENDER. - RenderAPIToRenderer: maps HostDisplay::RenderAPI::D3D12 to GPURenderer::HardwareD3D12 so reusing an existing hardware display across SwitchToHardwareRenderer rebinds correctly. - RequestHardwareRendererContext: calls LibretroD3D12HostDisplay::RequestHardwareRendererContext (sets context_type=RETRO_HW_CONTEXT_D3D12, version_major=12, version_minor=0). - SwitchToHardwareRenderer: instantiates LibretroD3D12HostDisplay when m_hw_render_callback.context_type indicates D3D12. Include line added for gpu_hw_d3d12.h alongside the existing gpu_hw_d3d11.h include. == src/libretro/libretro_core_options.h == Renderer dropdown gains {"D3D12", "Hardware (D3D12)"} entry, gated USE_D3D12 inside the existing WIN32 block. Settings ::ParseRendererName already had D3D12 in its s_gpu_renderer _names array (pre-existing), and Settings::GetRendererName reads from the same array, so the dropdown selection round-trips to/from GPURenderer::HardwareD3D12 correctly. == Makefile.libretro == Under the existing IS_WINDOWS guard, added a USE_D3D12=1 branch that: - Adds -DUSE_D3D12=1 to CXXFLAGS so the wiring under #ifdef USE _D3D12 in libretro_host_interface.cpp, libretro_core_options.h, gpu_hw_d3d12.cpp, and gpu_hw_d3d12.h gets compiled in. - Adds -ld3d12 to LDFLAGS so PFN_D3D12_SERIALIZE_ROOT_SIGNATURE resolves at link time (Context::SerializeRootSignature uses it). - Adds the seven common/d3d12 TUs (context, descriptor_heap_ manager, shader_cache, staging_texture, stream_buffer, texture, util) to SOURCES_CXX. - Adds src/core/gpu_hw_d3d12.cpp to SOURCES_CXX in the core section. Default (no USE_D3D12=1) keeps the existing Windows build unchanged. system.cpp's renderer dispatch already had the case GPURenderer::HardwareD3D12 case behind #ifdef USE_D3D12 and the forward declaration of GPU::CreateHardwareD3D12Renderer() was already in gpu.h, so no changes were needed there. == Build verification == Linux libretro build: clean, .so unchanged at 7,905,720 bytes (all new D3D12 code is gated under WIN32 + USE_D3D12 - no compiled-in effect on non-Windows targets), 25 retro_ exports preserved. Windows build with USE_D3D12=1 has not been verified in this environment - mingw cross-compile tools and the d3d12 SDK headers aren't available on the build host. Manual test on Windows required before pushing. 7 files changed, 414 insertions(+).
2026-05-14 23:07:01 +00:00
CXXFLAGS += -DUSE_D3D12=1
LDFLAGS += -ld3d12
SOURCES_CXX += \
$(COMMON_DIR)/d3d12/context.cpp \
$(COMMON_DIR)/d3d12/descriptor_heap_manager.cpp \
$(COMMON_DIR)/d3d12/shader_cache.cpp \
$(COMMON_DIR)/d3d12/staging_texture.cpp \
$(COMMON_DIR)/d3d12/stream_buffer.cpp \
$(COMMON_DIR)/d3d12/texture.cpp \
$(COMMON_DIR)/d3d12/util.cpp
endif
# ---------------------------------------------------------------------
# src/core
# ---------------------------------------------------------------------
CORE_SRC_DIR := $(SRC_DIR)/core
SOURCES_CXX += \
$(CORE_SRC_DIR)/analog_controller.cpp \
$(CORE_SRC_DIR)/analog_joystick.cpp \
$(CORE_SRC_DIR)/bios.cpp \
$(CORE_SRC_DIR)/bus.cpp \
$(CORE_SRC_DIR)/cdrom.cpp \
$(CORE_SRC_DIR)/cdrom_async_reader.cpp \
$(CORE_SRC_DIR)/cheats.cpp \
$(CORE_SRC_DIR)/controller.cpp \
$(CORE_SRC_DIR)/cpu_code_cache.cpp \
$(CORE_SRC_DIR)/cpu_core.cpp \
$(CORE_SRC_DIR)/cpu_types.cpp \
$(CORE_SRC_DIR)/digital_controller.cpp \
$(CORE_SRC_DIR)/dma.cpp \
$(CORE_SRC_DIR)/gpu.cpp \
$(CORE_SRC_DIR)/gpu_backend.cpp \
$(CORE_SRC_DIR)/gpu_commands.cpp \
$(CORE_SRC_DIR)/gpu_hw.cpp \
$(CORE_SRC_DIR)/gpu_hw_opengl.cpp \
$(CORE_SRC_DIR)/gpu_hw_shadergen.cpp \
$(CORE_SRC_DIR)/gpu_hw_vulkan.cpp \
$(CORE_SRC_DIR)/gpu_sw.cpp \
$(CORE_SRC_DIR)/gpu_sw_backend.cpp \
$(CORE_SRC_DIR)/gte.cpp \
$(CORE_SRC_DIR)/host_display.cpp \
$(CORE_SRC_DIR)/host_interface.cpp \
$(CORE_SRC_DIR)/host_interface_progress_callback.cpp \
$(CORE_SRC_DIR)/interrupt_controller.cpp \
$(CORE_SRC_DIR)/libcrypt_game_codes.cpp \
$(CORE_SRC_DIR)/mdec.cpp \
$(CORE_SRC_DIR)/memory_card.cpp \
$(CORE_SRC_DIR)/memory_card_image.cpp \
$(CORE_SRC_DIR)/multitap.cpp \
$(CORE_SRC_DIR)/namco_guncon.cpp \
$(CORE_SRC_DIR)/negcon.cpp \
$(CORE_SRC_DIR)/negcon_rumble.cpp \
$(CORE_SRC_DIR)/pad.cpp \
$(CORE_SRC_DIR)/pgxp.cpp \
$(CORE_SRC_DIR)/playstation_mouse.cpp \
$(CORE_SRC_DIR)/psf_loader.cpp \
$(CORE_SRC_DIR)/resources.cpp \
$(CORE_SRC_DIR)/settings.cpp \
$(CORE_SRC_DIR)/shadergen.cpp \
$(CORE_SRC_DIR)/sio.cpp \
$(CORE_SRC_DIR)/spu.cpp \
$(CORE_SRC_DIR)/system.cpp \
$(CORE_SRC_DIR)/texture_replacements.cpp \
$(CORE_SRC_DIR)/timers.cpp \
$(CORE_SRC_DIR)/timing_event.cpp
# D3D11 hardware GPU backend - Windows only.
ifeq ($(IS_WINDOWS),1)
SOURCES_CXX += $(CORE_SRC_DIR)/gpu_hw_d3d11.cpp
core, libretro, common: wire up D3D12 renderer for libretro Wires the existing D3D12 hardware renderer (src/core/gpu_hw_d3d12.cpp, src/common/d3d12/*) into the libretro frontend, behind a USE_D3D12=1 gate. The opt-in is because: 1. retro_hw_render_interface_d3d12 is supported by recent RetroArch builds but not all of them - the SET_HW_RENDER environment call will fail at runtime where unsupported. 2. Not every Windows target ships d3d12.lib in its toolchain; the gate keeps the existing default Windows build path working. When USE_D3D12=1 is set on the make command line, the libretro Makefile pulls in the seven common/d3d12 TUs, gpu_hw_d3d12.cpp, the new LibretroD3D12HostDisplay class, links against d3d12.lib, and exposes "D3D12" in the renderer dropdown next to D3D11. == src/common/d3d12 == D3D12::Context grew a CreateForLibretro(device, command_queue) static factory next to its existing Create(dxgi_factory, ...). The libretro path adopts the frontend's device + command queue (the frontend retains ownership; we just AddRef them via ComPtr) and then creates only the resources we own: fence, descriptor heaps, command lists, texture upload stream buffer. Feature level is pinned at FL11_0; the gpu_hw_d3d12 shader/PSO setup targets that baseline. CreateForLibretro still loads d3d12.dll because PFN_D3D12_SERIALIZE_ROOT_SIGNATURE is needed by Context::SerializeRootSignature, which gpu_hw_d3d12.cpp uses on initial root-signature creation. Destroy() is unchanged; the borrowed device/queue ComPtrs simply release their AddRef in the Context destructor and the frontend keeps the underlying objects alive. == src/core/gpu_hw_d3d12.h, .cpp == Added LibretroD3D12HostDisplay (declaration in the header above GPU_HW_D3D12, implementation appended ahead of GPU_HW_D3D12's constructor body in the .cpp). The class mirrors LibretroD3D11HostDisplay's surface and behaves identically on the libretro-API side, with two differences driven by the D3D12 libretro interface contract: 1. There is no analogue to ID3D11DeviceContext in D3D12 - work is recorded on command lists owned by D3D12::Context. The class therefore does not store m_device / m_context members; callers that need the device go through g_d3d12_context->GetDevice() as the rest of gpu_hw_d3d12.cpp already does. GetRenderDevice() returns g_d3d12_context->GetDevice() for HostDisplay-API callers; GetRenderContext() returns nullptr. 2. Present is the retro_hw_render_interface_d3d12::set_texture callback rather than a swapchain blit. LibretroD3D12HostDisplay ::Render() transitions the GPU_HW_D3D12-produced display texture into the frontend's required_state, flushes our pending command list via ExecuteCommandList(false), calls set_texture(frontend_handle, ID3D12Resource*, format), then signals the frontend a HW frame is ready via g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, width, height, 0). The frame-dupe (NULL) path for runahead / fast-forward video skip is identical to the D3D11 and SW renderer paths. The CreateTexture / BeginSetDisplayPixels / EndSetDisplayPixels paths return nullptr / false the same way LibretroHostDisplay does. They are not exercised on the libretro D3D12 path - GPU_HW _D3D12 owns its own D3D12::Texture instances directly, and the SW renderer (which is the only path that would BeginSetDisplay Pixels) uses LibretroHostDisplay rather than going through D3D12. An m_framebuffer member is reserved on the class for future software-cursor / lightgun-crosshair overlay work (which would composite over the display texture in an owned RTV before set_texture, the way gpu_hw_d3d11.cpp does it). For the initial wire-up the present path forwards the GPU_HW_D3D12 display texture directly. HAVE_D3D12 is #define'd before the libretro_d3d.h include to pull in the retro_hw_render_interface_d3d12 struct definition, matching the equivalent pattern in gpu_hw_d3d11.cpp. == src/libretro/libretro_host_interface.cpp == Four switch cases extended, all under #ifdef WIN32 + #ifdef USE _D3D12: - RetroHwContextToRenderer: maps RETRO_HW_CONTEXT_D3D12 = 9 to GPURenderer::HardwareD3D12 so the Auto-renderer path picks D3D12 when the frontend advertises it via GET_PREFERRED_HW_RENDER. - RenderAPIToRenderer: maps HostDisplay::RenderAPI::D3D12 to GPURenderer::HardwareD3D12 so reusing an existing hardware display across SwitchToHardwareRenderer rebinds correctly. - RequestHardwareRendererContext: calls LibretroD3D12HostDisplay::RequestHardwareRendererContext (sets context_type=RETRO_HW_CONTEXT_D3D12, version_major=12, version_minor=0). - SwitchToHardwareRenderer: instantiates LibretroD3D12HostDisplay when m_hw_render_callback.context_type indicates D3D12. Include line added for gpu_hw_d3d12.h alongside the existing gpu_hw_d3d11.h include. == src/libretro/libretro_core_options.h == Renderer dropdown gains {"D3D12", "Hardware (D3D12)"} entry, gated USE_D3D12 inside the existing WIN32 block. Settings ::ParseRendererName already had D3D12 in its s_gpu_renderer _names array (pre-existing), and Settings::GetRendererName reads from the same array, so the dropdown selection round-trips to/from GPURenderer::HardwareD3D12 correctly. == Makefile.libretro == Under the existing IS_WINDOWS guard, added a USE_D3D12=1 branch that: - Adds -DUSE_D3D12=1 to CXXFLAGS so the wiring under #ifdef USE _D3D12 in libretro_host_interface.cpp, libretro_core_options.h, gpu_hw_d3d12.cpp, and gpu_hw_d3d12.h gets compiled in. - Adds -ld3d12 to LDFLAGS so PFN_D3D12_SERIALIZE_ROOT_SIGNATURE resolves at link time (Context::SerializeRootSignature uses it). - Adds the seven common/d3d12 TUs (context, descriptor_heap_ manager, shader_cache, staging_texture, stream_buffer, texture, util) to SOURCES_CXX. - Adds src/core/gpu_hw_d3d12.cpp to SOURCES_CXX in the core section. Default (no USE_D3D12=1) keeps the existing Windows build unchanged. system.cpp's renderer dispatch already had the case GPURenderer::HardwareD3D12 case behind #ifdef USE_D3D12 and the forward declaration of GPU::CreateHardwareD3D12Renderer() was already in gpu.h, so no changes were needed there. == Build verification == Linux libretro build: clean, .so unchanged at 7,905,720 bytes (all new D3D12 code is gated under WIN32 + USE_D3D12 - no compiled-in effect on non-Windows targets), 25 retro_ exports preserved. Windows build with USE_D3D12=1 has not been verified in this environment - mingw cross-compile tools and the d3d12 SDK headers aren't available on the build host. Manual test on Windows required before pushing. 7 files changed, 414 insertions(+).
2026-05-14 23:07:01 +00:00
Makefile.libretro: compile D3D12 backend by default on Windows The previous wire-up commit (cf05cad) gated the D3D12 sources behind USE_D3D12=1 on the make command line. That gate had the side effect of leaving D3D12 entirely out of the default Windows build: - The seven common/d3d12 TUs were not compiled in - gpu_hw_d3d12.cpp was not compiled in - -ld3d12 was not on the link line - -DUSE_D3D12=1 was not in CXXFLAGS, so every #ifdef USE_D3D12 block in libretro_host_interface.cpp / libretro_core_options.h / gpu_hw_d3d12.h / gpu_hw_d3d12.cpp / system.cpp was inactive The user-visible consequence with a default Windows build: when RetroArch is set to the d3d12 video driver and the user starts the swanstation core, the auto-renderer path lands in RetroHwContextToRenderer() with retro_hw_context_type= RETRO_HW_CONTEXT_D3D12 (= 9), but the corresponding case label is #ifdef USE_D3D12'd out of the switch. The default branch returns std::nullopt, and RequestHardwareRendererContext falls back to DEFAULT_GPU_RENDERER which is HardwareD3D11. RetroArch's driver auto-switch logic then sees that the core requested a D3D11 context and silently switches its video driver from d3d12 to d3d11. The opt-in gate served no real purpose - d3d12.dll has shipped with every Windows 10 build and the mingw-w64 toolchain has had <d3d12.h> for years. The libretro frontend doesn't need to expose retro_hw_render_interface_d3d12 either; that determination happens at SET_HW_RENDER time and the existing m_hw_render_callback_valid =false fallback path handles a refusing frontend the same way it does for any other unsupported HW context type. Inline the D3D12 block into the existing IS_WINDOWS=1 guard so D3D12 compiles unconditionally on Windows alongside D3D11. The -DUSE_D3D12=1 define is still set the same way - so all of the #ifdef USE_D3D12 source-side gates keep working - but it no longer requires USE_D3D12=1 on the make command line. Both the common-section (src/common/d3d12/*.cpp) and the core- section (src/core/gpu_hw_d3d12.cpp) opt-in branches removed. == Build verification == make platform=win (no extra flags) now emits -DUSE_D3D12=1, links -ld3d12, and includes all eight d3d12 TUs. make platform=unix: clean, .so unchanged at 7,905,720 bytes, 25 retro_ exports preserved (IS_WINDOWS=0 skips the whole Windows block including the new always-on D3D12 lines). 1 file changed, 7 insertions(+), 14 deletions(-).
2026-05-14 23:13:09 +00:00
# D3D12 hardware GPU backend - Windows only (see common-section comment).
core, libretro, common: wire up D3D12 renderer for libretro Wires the existing D3D12 hardware renderer (src/core/gpu_hw_d3d12.cpp, src/common/d3d12/*) into the libretro frontend, behind a USE_D3D12=1 gate. The opt-in is because: 1. retro_hw_render_interface_d3d12 is supported by recent RetroArch builds but not all of them - the SET_HW_RENDER environment call will fail at runtime where unsupported. 2. Not every Windows target ships d3d12.lib in its toolchain; the gate keeps the existing default Windows build path working. When USE_D3D12=1 is set on the make command line, the libretro Makefile pulls in the seven common/d3d12 TUs, gpu_hw_d3d12.cpp, the new LibretroD3D12HostDisplay class, links against d3d12.lib, and exposes "D3D12" in the renderer dropdown next to D3D11. == src/common/d3d12 == D3D12::Context grew a CreateForLibretro(device, command_queue) static factory next to its existing Create(dxgi_factory, ...). The libretro path adopts the frontend's device + command queue (the frontend retains ownership; we just AddRef them via ComPtr) and then creates only the resources we own: fence, descriptor heaps, command lists, texture upload stream buffer. Feature level is pinned at FL11_0; the gpu_hw_d3d12 shader/PSO setup targets that baseline. CreateForLibretro still loads d3d12.dll because PFN_D3D12_SERIALIZE_ROOT_SIGNATURE is needed by Context::SerializeRootSignature, which gpu_hw_d3d12.cpp uses on initial root-signature creation. Destroy() is unchanged; the borrowed device/queue ComPtrs simply release their AddRef in the Context destructor and the frontend keeps the underlying objects alive. == src/core/gpu_hw_d3d12.h, .cpp == Added LibretroD3D12HostDisplay (declaration in the header above GPU_HW_D3D12, implementation appended ahead of GPU_HW_D3D12's constructor body in the .cpp). The class mirrors LibretroD3D11HostDisplay's surface and behaves identically on the libretro-API side, with two differences driven by the D3D12 libretro interface contract: 1. There is no analogue to ID3D11DeviceContext in D3D12 - work is recorded on command lists owned by D3D12::Context. The class therefore does not store m_device / m_context members; callers that need the device go through g_d3d12_context->GetDevice() as the rest of gpu_hw_d3d12.cpp already does. GetRenderDevice() returns g_d3d12_context->GetDevice() for HostDisplay-API callers; GetRenderContext() returns nullptr. 2. Present is the retro_hw_render_interface_d3d12::set_texture callback rather than a swapchain blit. LibretroD3D12HostDisplay ::Render() transitions the GPU_HW_D3D12-produced display texture into the frontend's required_state, flushes our pending command list via ExecuteCommandList(false), calls set_texture(frontend_handle, ID3D12Resource*, format), then signals the frontend a HW frame is ready via g_retro_video_refresh_callback(RETRO_HW_FRAME_BUFFER_VALID, width, height, 0). The frame-dupe (NULL) path for runahead / fast-forward video skip is identical to the D3D11 and SW renderer paths. The CreateTexture / BeginSetDisplayPixels / EndSetDisplayPixels paths return nullptr / false the same way LibretroHostDisplay does. They are not exercised on the libretro D3D12 path - GPU_HW _D3D12 owns its own D3D12::Texture instances directly, and the SW renderer (which is the only path that would BeginSetDisplay Pixels) uses LibretroHostDisplay rather than going through D3D12. An m_framebuffer member is reserved on the class for future software-cursor / lightgun-crosshair overlay work (which would composite over the display texture in an owned RTV before set_texture, the way gpu_hw_d3d11.cpp does it). For the initial wire-up the present path forwards the GPU_HW_D3D12 display texture directly. HAVE_D3D12 is #define'd before the libretro_d3d.h include to pull in the retro_hw_render_interface_d3d12 struct definition, matching the equivalent pattern in gpu_hw_d3d11.cpp. == src/libretro/libretro_host_interface.cpp == Four switch cases extended, all under #ifdef WIN32 + #ifdef USE _D3D12: - RetroHwContextToRenderer: maps RETRO_HW_CONTEXT_D3D12 = 9 to GPURenderer::HardwareD3D12 so the Auto-renderer path picks D3D12 when the frontend advertises it via GET_PREFERRED_HW_RENDER. - RenderAPIToRenderer: maps HostDisplay::RenderAPI::D3D12 to GPURenderer::HardwareD3D12 so reusing an existing hardware display across SwitchToHardwareRenderer rebinds correctly. - RequestHardwareRendererContext: calls LibretroD3D12HostDisplay::RequestHardwareRendererContext (sets context_type=RETRO_HW_CONTEXT_D3D12, version_major=12, version_minor=0). - SwitchToHardwareRenderer: instantiates LibretroD3D12HostDisplay when m_hw_render_callback.context_type indicates D3D12. Include line added for gpu_hw_d3d12.h alongside the existing gpu_hw_d3d11.h include. == src/libretro/libretro_core_options.h == Renderer dropdown gains {"D3D12", "Hardware (D3D12)"} entry, gated USE_D3D12 inside the existing WIN32 block. Settings ::ParseRendererName already had D3D12 in its s_gpu_renderer _names array (pre-existing), and Settings::GetRendererName reads from the same array, so the dropdown selection round-trips to/from GPURenderer::HardwareD3D12 correctly. == Makefile.libretro == Under the existing IS_WINDOWS guard, added a USE_D3D12=1 branch that: - Adds -DUSE_D3D12=1 to CXXFLAGS so the wiring under #ifdef USE _D3D12 in libretro_host_interface.cpp, libretro_core_options.h, gpu_hw_d3d12.cpp, and gpu_hw_d3d12.h gets compiled in. - Adds -ld3d12 to LDFLAGS so PFN_D3D12_SERIALIZE_ROOT_SIGNATURE resolves at link time (Context::SerializeRootSignature uses it). - Adds the seven common/d3d12 TUs (context, descriptor_heap_ manager, shader_cache, staging_texture, stream_buffer, texture, util) to SOURCES_CXX. - Adds src/core/gpu_hw_d3d12.cpp to SOURCES_CXX in the core section. Default (no USE_D3D12=1) keeps the existing Windows build unchanged. system.cpp's renderer dispatch already had the case GPURenderer::HardwareD3D12 case behind #ifdef USE_D3D12 and the forward declaration of GPU::CreateHardwareD3D12Renderer() was already in gpu.h, so no changes were needed there. == Build verification == Linux libretro build: clean, .so unchanged at 7,905,720 bytes (all new D3D12 code is gated under WIN32 + USE_D3D12 - no compiled-in effect on non-Windows targets), 25 retro_ exports preserved. Windows build with USE_D3D12=1 has not been verified in this environment - mingw cross-compile tools and the d3d12 SDK headers aren't available on the build host. Manual test on Windows required before pushing. 7 files changed, 414 insertions(+).
2026-05-14 23:07:01 +00:00
SOURCES_CXX += $(CORE_SRC_DIR)/gpu_hw_d3d12.cpp
endif
# Recompiler back-ends: shared TUs + per-arch TU.
ifeq ($(WITH_RECOMPILER),1)
SOURCES_CXX += \
$(CORE_SRC_DIR)/cpu_recompiler_code_generator.cpp \
$(CORE_SRC_DIR)/cpu_recompiler_code_generator_generic.cpp \
$(CORE_SRC_DIR)/cpu_recompiler_register_cache.cpp
ifeq ($(CPU_ARCH),x64)
SOURCES_CXX += $(CORE_SRC_DIR)/cpu_recompiler_code_generator_x64.cpp
endif
ifeq ($(CPU_ARCH),aarch64)
SOURCES_CXX += $(CORE_SRC_DIR)/cpu_recompiler_code_generator_aarch64.cpp
endif
ifeq ($(CPU_ARCH),aarch32)
SOURCES_CXX += $(CORE_SRC_DIR)/cpu_recompiler_code_generator_aarch32.cpp
endif
endif
# ---------------------------------------------------------------------
# src/libretro
# ---------------------------------------------------------------------
LIBRETRO_SRC_DIR := $(SRC_DIR)/libretro
SOURCES_CXX += \
$(LIBRETRO_SRC_DIR)/libretro_audio_stream.cpp \
$(LIBRETRO_SRC_DIR)/libretro_game_settings.cpp \
$(LIBRETRO_SRC_DIR)/libretro_host_display.cpp \
$(LIBRETRO_SRC_DIR)/libretro_host_interface.cpp \
$(LIBRETRO_SRC_DIR)/libretro_settings_interface.cpp
# ---------------------------------------------------------------------
# dep/libretro-common
# ---------------------------------------------------------------------
SOURCES_C += \
$(LIBRETRO_COMM_DIR)/compat/compat_posix_string.c \
$(LIBRETRO_COMM_DIR)/compat/compat_strl.c \
$(LIBRETRO_COMM_DIR)/compat/fopen_utf8.c \
$(LIBRETRO_COMM_DIR)/encodings/encoding_utf.c \
$(LIBRETRO_COMM_DIR)/file/file_path.c \
$(LIBRETRO_COMM_DIR)/file/file_path_io.c \
$(LIBRETRO_COMM_DIR)/streams/file_stream.c \
$(LIBRETRO_COMM_DIR)/string/stdstring.c \
$(LIBRETRO_COMM_DIR)/time/rtime.c \
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.c
# ---------------------------------------------------------------------
# dep/glad - OpenGL loader
# ---------------------------------------------------------------------
SOURCES_C += $(GLAD_DIR)/src/glad.c
ifeq ($(IS_WINDOWS),1)
SOURCES_C += $(GLAD_DIR)/src/glad_wgl.c
endif
# ---------------------------------------------------------------------
# dep/stb
# ---------------------------------------------------------------------
SOURCES_C += \
$(STB_DIR)/src/stb_image.c \
$(STB_DIR)/src/stb_image_resize.c
# ---------------------------------------------------------------------
# dep/xxhash
# ---------------------------------------------------------------------
SOURCES_C += $(XXHASH_DIR)/src/xxhash.c
ifneq (,$(filter $(CPU_ARCH),x86 x64))
SOURCES_C += $(XXHASH_DIR)/src/xxh_x86dispatch.c
FLAGS += -DXXH_X86DISPATCH_ALLOW_AVX
endif
# ---------------------------------------------------------------------
# dep/libchdr (and bundled lzma / miniz / zstd)
# ---------------------------------------------------------------------
SOURCES_C += \
$(LIBCHDR_DIR)/deps/lzma-25.01/src/LzmaDec.c \
$(LIBCHDR_DIR)/deps/miniz-3.1.1/miniz.c \
$(LIBCHDR_DIR)/deps/zstd-1.5.7/zstddeclib.c \
$(LIBCHDR_DIR)/src/libchdr_bitstream.c \
$(LIBCHDR_DIR)/src/libchdr_cdrom.c \
$(LIBCHDR_DIR)/src/libchdr_chd.c \
$(LIBCHDR_DIR)/src/libchdr_codec_cdfl.c \
$(LIBCHDR_DIR)/src/libchdr_codec_cdlz.c \
$(LIBCHDR_DIR)/src/libchdr_codec_cdzl.c \
$(LIBCHDR_DIR)/src/libchdr_codec_cdzs.c \
$(LIBCHDR_DIR)/src/libchdr_codec_flac.c \
$(LIBCHDR_DIR)/src/libchdr_codec_huff.c \
$(LIBCHDR_DIR)/src/libchdr_codec_lzma.c \
$(LIBCHDR_DIR)/src/libchdr_codec_zlib.c \
$(LIBCHDR_DIR)/src/libchdr_codec_zstd.c \
$(LIBCHDR_DIR)/src/libchdr_flac.c \
$(LIBCHDR_DIR)/src/libchdr_huffman.c
# ---------------------------------------------------------------------
# dep/vulkan-loader
# ---------------------------------------------------------------------
SOURCES_CXX += $(VULKAN_LOADER_DIR)/src/vulkan_loader.cpp
# ---------------------------------------------------------------------
# dep/glslang
# ---------------------------------------------------------------------
SOURCES_CXX += \
$(GLSLANG_DIR)/glslang/CInterface/glslang_c_interface.cpp \
$(GLSLANG_DIR)/glslang/GenericCodeGen/CodeGen.cpp \
$(GLSLANG_DIR)/glslang/GenericCodeGen/Link.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/attribute.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/Constant.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/glslang_tab.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/InfoSink.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/Initialize.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/Intermediate.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/intermOut.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/IntermTraverse.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/iomapper.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/limits.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/linkValidate.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/parseConst.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/ParseContextBase.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/ParseHelper.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/PoolAlloc.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/preprocessor/Pp.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/preprocessor/PpAtom.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/preprocessor/PpContext.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/preprocessor/PpScanner.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/preprocessor/PpTokens.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/propagateNoContraction.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/reflection.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/RemoveTree.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/Scan.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/ShaderLang.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/SymbolTable.cpp \
$(GLSLANG_DIR)/glslang/MachineIndependent/Versions.cpp \
$(GLSLANG_DIR)/OGLCompilersDLL/InitializeDll.cpp \
$(GLSLANG_DIR)/SPIRV/disassemble.cpp \
$(GLSLANG_DIR)/SPIRV/doc.cpp \
$(GLSLANG_DIR)/SPIRV/GlslangToSpv.cpp \
$(GLSLANG_DIR)/SPIRV/InReadableOrder.cpp \
$(GLSLANG_DIR)/SPIRV/Logger.cpp \
$(GLSLANG_DIR)/SPIRV/SpvBuilder.cpp \
$(GLSLANG_DIR)/SPIRV/SpvPostProcess.cpp \
$(GLSLANG_DIR)/SPIRV/SPVRemapper.cpp \
$(GLSLANG_DIR)/SPIRV/SpvTools.cpp \
$(GLSLANG_DIR)/StandAlone/ResourceLimits.cpp \
$(GLSLANG_DIR)/StandAlone/resource_limits_c.cpp
# OS-specific glslang OS abstraction.
ifeq ($(IS_WINDOWS),1)
SOURCES_CXX += $(GLSLANG_DIR)/glslang/OSDependent/Windows/ossource.cpp
else
SOURCES_CXX += $(GLSLANG_DIR)/glslang/OSDependent/Unix/ossource.cpp
endif
# ---------------------------------------------------------------------
# dep/vixl - aarch32 / aarch64 only
# ---------------------------------------------------------------------
ifneq (,$(filter $(CPU_ARCH),aarch64 aarch32))
SOURCES_CC += \
$(VIXL_DIR)/src/code-buffer-vixl.cc \
$(VIXL_DIR)/src/compiler-intrinsics-vixl.cc \
$(VIXL_DIR)/src/cpu-features.cc \
$(VIXL_DIR)/src/utils-vixl.cc
endif
ifeq ($(CPU_ARCH),aarch64)
SOURCES_CC += \
$(VIXL_DIR)/src/aarch64/assembler-aarch64.cc \
$(VIXL_DIR)/src/aarch64/cpu-aarch64.cc \
$(VIXL_DIR)/src/aarch64/cpu-features-auditor-aarch64.cc \
$(VIXL_DIR)/src/aarch64/decoder-aarch64.cc \
$(VIXL_DIR)/src/aarch64/disasm-aarch64.cc \
$(VIXL_DIR)/src/aarch64/instructions-aarch64.cc \
$(VIXL_DIR)/src/aarch64/instrument-aarch64.cc \
$(VIXL_DIR)/src/aarch64/logic-aarch64.cc \
$(VIXL_DIR)/src/aarch64/macro-assembler-aarch64.cc \
$(VIXL_DIR)/src/aarch64/operands-aarch64.cc \
$(VIXL_DIR)/src/aarch64/pointer-auth-aarch64.cc \
$(VIXL_DIR)/src/aarch64/simulator-aarch64.cc
endif
ifeq ($(CPU_ARCH),aarch32)
SOURCES_CC += \
$(VIXL_DIR)/src/aarch32/assembler-aarch32.cc \
$(VIXL_DIR)/src/aarch32/constants-aarch32.cc \
$(VIXL_DIR)/src/aarch32/disasm-aarch32.cc \
$(VIXL_DIR)/src/aarch32/instructions-aarch32.cc \
$(VIXL_DIR)/src/aarch32/location-aarch32.cc \
$(VIXL_DIR)/src/aarch32/macro-assembler-aarch32.cc \
$(VIXL_DIR)/src/aarch32/operands-aarch32.cc
endif
# ---------------------------------------------------------------------
# Compile / link flags
# ---------------------------------------------------------------------
ifeq ($(DEBUG), 1)
CFLAGS += -O0 -g -DDEBUG -D_DEBUG -MMD
CXXFLAGS += -O0 -g -DDEBUG -D_DEBUG -MMD
else
CFLAGS += -O3 -DNDEBUG -MMD
CXXFLAGS += -O3 -DNDEBUG -MMD
endif
# Position-independent code and shared-library/visibility plumbing.
LDFLAGS += $(fpic) $(SHARED)
FLAGS += $(fpic)
# Hide non-`retro_` symbols, matching what the CMake build does.
FLAGS += -fvisibility=hidden
CXXFLAGS += -fvisibility-inlines-hidden
# Always-on libretro defines (this Makefile is libretro-only).
FLAGS += \
-DLIBRETRO=1 \
-D__LIBRETRO__ \
-D_FILE_OFFSET_BITS=64 \
-DUSE_LIBRETRO_VFS \
-DVIXL_CODE_BUFFER_MALLOC \
-DMINIZ_NO_ARCHIVE_APIS \
-DMINIZ_NO_DEFLATE_APIS \
-DMINIZ_NO_STDIO \
-DMINIZ_NO_TIME \
-DGIT_VERSION='"$(GIT_VERSION)"' \
-DGIT_HASH='"$(GIT_HASH)"' \
-DBUILD_DATE='"$(BUILD_DATE)"'
# Recompiler / fastmem flags - only when the host CPU has a JIT backend.
ifeq ($(WITH_RECOMPILER),1)
FLAGS += -DWITH_RECOMPILER=1
endif
ifeq ($(WITH_MMAP_FASTMEM),1)
FLAGS += -DWITH_MMAP_FASTMEM=1
endif
# vixl needs to know which target it is generating code for.
ifeq ($(CPU_ARCH),aarch64)
FLAGS += -DVIXL_INCLUDE_TARGET_A64
endif
ifeq ($(CPU_ARCH),aarch32)
FLAGS += -DVIXL_INCLUDE_TARGET_A32
endif
FLAGS += $(INCFLAGS)
CFLAGS += $(FLAGS) -std=gnu11
CXXFLAGS += $(FLAGS) -std=gnu++17
# NOTE: Unlike Beetle PSX, swanstation does NOT build with
# -fno-exceptions. xbyak (the x64 recompiler backend) uses C++ throw to
# signal bad operand sizes; building with -fno-exceptions would turn
# every xbyak header inclusion into a hard error.
# Use semantic interposition off everywhere except Apple, mirroring CMake.
ifneq ($(platform), osx)
CFLAGS += -fno-semantic-interposition
CXXFLAGS += -fno-semantic-interposition
endif
# Sanitizer hook (optional)
ifneq ($(SANITIZER),)
CFLAGS := -fsanitize=$(SANITIZER) $(CFLAGS)
CXXFLAGS := -fsanitize=$(SANITIZER) $(CXXFLAGS)
LDFLAGS := -fsanitize=$(SANITIZER) $(LDFLAGS)
endif
# Host endianness opt-in.
#
# All currently-supported targets (x86, x64, AArch32 LE, AArch64 LE) are
# little-endian. swanstation does not autodetect byte order and does
# not define a positive marker for the LE case - little-endian is the
# unmarked default. If you are porting to a big-endian host, build with
# `make ... MSB_FIRST=1` and the code's `#ifdef MSB_FIRST` branches
# will activate.
ifeq ($(MSB_FIRST),1)
CFLAGS += -DMSB_FIRST=1
CXXFLAGS += -DMSB_FIRST=1
endif
# ---------------------------------------------------------------------
# Build rules
# ---------------------------------------------------------------------
OBJECTS := $(SOURCES_CXX:.cpp=.o) $(SOURCES_CC:.cc=.o) $(SOURCES_C:.c=.o)
DEPS := $(SOURCES_CXX:.cpp=.d) $(SOURCES_CC:.cc=.d) $(SOURCES_C:.c=.d)
LD = $(CXX)
.PHONY: all clean
all: $(TARGET)
-include $(DEPS)
# config.h and version.h are normally generated by CMake during configure.
# - config.h is generated from src/config.h.cmake; it carries the
# HAVE_MKSTEMP / HAVE_ALLOCA_H / HAVE_MALLOC_H autoconf-style flags
# used by src/common/{byte_stream,file_system}.cpp.
# - version.h is generated from src/libretro/version.h.in; the real
# GIT_* / BUILD_DATE strings are baked in via -D in $(FLAGS), so the
# stub just needs to exist and provide fallbacks if those defines are
# absent.
SRC_LIBRETRO_DIR := $(CORE_DIR)/src/libretro
# Pick the platform-appropriate alloca header. CMake checks for these
# at configure time via check_symbol_exists(); we can answer at make
# time because the host alloca header location is well-known.
ifeq ($(IS_WINDOWS),1)
CONFIG_HAVE_ALLOCA := /* Windows: alloca() lives in <malloc.h> */
CONFIG_HAVE_MALLOC := \#define HAVE_MALLOC_H
CONFIG_HAVE_ALLOCA_H :=
else ifeq ($(platform),osx)
# macOS provides <alloca.h>.
CONFIG_HAVE_ALLOCA_H := \#define HAVE_ALLOCA_H
CONFIG_HAVE_MALLOC :=
else
# Linux, *BSD, etc. provide <alloca.h>.
CONFIG_HAVE_ALLOCA_H := \#define HAVE_ALLOCA_H
CONFIG_HAVE_MALLOC :=
endif
# mkstemp() is available everywhere except Windows (MinGW does not
# expose it).
ifeq ($(IS_WINDOWS),1)
CONFIG_HAVE_MKSTEMP :=
else
CONFIG_HAVE_MKSTEMP := \#define HAVE_MKSTEMP
endif
$(SRC_DIR)/config.h:
@echo "GEN $@"
@printf '%s\n' \
'/* Auto-generated by static Makefile, do not edit. */' \
'#pragma once' \
'$(CONFIG_HAVE_MKSTEMP)' \
'$(CONFIG_HAVE_ALLOCA_H)' \
'$(CONFIG_HAVE_MALLOC)' > $@
$(SRC_LIBRETRO_DIR)/version.h:
@echo "GEN $@"
@printf '%s\n' \
'#pragma once' \
'#ifndef GIT_VERSION' \
'#define GIT_VERSION "unknown"' \
'#endif' \
'#ifndef GIT_HASH' \
'#define GIT_HASH "unknown"' \
'#endif' \
'#ifndef BUILD_DATE' \
'#define BUILD_DATE __DATE__ " " __TIME__' \
'#endif' > $@
# Order-only dependency: every object needs the generated headers in
# place but does not need to be rebuilt when their contents change.
$(OBJECTS): | $(SRC_DIR)/config.h $(SRC_LIBRETRO_DIR)/version.h
$(TARGET): $(OBJECTS)
@echo "LD $@"
$(LD) -o $@ $(OBJECTS) $(LDFLAGS)
%.o: %.cpp
@if [ "$(SILENT)" != "1" ]; then echo "CXX $<"; fi
$(CXX) -c -o $@ $< $(CXXFLAGS)
%.o: %.cc
@if [ "$(SILENT)" != "1" ]; then echo "CXX $<"; fi
$(CXX) -c -o $@ $< $(CXXFLAGS)
%.o: %.c
@if [ "$(SILENT)" != "1" ]; then echo "CC $<"; fi
$(CC) -c -o $@ $< $(CFLAGS)
clean:
@echo "Cleaning $(TARGET)"
@rm -f $(OBJECTS) $(DEPS) $(TARGET) \
$(SRC_DIR)/config.h $(SRC_LIBRETRO_DIR)/version.h