Skip to content
Open
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
9 changes: 9 additions & 0 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -4284,6 +4284,15 @@ Games and middleware call these every frame (PIX events), so they must be cheap
- **Labels, only with `VK_EXT_debug_utils`.** It is an instance extension, so `VulkanDeviceInfo::debug_utils` says
whether the instance enabled it; `create_vulkan_device_standalone` enables it when the loader lists it. Without
it every marker call is a no-op (nothing logged, nothing recorded on the queue).
- **Compute shader modules.** With `VK_EXT_debug_utils`, each module is named with its shader-library entry name
before pipeline creation. This lets GPU-assisted validation select an individual compute shader using
`VK_LAYER_GPUAV_ENABLE=1`, `VK_LAYER_GPUAV_SELECT_INSTRUMENTED_SHADERS=1` and
`VK_LAYER_GPUAV_SHADERS_TO_INSTRUMENT=<entry name>` alongside `LEONIDA_VK_VALIDATION=1`.
Shader code and execution are unchanged; without the extension or naming entry point no naming call is made.
The layer's selection setting must be enabled to avoid instrumenting the entire library.
With a recent Khronos validation layer installed, `python -I scripts/check_compute_gpuav_selection.py
<build>/d3d12_compute_test.exe` checks selected and unmatched names using synthetic compute readbacks and
the layer's instrumented-module dumps. It is an opt-in GPU-AV check, not a default CTest requirement.
- **Command lists.** `SetMarker`/`BeginEvent`/`EndEvent` are recorded in the IR (`DebugMarker`) in order with the
other commands and replayed as `vkCmdInsertDebugUtilsLabelEXT`/`vkCmdBeginDebugUtilsLabelEXT`/
`vkCmdEndDebugUtilsLabelEXT` into the submission's command buffer.
Expand Down
9 changes: 9 additions & 0 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,7 @@ struct DeviceState {
std::mutex title_image_mutex;
std::multimap<std::uint64_t, Resource*> title_images;
VulkanDeviceInfo info;
PFN_vkSetDebugUtilsObjectNameEXT set_debug_name = nullptr;
std::vector<std::uint32_t> families;

template<typename CreateInfo>
Expand Down Expand Up @@ -10447,6 +10448,13 @@ ComputeBuild build_compute_pipeline(DeviceState& device, const leonida::ShaderEn
{
const leonida::aftermath::ShaderName named(entry->name);
if (vk.vkCreateShaderModule(dev, &module_info, nullptr, &module) != VK_SUCCESS) return out;
if (device.set_debug_name) {
VkDebugUtilsObjectNameInfoEXT name{VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT};
name.objectType = VK_OBJECT_TYPE_SHADER_MODULE;
name.objectHandle = reinterpret_cast<std::uint64_t>(module);
name.pObjectName = entry->name.c_str();
device.set_debug_name(dev, &name);
}
}
pipeline_info.stage.module = module;
journal.create();
Expand Down Expand Up @@ -13870,6 +13878,7 @@ class Device final
f = reinterpret_cast<std::remove_reference_t<decltype(f)>>(info.get_instance_proc(info.instance, name));
};
load(labels.cmd_insert, "vkCmdInsertDebugUtilsLabelEXT");
load(state_.set_debug_name, "vkSetDebugUtilsObjectNameEXT");
load(labels.cmd_begin, "vkCmdBeginDebugUtilsLabelEXT");
load(labels.cmd_end, "vkCmdEndDebugUtilsLabelEXT");
load(labels.queue_insert, "vkQueueInsertDebugUtilsLabelEXT");
Expand Down
1 change: 1 addition & 0 deletions runtime/test/d3d12_compute_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ int main() {
{
rt::d3d12::VulkanDeviceInfo info{};
info.prepare_on_bind=d.prepare_on_bind;
info.debug_utils = d.debug_utils;
info.get_instance_proc = d.instance_proc;
info.instance = d.instance;
info.physical = d.physical;
Expand Down
70 changes: 70 additions & 0 deletions scripts/check_compute_gpuav_selection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Check compute-module debug-name selection with an installed Khronos GPU-AV layer.

Uses only d3d12_compute_test's synthetic shaders. This is an opt-in integration
check: it requires a Vulkan device and a layer supporting selective GPU-AV and
instrumented-shader dumps. It is not part of the default CTest suite.
"""
import argparse
import os
from pathlib import Path
import subprocess
import tempfile


def run_case(executable, directory, selector):
directory.mkdir()
cache = directory / "cache"
cache.mkdir()
env = os.environ.copy()
env.update({
"LEONIDA_VK_VALIDATION": "1",
"LEONIDA_PIPELINE_CACHE_DIR": str(cache),
"VK_LAYER_GPUAV_ENABLE": "1",
"VK_LAYER_GPUAV_SHADER_INSTRUMENTATION": "1",
"VK_LAYER_GPUAV_SELECT_INSTRUMENTED_SHADERS": "1",
"VK_LAYER_GPUAV_SHADERS_TO_INSTRUMENT": selector,
"VK_LAYER_GPUAV_DEBUG_DUMP_INSTRUMENTED_SHADERS": "1",
})
result = subprocess.run([str(executable)], cwd=directory, env=env,
capture_output=True, timeout=120)
if result.returncode == 77:
return None
if result.returncode:
raise RuntimeError(f"compute fixture failed ({result.returncode}):\n"
+ result.stderr.decode("utf-8", errors="replace"))
dumps = list(directory.glob("dump_*_after.spv"))
for after in dumps:
before = after.with_name(after.name.replace("_after.spv", "_before.spv"))
original, instrumented = before.read_bytes(), after.read_bytes()
if original[:4] != b"\x03\x02\x23\x07" or instrumented[:4] != b"\x03\x02\x23\x07":
raise RuntimeError("layer dump is not SPIR-V")
if original == instrumented:
raise RuntimeError("selected module was not instrumented")
return len(dumps)


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("compute_test", type=Path, help="path to d3d12_compute_test")
args = parser.parse_args()
executable = args.compute_test.resolve(strict=True)
with tempfile.TemporaryDirectory(prefix="leonida_gpuav_selection_") as scratch:
root = Path(scratch)
selected = run_case(executable, root / "selected", "cs_user_data")
if selected is None:
print("SKIP: no usable Vulkan device")
return 77
if not selected:
raise RuntimeError("named selection produced no instrumented module; "
"check module naming and the installed validation layer")
unmatched = run_case(executable, root / "unmatched", "__leonida_no_matching_shader__")
if unmatched is None:
raise RuntimeError("Vulkan device became unavailable during the check")
if unmatched:
raise RuntimeError("unmatched selection instrumented a shader")
print(f"PASS: selected {selected} module(s), unmatched 0; compute readback checks passed")
return 0


if __name__ == "__main__":
raise SystemExit(main())
Loading