mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
Integrate ce9c10a into the unified hybrid base
Signed-off-by: Arths17 <Atharvranjan8@gmail.com>
This commit is contained in:
commit
d24baa284f
4 files changed
+315
No files matched your search
@@ -0,0 +1,74 @@
|
||||
# D3D11 compute-buffer workload
|
||||
|
||||
This original fixture submits an unsigned 32-bit addition in a Direct3D 11 compute shader and verifies the GPU output through CPU staging readback. It requires a hardware device at feature level 11.0 and uses no game data.
|
||||
|
||||
## Expected output
|
||||
|
||||
The shader adds one plus the lane's position within a repeating 16-word sequence. Write an output index as `16b + r` with `0 ≤ r < 16`. Pattern 0 starts its block at `4096 + 65536b`. Pattern 1 starts at `−16 − 65536b`, represented modulo 2³². Each input is its block's base plus `r`. The expected output is the corresponding odd-number progression from base plus 1 to base plus 31, reduced modulo 2³². The C code lists both first-block progressions as constants. Subsequent blocks shift the expected progression by the signed block offset. The block tags distinguish writes whose indices differ by a multiple of 16. The second pattern exercises unsigned wraparound in its first block.
|
||||
|
||||
Each pattern runs with counts 0, 1, 63, 64, 65, 127, 128, 129, and 191. A zero count skips dispatch and checks that the entire buffer retains its initial sentinel. The other cases dispatch groups of 64. The structured buffers physically hold 192 words, so an erroneous write from a rounded-up tail would overwrite a sentinel inside the allocated buffer. Every run compares all 192 words, including undispatched slots. The negative control changes only the expected word for pattern 0, count 65, index 64 from `00041001` to `00041000`.
|
||||
|
||||
The digest is 32-bit FNV-1a over all 3,456 readback words, each fed as four bytes in little-endian order. Pattern 0 comes first, each pattern uses the count order above, and each buffer is traversed by ascending index. The analytic result is `6ce404b5`. The negative control should give exactly one mismatch with the same digest because it leaves the GPU inputs and work unchanged.
|
||||
|
||||
The executable returns 0 for a matching readback, 1 for mismatches, 2 for no feature-level-11.0 hardware device, 3 for another API failure, and 4 for invalid arguments.
|
||||
|
||||
## Build and run
|
||||
|
||||
Use the external llvm-mingw 20261117 UCRT macOS universal release pinned by the candidate in #384. Its archive SHA-256 is `98d340bbb8d46b09ad6886ffba88bd9d5415e131c316de48e6bd7647377446aa`. Clang and LLD are 23.1.6. The package ships both host slices and the recipe explicitly runs Clang as ARM64. The release includes LLVM's Apache-2.0 license with LLVM exceptions and dependency notices. See the archive's `LICENSE.TXT`. It is a build dependency and is supplied separately.
|
||||
|
||||
```sh
|
||||
workloads/d3d11-compute/build.sh /absolute/path/to/llvm-mingw /absolute/path/to/vkd3d-compiler
|
||||
```
|
||||
|
||||
The second dependency is WineHQ vkd3d-compiler 2.2 with libvkd3d-shader 2.2 (LGPL-2.1-or-later). The WineHQ 2.2 source archive used locally had SHA-256 `6f8cdbfc52e36eb74ab6aff42b1e958c3d9af912ab8f23d16d63711f2bab051b`. Use a native ARM64 build. The recipe compiles HLSL entry `main` to the `cs_5_0` profile in a tokenized DXBC container and embeds the resulting bytes in the executable. The guest gives those bytes directly to `CreateComputeShader`. Neither compiler is bundled or invoked by the guest.
|
||||
|
||||
Local compiler build inputs were the WineHQ release, Xcode Command Line Tools, pkgconf 2.5.1, Bison 3.8.2, system Flex, Vulkan-Headers `d4a196d8c84e032d27f999adcea3075517c1c97f` and SPIRV-Headers `3f17b2af6784bfa2c5aa5dbb8e0e74a607dd8b3b`. From the extracted vkd3d source, the local ARM64 build used:
|
||||
|
||||
```sh
|
||||
PKG_CONFIG=/absolute/path/to/pkgconf SONAME_LIBVULKAN=libMoltenVK.dylib \
|
||||
CPPFLAGS="-I$VULKAN_HEADERS/include -I$SPIRV_HEADERS/include" \
|
||||
./configure --disable-tests --disable-demos
|
||||
for grammar in hlsl preproc; do
|
||||
bison -d -o "libs/vkd3d-shader/$grammar.tab.c" "libs/vkd3d-shader/$grammar.y"
|
||||
done
|
||||
make include/private/vkd3d_version.h
|
||||
make -j2 vkd3d-compiler
|
||||
```
|
||||
|
||||
The Vulkan soname satisfies configure's runtime-library setting for the broader vkd3d project. The compiler target links libvkd3d-shader and does not link Vulkan or MoltenVK. The default guest build output is `artifacts/hybrid-workloads/x86_64/d3d11-compute.exe`.
|
||||
|
||||
Use a fresh dedicated Windows 11 64-bit bottle and the evidence-saving runner from #398. The runner's backend selector is observed CrossOver behavior. Record the backend evidence from each run.
|
||||
|
||||
```sh
|
||||
betterxen-hybrid run --bottle betterxen-issue-401 --backend dxvk \
|
||||
--timeout 45 --expect 'PASS cases=' --out artifacts/issue-401/run-records \
|
||||
-- "$PWD/artifacts/hybrid-workloads/x86_64/d3d11-compute.exe"
|
||||
betterxen-hybrid run --bottle betterxen-issue-401 --backend dxvk \
|
||||
--timeout 45 --expect 'PASS cases=' --out artifacts/issue-401/run-records \
|
||||
-- "$PWD/artifacts/hybrid-workloads/x86_64/d3d11-compute.exe" --negative-control
|
||||
```
|
||||
|
||||
The second command should return 1 and report one mismatch. A result without a guest exit code or completed readback is unavailable.
|
||||
|
||||
## Local evidence
|
||||
|
||||
Workload branch base: `566272082a74d8b45fcec37edd00f4f6703df3ab` (#384). The separate Rust 1.100.0 runner checkout used `e1b6a24a4f37360abb1f5c77bedbfd470cf1c720` (#398's persistence fix on #384). Host was an ARM64 Apple M2 Pro with 16 GiB and macOS 27.3 (26C5035r). CrossOver Preview was 20261111 (27.0.0.41303). The pinned archive checksum matched. Separate source and output directories produced identical DXBC (SHA-256 `af046791dce24119b0452d50cd30f69a2735de649161101cb5d0626625eebee0`) and x86-64 PE32+ executables (SHA-256 `2f92cd68266592039cdc4860a2c3896a15ddabb83dbecd0d1ed928599009095f`).
|
||||
|
||||
The default memory guard refused the first request at 49% free. Subsequent local runs used the runner's `--min-start-free 45` option with the default during-run floor. Run records are under ignored `artifacts/issue-401/precompiled-records/`. This is author-side verification. Independent derivation and CrossOver reproduction are pending.
|
||||
|
||||
| Requested backend | Evidence in the run record | Normal run | Negative control |
|
||||
| --- | --- | --- | --- |
|
||||
| D3DMetal | Inferred from the `AMD Compatibility Mode` adapter | Exit 0, zero mismatches | Exit 1, one mismatch |
|
||||
| DXVK | DXVK banner and `Apple M2 Pro` adapter | Exit 0, zero mismatches | Exit 1, one mismatch |
|
||||
|
||||
All four completed runs read back 3,456 words and matched the independently calculated digest `6ce404b5`. The initial memory refusal was the only unavailable run in the final evidence set. The runner intentionally classifies a negative-control exit 1 as a workload failure.
|
||||
|
||||
## References
|
||||
|
||||
- [llvm-mingw 20261117 release](https://github.com/mstorsjo/llvm-mingw/releases/tag/20261117)
|
||||
- [WineHQ vkd3d 2.2 release](https://list.winehq.org/hyperkitty/list/wine-announce%40list.winehq.org/thread/QBVNHPS2PLCJXA67ESIEY3XZP7BV4KRA/)
|
||||
- [Microsoft compute shader creation and profile example](https://learn.microsoft.com/en-us/windows/win32/direct3d11/direct3d-11-advanced-stages-compute-create)
|
||||
- [Microsoft structured-buffer resource](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-structuredbuffer)
|
||||
- [Microsoft thread-group size and dispatch IDs](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-attributes-numthreads)
|
||||
- [Microsoft CopyResource reference](https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-copyresource)
|
||||
- [Microsoft Map reference](https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-map)
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
set -eu
|
||||
toolchain=${1:?usage: build.sh LLVM_MINGW_DIR VKD3D_COMPILER [OUTPUT_DIR]}
|
||||
shader_compiler=${2:?supply the native vkd3d-compiler 2.2 executable}
|
||||
src=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
||||
out=${3:-"$src/../../artifacts/hybrid-workloads/x86_64"}
|
||||
mkdir -p "$out"
|
||||
|
||||
version=$(arch -arm64 "$shader_compiler" --version)
|
||||
case "$version" in
|
||||
'vkd3d shader compiler version 2.2 using vkd3d-shader 2.2'*) ;;
|
||||
*) printf 'Expected vkd3d-compiler and vkd3d-shader 2.2, got %s\n' "$version" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
# Compile original HLSL to D3D11-compatible shader model 5 tokenized bytecode.
|
||||
arch -arm64 "$shader_compiler" -x hlsl -b dxbc-tpf -p cs_5_0 -e main \
|
||||
-o "$out/compute.dxbc" "$src/compute.hlsl"
|
||||
xxd -i < "$out/compute.dxbc" > "$out/compute_dxbc.inc"
|
||||
arch -arm64 "$toolchain/bin/x86_64-w64-mingw32-clang" \
|
||||
-std=c11 -O2 -Wall -Wextra -Werror -Wl,--no-insert-timestamp \
|
||||
-I "$out" "$src/compute.c" -o "$out/d3d11-compute.exe" -ld3d11 -ldxguid
|
||||
description=$(file -b "$out/d3d11-compute.exe")
|
||||
echo "$description"
|
||||
case "$description" in
|
||||
*PE32+*x86-64*) ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
@@ -0,0 +1,198 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#define COBJMACROS
|
||||
#include <d3d11.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static const unsigned char shader_bytecode[] = {
|
||||
#include "compute_dxbc.inc"
|
||||
};
|
||||
|
||||
enum { GROUP_WIDTH = 64, CAPACITY = 3 * GROUP_WIDTH, PATTERNS = 2 };
|
||||
static const uint32_t sentinel = UINT32_C(0xcafef00d);
|
||||
|
||||
// Authored as base + residue. The second row crosses the 32-bit wrap boundary.
|
||||
static const uint32_t inputs[PATTERNS][16] = {
|
||||
{0x1000, 0x1001, 0x1002, 0x1003, 0x1004, 0x1005, 0x1006, 0x1007,
|
||||
0x1008, 0x1009, 0x100a, 0x100b, 0x100c, 0x100d, 0x100e, 0x100f},
|
||||
{0xfffffff0, 0xfffffff1, 0xfffffff2, 0xfffffff3,
|
||||
0xfffffff4, 0xfffffff5, 0xfffffff6, 0xfffffff7,
|
||||
0xfffffff8, 0xfffffff9, 0xfffffffa, 0xfffffffb,
|
||||
0xfffffffc, 0xfffffffd, 0xfffffffe, 0xffffffff},
|
||||
};
|
||||
|
||||
static const uint32_t expected[PATTERNS][16] = {
|
||||
{0x1001, 0x1003, 0x1005, 0x1007, 0x1009, 0x100b, 0x100d, 0x100f,
|
||||
0x1011, 0x1013, 0x1015, 0x1017, 0x1019, 0x101b, 0x101d, 0x101f},
|
||||
{0xfffffff1, 0xfffffff3, 0xfffffff5, 0xfffffff7, 0xfffffff9, 0xfffffffb,
|
||||
0xfffffffd, 0xffffffff, 1, 3, 5, 7, 9, 11, 13, 15},
|
||||
};
|
||||
|
||||
#define CHECK(operation) do { \
|
||||
HRESULT result = (operation); \
|
||||
if (FAILED(result)) { \
|
||||
printf("API_ERROR operation=%s hr=0x%08lx\n", #operation, (unsigned long)result); \
|
||||
goto cleanup; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int run_case(ID3D11Device *device, ID3D11DeviceContext *context,
|
||||
UINT pattern, UINT count, int negative, uint32_t *digest,
|
||||
UINT *mismatches) {
|
||||
uint32_t input[CAPACITY], initial[CAPACITY];
|
||||
const uint32_t params[4] = {count, 0, 0, 0};
|
||||
ID3D11Buffer *source = NULL, *destination = NULL, *staging = NULL, *constants = NULL;
|
||||
ID3D11ShaderResourceView *srv = NULL;
|
||||
ID3D11UnorderedAccessView *uav = NULL;
|
||||
int status = 3;
|
||||
for (UINT i = 0; i < CAPACITY; ++i) {
|
||||
input[i] = inputs[pattern][i % 16] ^ ((i / 16) << 16);
|
||||
initial[i] = sentinel;
|
||||
}
|
||||
|
||||
D3D11_BUFFER_DESC desc = {
|
||||
.ByteWidth = sizeof input, .Usage = D3D11_USAGE_DEFAULT,
|
||||
.BindFlags = D3D11_BIND_SHADER_RESOURCE,
|
||||
.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED,
|
||||
.StructureByteStride = sizeof(uint32_t),
|
||||
};
|
||||
D3D11_SUBRESOURCE_DATA data = {.pSysMem = input};
|
||||
CHECK(ID3D11Device_CreateBuffer(device, &desc, &data, &source));
|
||||
desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
|
||||
data.pSysMem = initial;
|
||||
CHECK(ID3D11Device_CreateBuffer(device, &desc, &data, &destination));
|
||||
|
||||
desc = (D3D11_BUFFER_DESC){
|
||||
.ByteWidth = sizeof initial, .Usage = D3D11_USAGE_STAGING,
|
||||
.CPUAccessFlags = D3D11_CPU_ACCESS_READ,
|
||||
};
|
||||
CHECK(ID3D11Device_CreateBuffer(device, &desc, NULL, &staging));
|
||||
desc = (D3D11_BUFFER_DESC){
|
||||
.ByteWidth = sizeof params, .Usage = D3D11_USAGE_IMMUTABLE,
|
||||
.BindFlags = D3D11_BIND_CONSTANT_BUFFER,
|
||||
};
|
||||
data.pSysMem = params;
|
||||
CHECK(ID3D11Device_CreateBuffer(device, &desc, &data, &constants));
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC read_view = {
|
||||
.Format = DXGI_FORMAT_UNKNOWN, .ViewDimension = D3D11_SRV_DIMENSION_BUFFER,
|
||||
.Buffer = {.NumElements = CAPACITY},
|
||||
};
|
||||
D3D11_UNORDERED_ACCESS_VIEW_DESC write_view = {
|
||||
.Format = DXGI_FORMAT_UNKNOWN, .ViewDimension = D3D11_UAV_DIMENSION_BUFFER,
|
||||
.Buffer = {.NumElements = CAPACITY},
|
||||
};
|
||||
CHECK(ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)source, &read_view, &srv));
|
||||
CHECK(ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)destination, &write_view, &uav));
|
||||
|
||||
if (count) {
|
||||
ID3D11DeviceContext_CSSetShaderResources(context, 0, 1, &srv);
|
||||
ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
|
||||
ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &constants);
|
||||
ID3D11DeviceContext_Dispatch(context, (count + GROUP_WIDTH - 1) / GROUP_WIDTH, 1, 1);
|
||||
ID3D11ShaderResourceView *no_srv = NULL;
|
||||
ID3D11UnorderedAccessView *no_uav = NULL;
|
||||
ID3D11Buffer *no_buffer = NULL;
|
||||
ID3D11DeviceContext_CSSetShaderResources(context, 0, 1, &no_srv);
|
||||
ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &no_uav, NULL);
|
||||
ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &no_buffer);
|
||||
}
|
||||
ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)staging, (ID3D11Resource *)destination);
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
CHECK(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging, 0, D3D11_MAP_READ, 0, &map));
|
||||
const uint32_t *words = map.pData;
|
||||
for (UINT i = 0; i < CAPACITY; ++i) {
|
||||
uint32_t want = sentinel;
|
||||
if (i < count) {
|
||||
want = expected[pattern][i % 16];
|
||||
// Input tags increase pattern 0 and decrease pattern 1 by whole 65536s.
|
||||
want += pattern == 0 ? (i / 16) << 16 : 0u - ((i / 16) << 16);
|
||||
if (negative && pattern == 0 && count == GROUP_WIDTH + 1 && i == GROUP_WIDTH)
|
||||
want ^= 1u;
|
||||
}
|
||||
if (words[i] != want) {
|
||||
if (*mismatches < 8)
|
||||
printf("MISMATCH pattern=%u count=%u index=%u expected=%08" PRIx32
|
||||
" actual=%08" PRIx32 "\n", pattern, count, i, want, words[i]);
|
||||
++*mismatches;
|
||||
}
|
||||
for (unsigned shift = 0; shift < 32; shift += 8) {
|
||||
*digest ^= (words[i] >> shift) & 0xffu;
|
||||
*digest *= UINT32_C(16777619);
|
||||
}
|
||||
}
|
||||
ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging, 0);
|
||||
status = 0;
|
||||
|
||||
cleanup:
|
||||
if (uav) ID3D11UnorderedAccessView_Release(uav);
|
||||
if (srv) ID3D11ShaderResourceView_Release(srv);
|
||||
if (constants) ID3D11Buffer_Release(constants);
|
||||
if (staging) ID3D11Buffer_Release(staging);
|
||||
if (destination) ID3D11Buffer_Release(destination);
|
||||
if (source) ID3D11Buffer_Release(source);
|
||||
return status;
|
||||
}
|
||||
|
||||
static void report_adapter(ID3D11Device *device) {
|
||||
IDXGIDevice *dxgi = NULL;
|
||||
IDXGIAdapter *adapter = NULL;
|
||||
DXGI_ADAPTER_DESC desc;
|
||||
if (SUCCEEDED(ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi))) {
|
||||
if (SUCCEEDED(IDXGIDevice_GetAdapter(dxgi, &adapter))) {
|
||||
if (SUCCEEDED(IDXGIAdapter_GetDesc(adapter, &desc)))
|
||||
printf("adapter=%.127ls vendor=0x%x\n", desc.Description, desc.VendorId);
|
||||
IDXGIAdapter_Release(adapter);
|
||||
}
|
||||
IDXGIDevice_Release(dxgi);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const int negative = argc == 2 && strcmp(argv[1], "--negative-control") == 0;
|
||||
if (argc != 1 && !negative) {
|
||||
puts("USAGE d3d11-compute.exe [--negative-control]");
|
||||
return 4;
|
||||
}
|
||||
|
||||
ID3D11Device *device = NULL;
|
||||
ID3D11DeviceContext *context = NULL;
|
||||
const D3D_FEATURE_LEVEL level = D3D_FEATURE_LEVEL_11_0;
|
||||
HRESULT hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &level, 1,
|
||||
D3D11_SDK_VERSION, &device, NULL, &context);
|
||||
if (FAILED(hr)) {
|
||||
printf("NO_DEVICE hr=0x%08lx\n", (unsigned long)hr);
|
||||
return 2;
|
||||
}
|
||||
|
||||
report_adapter(device);
|
||||
|
||||
ID3D11ComputeShader *shader = NULL;
|
||||
int status = 3;
|
||||
CHECK(ID3D11Device_CreateComputeShader(device, shader_bytecode,
|
||||
sizeof shader_bytecode, NULL, &shader));
|
||||
ID3D11DeviceContext_CSSetShader(context, shader, NULL, 0);
|
||||
|
||||
const UINT counts[] = {0, 1, 63, 64, 65, 127, 128, 129, 191};
|
||||
const UINT count_cases = sizeof counts / sizeof counts[0];
|
||||
uint32_t digest = UINT32_C(2166136261);
|
||||
UINT mismatches = 0;
|
||||
for (UINT pattern = 0; pattern < PATTERNS; ++pattern) {
|
||||
for (UINT i = 0; i < count_cases; ++i) {
|
||||
status = run_case(device, context, pattern, counts[i], negative, &digest, &mismatches);
|
||||
if (status) goto cleanup;
|
||||
}
|
||||
}
|
||||
printf("%s cases=%u words=%u mismatches=%u digest=%08" PRIx32 "\n",
|
||||
mismatches ? "FAIL" : "PASS", PATTERNS * count_cases,
|
||||
PATTERNS * count_cases * CAPACITY, mismatches, digest);
|
||||
status = mismatches ? 1 : 0;
|
||||
|
||||
cleanup:
|
||||
ID3D11DeviceContext_ClearState(context);
|
||||
if (shader) ID3D11ComputeShader_Release(shader);
|
||||
ID3D11DeviceContext_Release(context);
|
||||
ID3D11Device_Release(device);
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
StructuredBuffer<uint> inputWords : register(t0);
|
||||
RWStructuredBuffer<uint> outputWords : register(u0);
|
||||
|
||||
cbuffer Parameters : register(b0)
|
||||
{
|
||||
uint count;
|
||||
};
|
||||
|
||||
[numthreads(64, 1, 1)]
|
||||
void main(uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
if (id.x < count)
|
||||
outputWords[id.x] = inputWords[id.x] + (id.x & 15u) + 1u;
|
||||
}
|
||||
Reference in new issue
Block a user