microsoft / microsoft/DirectXShaderCompiler

RDAT part is missing when linking a compute shader

Open
#5,703 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
Linking a cs_6_3 target from a library source omits the RDAT part from the compiled DXIL module. This seems to happen even if the inputs have RDAT.

Steps to Reproduce
Run this:

void ReflBugTest(IDxcCompiler3* aCompiler, IDxcLinker* aLinker, IDxcContainerReflection* aRefl)
{
	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",
	};

	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",
	};

	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();

	aRefl->Load(linkedBlob);

	UINT32 partCount = 0;
	aRefl->GetPartCount(&partCount);

	bool foundRDAT = false;
	for (unsigned int i = 0; i < partCount; i++)
	{
		UINT32 partKind = 0;
		aRefl->GetPartKind(i, &partKind);
		if (partKind == DXC_PART_REFLECTION_DATA)
		{
			foundRDAT = true;
			break;
		}
	}

	assert(foundRDAT);
}

Actual Behavior
Assert fails (RDAT is missing)

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 IDxcCompiler3, IDxcLinker, and IDxcContainerReflection reproduction on the stated DXC versions, then inspect how linking a lib_6_3 library to cs_6_3 assembles the DXIL container. Done means the linked blob contains an RDAT part detectable through GetPartCount, GetPartKind, and DXC_PART_REFLECTION_DATA.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.