microsoft / microsoft/DirectXShaderCompiler

Linker doesn't strip resource names when using -Qstrip_reflect

Open
#5,704 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug reflection shader-linking
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
The linker keeps resource names in DXIL reflection even when the -Qstrip_reflect is used. Compiling lib_6_3 targets also leaves the resource names in too, so there doesn't appear to be any way to remove them.

Steps to Reproduce
Run this:

void ReflStripBugTest(IDxcCompiler3* aCompiler, IDxcLinker* aLinker)
{
	const char* sourceBlob =
		"Texture2D<uint> texResource : register(t900);\n"
		"RWTexture2D<uint> rwTexResource[] : register(u0, space2400);\n"
		"[numthreads(8, 8, 1)]\n"
		"void main(uint3 dtid : SV_DispatchThreadID, uint3 gtid : SV_GroupThreadID, uint3 gid : SV_GroupID, uint gindex : SV_GroupIndex)\n"
		"{\n"
		"    rwTexResource[0][dtid.xy] = texResource.Load(dtid.xyz);\n"
		"}\n";

	DxcBuffer sourceBuffer;
	sourceBuffer.Encoding = DXC_CP_ACP;
	sourceBuffer.Ptr = sourceBlob;
	sourceBuffer.Size = strlen(sourceBlob);

	const wchar_t* compileArgs[] = {
		L"-O3",
		L"-T",
		L"lib_6_3",
		L"-Qstrip_reflect",
	};

	IDxcResult* result;

	aCompiler->Compile(&sourceBuffer, compileArgs, sizeof(compileArgs) / sizeof(compileArgs[0]), nullptr, IID_PPV_ARGS(&result));

	IDxcBlob* compiledBlob = nullptr;
	result->GetResult(&compiledBlob);

	const wchar_t* libName = L"MyLibrary";
	aLinker->RegisterLibrary(libName, compiledBlob);

	const wchar_t* linkArgs[] = {
		L"-O3",
		L"-Qstrip_reflect",
	};

	IDxcOperationResult* linkResult = nullptr;
	aLinker->Link(L"main", L"cs_6_3", &libName, 1, linkArgs, sizeof(linkArgs) / sizeof(linkArgs[0]), &linkResult);

	IDxcBlob* linkedBlob = nullptr;
	linkResult->GetResult(&linkedBlob);

	const void* linkedData = linkedBlob->GetBufferPointer();
	size_t linkedDataSize = linkedBlob->GetBufferSize();

	IDxcResult* disasmResult = nullptr;

	DxcBuffer linkedBuffer;
	linkedBuffer.Encoding = DXC_CP_ACP;
	linkedBuffer.Ptr = linkedBlob->GetBufferPointer();
	linkedBuffer.Size = linkedBlob->GetBufferSize();
	aCompiler->Disassemble(&linkedBuffer, IID_PPV_ARGS(&disasmResult));

	IDxcBlob* disasmBlob = nullptr;
	disasmResult->GetResult(&disasmBlob);

	const char* disasmText = static_cast<const char*>(disasmBlob->GetBufferPointer());

	puts(disasmText);
}

Actual Behavior
Disassembly contains the resource names in the metadata.

Environment

  • DXC version dxcompiler.dll: 1.7 - 1.7.2308.7 (69e54e290); dxil.dll: 1.7(101.7.2308.12)
  • Host Operating System Windows 10

Contributor guide

Open the contributing guide

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.

Research direction

Start by running the provided ReflStripBugTest reproduction with the stated DXC versions and inspect the linked disassembly. Trace how -Qstrip_reflect is handled during compilation and linking, then verify that the resource names are absent from DXIL reflection metadata while linking the lib_6_3 shader still succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.