DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

RDAT part is missing when linking a compute shader

Open EricLasotaRSE opened this issue 2 years ago • 0 comments

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

EricLasotaRSE avatar Sep 13 '23 03:09 EricLasotaRSE