Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ Paths are placeholders: `<checkout>` is the repository, `<build>` the folder wit
`gta6rt_tls_host.dll`, `<work>` the work folder `make_game.py` writes, `<cache>` a folder for pipeline caches,
`<package>` the game's package folder and `<exe>` its executable. Under Wine, a Linux path is passed as `Z:<path>`.

## Check a translated shader pack

Before precompiling or starting the game, `gta6rt.exe --check-shader-pack [DIR]` checks the pack's mesh and
barycentric requirements against the GPU that `--run` would select with `LEONIDA_D3D12=vulkan` and the
same `LEONIDA_VK_DEVICE` setting. Omit `DIR` to use `LEONIDA_SHADERS` or the runtime's `shader_path.txt`.

```sh
wine <build>/gta6rt.exe --check-shader-pack 'Z:\path\to\work\shaders\spirv'
```

It reports missing GPU features, known native mesh/barycentric driver issues that `make_game.py` selects
fallbacks for, and translated fallbacks this runtime cannot use. It reads indexes only: no game files,
logical Vulkan device, pipeline compilation, or cache writes. Exit `0` means no mismatch was found, `1`
means blockers were found (even if some optional indexes could not be read), and `2` means the check
could not be completed and found no blockers. This does not verify SPIR-V files, shader interfaces,
other GPU requirements, or that the game will boot.

## Settings every platform needs

- **The title's hang watchdog.** The title exits on purpose (a write to address 0) when its main loop has not reported
Expand Down
9 changes: 3 additions & 6 deletions make_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
from shader_stage_manifest import shader_stems # noqa: E402
from replace_retry import replace as replace_retry # noqa: E402
from stale_build import newer_sources # noqa: E402
from vk_subgroup_info import native_shader_driver_issue # noqa: E402

VERSIONS = os.path.join(ROOT, "game")
STAGES = ["check", "shaders", "assets", "runtime", "pipelines"]
Expand Down Expand Up @@ -2029,10 +2030,6 @@ def barycentric_fallback_override():
return None


# VkDriverId of Intel's Windows Vulkan driver (igvk64.dll).
VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS = 5


