[WSLg / D3D12] `ID3D12PipelineState::GetCachedBlob()` and `ID3D12PipelineLibrary::StorePipeline()` crash with "double free or corruption"

Open
#42,280 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
12/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, linux

Research direction

The repro is pso_cache_probe.cpp, which calls GetCachedBlob() on a compute pipeline state and then StorePipeline() on a pipeline library created with CreatePipelineLibrary(nullptr, 0, ...). Build it with the g++ line in the issue and run it under gdb or with AddressSanitizer to get a backtrace at the abort. Done means both calls return instead of aborting, or CheckFeatureSupport stops reporting SINGLE_PSO and LIBRARY. The crash is likely in the WSL D3D12 translation layer (libd3d12.so), which may not be in this repository, so confirm where the backtrace lands before changing anything.

Written by the indexing model from the issue text.

Description

emailed-logs GPU wsl2
Windows Version

Windows 11 25H2, build 26200.9711

WSL Version

WSL 3.0.5.0, kernel 6.18.58.1-1, WSLg 1.0.79

Are you using WSL 1, WSL 2, or WSLC?
  • WSL 2
  • WSL 1
  • WSLC
Kernel Version

6.18.58.1-1

Distro Version

Ubuntu 24.04

Other Software
  • Direct3D (WSL) 1.611.1-81528511 (libd3d12.so/libd3d12core.so dated 2023-10-20), DXCore 10.0.26100.1

  • NVIDIA RTX PRO 500 Blackwell Generation Laptop GPU, driver 32.0.15.9595

  • Ubuntu 24.04, DirectX-Headers from the distribution

Repro Steps

pso_cache_probe.cpp (compute shader: any DXIL compute shader with an
embedded root signature; ours is compiled with
dxc -T cs_6_0 -E cs_main -Fh depthcopy_cs_main.h -Vn g_cs_main):

#include <wsl/winadapter.h>
#include <directx/d3d12.h>
#include <directx/dxcore.h>
#include <dxguids/dxguids.h>
#include <cstdio>
#include <cstring>
#include "depthcopy_cs_main.h"   // const unsigned char g_cs_main[]

int main() {
    IDXCoreAdapterFactory *f; IDXCoreAdapterList *l; IDXCoreAdapter *ad = nullptr;
    const GUID attr[] = {DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS};
    DXCoreCreateAdapterFactory(IID_PPV_ARGS(&f));
    f->CreateAdapterList(1, attr, IID_PPV_ARGS(&l));
    for (uint32_t i = 0; i < l->GetAdapterCount() && !ad; ++i) {
        char desc[256] = {}; IDXCoreAdapter *a;
        l->GetAdapter(i, IID_PPV_ARGS(&a));
        a->GetProperty(DXCoreAdapterProperty::DriverDescription, sizeof(desc), desc);
        if (strstr(desc, "NVIDIA")) ad = a;
    }
    ID3D12Device1 *dev;  D3D12CreateDevice(ad, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&dev));
    ID3D12RootSignature *rs; dev->CreateRootSignature(0, g_cs_main, sizeof(g_cs_main), IID_PPV_ARGS(&rs));
    D3D12_COMPUTE_PIPELINE_STATE_DESC d = {}; d.pRootSignature = rs; d.CS = {g_cs_main, sizeof(g_cs_main)};
    ID3D12PipelineState *p;  dev->CreateComputePipelineState(&d, IID_PPV_ARGS(&p));   // S_OK
    ID3DBlob *blob;
    printf("GetCachedBlob...\n"); fflush(stdout);
    p->GetCachedBlob(&blob);                       // aborts: double free or corruption (!prev)
    ID3D12PipelineLibrary *lib; dev->CreatePipelineLibrary(nullptr, 0, IID_PPV_ARGS(&lib));
    lib->StorePipeline(L"test", p);                // also aborts (seen separately)
    return 0;
}
g++ -O1 -g $(pkg-config --cflags DirectX-Headers) -o pso_cache_probe pso_cache_probe.cpp \
    $(pkg-config --libs DirectX-Headers) -L/usr/lib/wsl/lib -Wl,-rpath,/usr/lib/wsl/lib -ld3d12 -ldxcore
./pso_cache_probe
Expected Behavior

As on Windows with the same GPU and driver: GetCachedBlob() returns a blob that
can be passed back in D3D12_*_PIPELINE_STATE_DESC::CachedPSO, and
StorePipeline() returns S_OK. Alternatively, CheckFeatureSupport should not
report SINGLE_PSO/LIBRARY when they are unsupported.

Actual Behavior
adapter: NVIDIA RTX PRO 500 Blackwell Generation Laptop GPU
CreateDevice: 0x00000000
CreateRootSignature: 0x00000000
CreateComputePipelineState: 0x00000000
GetCachedBlob: ...
double free or corruption (!prev)
Aborted (core dumped)

StorePipeline() on an empty library created with CreatePipelineLibrary(NULL, 0, ...)
aborts the same way (a LoadGraphicsPipeline() miss before it returns
E_INVALIDARG as expected).

Diagnostic Logs

No response

Dominant language
C++
Stars
34.4k
Forks
1.9k
Avg merge
1d 23h
Merged PRs (30d)
166

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/WSL

All issues in microsoft/WSL

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.