def runtime_gpu_mesh_draws_crash():
"""True where the GPU the runtime would use is on Intel's Windows Vulkan driver with VK_EXT_mesh_shader: there
vkCmdDrawMeshTasksEXT crashes (0xC0000409 in igvk64.dll) for a mesh shader with a live push-constant load at
Expand All @@ -2042,8 +2039,8 @@ def runtime_gpu_mesh_draws_crash():
info = runtime_gpu_info()
if not info or "driver_id" not in info:
return None
return info.get("driver_id") == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS and \
info.get("mesh_in_supported_stages") is True
return info.get("mesh_in_supported_stages") is True and native_shader_driver_issue(
"mesh", info["driver_id"], info.get("vendor_id"), info.get("device_id"))


def runtime_gpu_max_push_constants():
Expand Down
2 changes: 2 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,8 @@ if(BUILD_TESTING)
add_test(NAME descriptor_table COMMAND descriptor_table_test)
add_executable(shader_library_test test/shader_library_test.cpp)
add_test(NAME shader_library COMMAND shader_library_test)
add_executable(shader_pack_check_test test/shader_pack_check_test.cpp)
add_test(NAME shader_pack_check COMMAND shader_pack_check_test)
add_executable(native_pso_blend_test test/native_pso_blend_test.cpp)
add_test(NAME native_pso_blend COMMAND native_pso_blend_test)
add_executable(native_pso_depth_test test/native_pso_depth_test.cpp)
Expand Down
11 changes: 11 additions & 0 deletions runtime/shims/d3d12_shader_pack_check.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <filesystem>

namespace rt::d3d12 {

// Uses the same Vulkan adapter selection as --run, without creating a logical device. An empty directory uses
// LEONIDA_SHADERS or shader_path.txt. Returns 0 for no known mismatch, 1 for blockers, 2 for an incomplete check.
int check_shader_pack(const std::filesystem::path& directory);

} // namespace rt::d3d12
86 changes: 79 additions & 7 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "d3d12_compile_exit.h"
#include "d3d12_pipeline_compile.h"
#include "d3d12_precompile.h"
#include "d3d12_shader_pack_check.h"
#include "d3d12_compile_helper.h"
#include "d3d12_pipeline_checkpoint.h"
#include "d3d12_feature_compat.h"
Expand Down Expand Up @@ -57,6 +58,7 @@
#include "../src/resource_detile.h"
#include "../src/console_texture_layout.h"
#include "../src/shader_library.h"
#include "../src/shader_pack_check.h"
#include "../src/shadow_keep.h"
#include "../src/dstorage_trace.h"
#include "../src/title_page_watch.h"
Expand Down Expand Up @@ -21494,13 +21496,19 @@ HRESULT create_dxgi_factory(ID3D12Device* device, REFIID riid, void** out) {
i.queue_family, riid, out);
}

// Creates its own Vulkan instance and a Vulkan 1.3 device, or a 1.2 device with VK_KHR_dynamic_rendering and
// VK_KHR_synchronization2 (vulkan13_features.h). LEONIDA_VK_VALIDATION=1 adds VK_LAYER_KHRONOS_validation.
HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettings queue_test_settings) {
if (!out) return E_POINTER;
*out = nullptr;
struct ShaderPackProbe {
leonida::ShaderPackDevice device;
char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE]{};
};

// Creates its own Vulkan instance and device (or probes the same selected GPU and stops before the logical device).
// LEONIDA_VK_VALIDATION=1 adds VK_LAYER_KHRONOS_validation.
static HRESULT open_vulkan_standalone(REFIID riid, void** out, QueueTestSettings queue_test_settings,
ShaderPackProbe* probe) {
if (!probe && !out) return E_POINTER;
if (out) *out = nullptr;
// LEONIDA_AFTERMATH=1: GPU crash dumps on before the Vulkan instance and device exist (src/vulkan_aftermath.h).
leonida::aftermath::enable();
if (!probe) leonida::aftermath::enable();
static const HMODULE library = LoadLibraryA("vulkan-1.dll");
const auto get = library ? reinterpret_cast<PFN_vkGetInstanceProcAddr>(
reinterpret_cast<void*>(GetProcAddress(library, "vkGetInstanceProcAddr")))
Expand Down Expand Up @@ -21607,7 +21615,7 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
instance_info.enabledExtensionCount = static_cast<std::uint32_t>(inst_exts.size());
instance_info.ppEnabledExtensionNames = inst_exts.empty() ? nullptr : inst_exts.data();
OwnedRuntime owned{};
if (create_instance(&instance_info, nullptr, &owned.instance) != VK_SUCCESS) {
if (!create_instance || create_instance(&instance_info, nullptr, &owned.instance) != VK_SUCCESS) {
std::fprintf(stderr, "[rt] d3d12: vkCreateInstance (Vulkan 1.3) failed\n");
return E_FAIL;
}
Expand Down Expand Up @@ -22044,6 +22052,19 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
*v13.next() = &barycentric;
}
}
if (probe) {
VkPhysicalDeviceDriverProperties driver{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES};
VkPhysicalDeviceSubgroupProperties subgroup{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES, &driver};
VkPhysicalDeviceProperties2 properties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &subgroup};
vkGetPhysicalDeviceProperties2(info.physical, &properties);
// make_game's mesh policy also requires mesh in the supported subgroup stages.
probe->device = leonida::shader_pack_device(info.mesh_shader, info.fragment_shader_barycentric,
(subgroup.supportedStages & VK_SHADER_STAGE_MESH_BIT_EXT) != 0,
driver.driverID, chosen.vendorID, chosen.deviceID);
std::memcpy(probe->name, chosen.deviceName, sizeof(probe->name));
owned.destroy_instance(owned.instance, nullptr);
return S_OK;
}
VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT interlock{
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT};
if (has_device_extension(VK_EXT_FRAGMENT_SHADER_INTERLOCK_EXTENSION_NAME)) {
Expand Down Expand Up @@ -22411,6 +22432,57 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
return hand_out(device, riid, out);
}

HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettings queue_test_settings) {
return open_vulkan_standalone(riid, out, queue_test_settings, nullptr);
}

int check_shader_pack(const std::filesystem::path& directory) {
std::string error;
const auto root = directory.empty() ? configured_shader_directory(&error) : directory;
if (root.empty()) {
std::fprintf(stderr, "[shader-pack] no shader directory: %s\n", error.c_str());
return 2;
}
ShaderPackProbe probe;
if (FAILED(open_vulkan_standalone(__uuidof(ID3D12Device), nullptr, QueueTestSettings::ignore, &probe))) {
std::fprintf(stderr, "[shader-pack] could not probe the Vulkan device\n");
return 2;
}
std::printf("[shader-pack] Vulkan device: %s (native mesh: %s, native barycentrics: %s)\n", probe.name,
probe.device.native_mesh ? "yes" : "no", probe.device.native_barycentric ? "yes" : "no");
leonida::ShaderPackCheck report;
if (!leonida::check_shader_pack(root, probe.device, report, error)) {
std::fprintf(stderr, "[shader-pack] %s\n", error.c_str());
return 2;
}
for (const auto& issue : report.optional_index_errors)
std::fprintf(stderr, "[shader-pack] incomplete scan: %s\n", issue.c_str());
if (report.native_mesh_missing)
std::printf("[shader-pack] %zu mesh modules need VK_EXT_mesh_shader / meshShader, unavailable on this GPU\n",
report.native_mesh_missing);
if (report.native_mesh_driver_blocked)
std::printf("[shader-pack] %zu native mesh modules match a known driver issue (mesh draws can crash)\n",
report.native_mesh_driver_blocked);
if (report.mesh_compute_unimplemented)
std::printf("[shader-pack] %zu mesh modules were translated to compute, but this runtime cannot replay them\n",
report.mesh_compute_unimplemented);
if (report.native_barycentric_missing)
std::printf("[shader-pack] %zu pixel modules need fragmentShaderBarycentric, unavailable on this GPU\n",
report.native_barycentric_missing);
if (report.native_barycentric_driver_blocked)
std::printf("[shader-pack] %zu native barycentric modules match a known driver issue (barycentrics can be incorrect)\n",
report.native_barycentric_driver_blocked);
if (report.barycentric_fallback_unimplemented)
std::printf("[shader-pack] %zu pixel modules need the barycentric fallback, not implemented in this runtime\n",
report.barycentric_fallback_unimplemented);
if (report.unknown)
std::printf("[shader-pack] %zu entries have missing or malformed stage or mesh/barycentric metadata\n", report.unknown);
std::printf("[shader-pack] %zu indexed modules: %s. Metadata only; no pipelines tested.\n", report.indexed,
report.blocked() ? "mesh/barycentric blockers found"
: report.exit_code() ? "incomplete check" : "no known mesh/barycentric mismatch");
return report.exit_code();
}

// A Vulkan device made as `gta6rt --run` makes it, for building the library's compute pipelines with no title
// (--precompile-pipelines, --compile-server), with the two layouts create_compute makes.
class BuildHost {
Expand Down
11 changes: 11 additions & 0 deletions runtime/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
// does not stall it. Resumable: entries already journaled are skipped (--all: built anyway). Programs named by
// LEONIDA_SKIP_COMPUTE are built too unless --skip-listed is given. See shims/d3d12_precompile.h.
//
// gta6rt --check-shader-pack [DIR]
// Checks mesh and barycentric index metadata against the Vulkan GPU selected by --run. No game or pipelines.
//
// gta6rt --run <exe> [--game-dir DIR] [--overlay DIR] [--trace-d3d12] [--trace FILE] [-- game arguments...]
// The same, then the EXE's own TLS callbacks and its entry point, on a game thread. The game's argv and
// command line are <exe name> plus the arguments after "--"; exit/ExitProcess from the game end the run
Expand All @@ -33,6 +36,7 @@
#include <map>
#include <mutex>
#include <string>
#include <string_view>
#include <system_error>
#include <vector>

Expand Down Expand Up @@ -194,6 +198,7 @@ void start_title_peek(std::uint8_t* base) {
#include "vulkan_device_fault.h"
#include "../shims/d3d12_compile_exit.h"
#include "../shims/d3d12_precompile.h"
#include "../shims/d3d12_shader_pack_check.h"
#include "../shims/package_splash.h"
#endif
#include "../shims/process_shim.h"
Expand Down Expand Up @@ -263,6 +268,7 @@ int usage() {
" gta6rt --first-run-ui <exe> [--game-dir DIR] [--overlay DIR] [--trace FILE]\n"
" gta6rt --run <exe> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE] [-- game arguments...]\n"
" gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--big-bytes N] [--all] [--smallest-first] [--limit N] [--min-bytes N] [--max-bytes N] [--filter PART]... [--skip-listed] [--list] [--via-helper]\n"
" gta6rt --check-shader-pack [DIR]\n"
" gta6rt --compile-server [--parent PID] [--threads N] [--idle-threads N] [--idle-exit SECONDS]\n");
return 2;
}
Expand Down Expand Up @@ -387,6 +393,11 @@ static BOOL WINAPI show_package_window(HWND window, int command) {

int wmain(int argc, wchar_t** argv) {
#ifdef LEONIDA_VULKAN_DEVICE
if (argc > 1 && std::wstring_view(argv[1]) == L"--check-shader-pack") {
if (argc == 2) return rt::d3d12::check_shader_pack({});
if (argc != 3 || !*argv[2] || std::wstring_view(argv[2]).starts_with(L"--")) return usage();
return rt::d3d12::check_shader_pack(argv[2]);
}
if (argc > 1 && std::wstring(argv[1]) == L"--precompile-pipelines") return precompile_main(argc, argv);
if (argc > 1 && std::wstring(argv[1]) == L"--compile-server") return compile_server_main(argc, argv);
#endif
Expand Down
12 changes: 12 additions & 0 deletions runtime/src/shader_driver_rules.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Native shader paths that need a translation fallback on a known driver. Shared with tools/vk_subgroup_info.py.
// Columns: path, VkDriverId, PCI vendor ID, PCI device ID. Zero in a PCI column matches any ID.
// BUILD-2202: Intel Windows mesh draws crash on the corpus's live push-constant loads.
LEONIDA_SHADER_DRIVER_RULE(mesh, 5, 0, 0)
// SHADER-925: Mesa ANV returns a zero BaryCoordKHR.i on Intel Arc.
LEONIDA_SHADER_DRIVER_RULE(barycentric, 6, 0, 0)
// AMD's proprietary Windows driver returns a wrong BaryCoordKHR component on gfx90c (#5933).
// These are amdgpu's CHIP_RENOIR PCI IDs (Renoir, Lucienne, Cezanne and Barcelo).
LEONIDA_SHADER_DRIVER_RULE(barycentric, 1, 0x1002, 0x15E7)
LEONIDA_SHADER_DRIVER_RULE(barycentric, 1, 0x1002, 0x1636)
LEONIDA_SHADER_DRIVER_RULE(barycentric, 1, 0x1002, 0x1638)
LEONIDA_SHADER_DRIVER_RULE(barycentric, 1, 0x1002, 0x164C)
36 changes: 24 additions & 12 deletions runtime/src/shader_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,27 @@ inline bool descriptor_hash_kind_from_env(const char* value, DescriptorHashKind*
return false;
}

// The runtime's optional indexes, in lookup order. The read-only pack check scans the same set.
inline constexpr const char* shader_index_subdirectories[] = {"fspx", "fspx_compute", "fspx_gfx", "bvh", "exe", "library"};

inline bool read_shader_index(const std::filesystem::path& index, Json& root, std::string& error) {
std::ifstream file(index, std::ios::binary);
if (!file) {
const auto path = index.u8string();
error = "cannot open " + std::string(path.begin(), path.end());
return false;
}
const std::string text((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
constexpr std::string_view utf8_bom = "\xef\xbb\xbf";
std::string_view json(text);
if (json.starts_with(utf8_bom)) json.remove_prefix(utf8_bom.size());
if (!JsonReader(json).parse(root) || root.kind != Json::Kind::object) {
error = "index.json is not a JSON object";
return false;
}
return true;
}

class ShaderLibrary {
public:
// Reads <dir>/index.json, then the indexes of the programs make_game.py translates from the package's DLLs and the
Expand Down Expand Up @@ -989,7 +1010,7 @@ class ShaderLibrary {
} catch (...) {
return fail("index.json could not be read");
}
for (const char* sub_folder : {"fspx", "fspx_compute", "fspx_gfx", "bvh", "exe", "library"}) {
for (const char* sub_folder : shader_index_subdirectories) {
try {
const auto ignore = [](const std::string&) { return false; };
const std::filesystem::path sub = folder / sub_folder;
Expand Down Expand Up @@ -1199,18 +1220,9 @@ class ShaderLibrary {
// adds its entries under "<prefix><name>", the path of their modules relative to the main folder.
template<typename Fail>
bool load_index(const std::filesystem::path& dir, const std::string& prefix, Fail&& fail) {
const auto index = dir / "index.json";
std::ifstream file(index, std::ios::binary);
if (!file) {
const auto path = index.u8string();
return fail("cannot open " + std::string(path.begin(), path.end()));
}
const std::string text((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
constexpr std::string_view utf8_bom = "\xef\xbb\xbf";
std::string_view json(text);
if (json.starts_with(utf8_bom)) json.remove_prefix(utf8_bom.size());
Json root;
if (!JsonReader(json).parse(root) || root.kind != Json::Kind::object) return fail("index.json is not a JSON object");
std::string error;
if (!read_shader_index(dir / "index.json", root, error)) return fail(error);
if (prefix.empty()) {
dir_ = dir;
entries_.clear();
Expand Down
Loading