Skip to main content
GameDev.net gamedev.net
🔒 Locked

dxc code size [SOLVED]

Started by WFP Jun 4, 2019 at 5:13 AM 6 replies 6.2k views
Original Post
WFP
WFP

I'm testing out DXC to compile HLSL files into SPIR-V, but have run into an issue on a seemingly simple shader. The shader compiles and runs fine using glslangValidator with the -D flag (HLSL input), but when trying to compile it with DXC, I get the following error message:

Quote

VKMessage: SPIR-V module not valid: Codesize must be a multiple of 4 but is 7333. The Vulkan spec states: If pCode points to SPIR-V code, codeSize must be a multiple of 4

Is there a flag or option I've missed to force DXC to output a multiple-of-4 result? With this requirement, I would have assumed it would have done that by default, but that obviously isn't the case.

Below are the two commands I'm trying to get to act the same. As stated, the first command produces the expected result and everything runs fine. The dxc line gives the issue. (And I run these separately - they're posted together below for quick reading, but they do not run sequentially and overwrite each other in practice).


C:/VulkanSDK/1.1.106.0/Bin/glslangValidator.exe -e main -V -D Basic_PushConstant_HLSL.frag -o basic_push_constant_ps.spv

C:/"Program Files (x86)"/"Windows Kits"/10/bin/10.0.17763.0/x64/dxc.exe /Zi /spirv /fspv-target-env=vulkan1.1 /E"main" /Od /Fo"basic_push_constant_ps.spv" /T"ps_6_0" /nologo Basic_PushConstant_HLSL.frag

The shader is below. Nothing fancy, just drawing colored quads on the screen.


[[vk::push_constant]]
cbuffer PConsts : register(b2)
{
	[[vk::offset(8)]]
	float cb_push;
};

struct PixelIn
{
	float4 posH : SV_Position;
	float3 color : COLOR;
	float2 texcoord : TEXCOORD;
};

float4 main(PixelIn pIn) : SV_Target0
{
	float3 color = pIn.color * saturate(cb_push + 0.2f);
	return float4(color, 1.0f);
}

Thanks!

WFP
WFP

A few more things I've tried, in case it helps.

- Tried switching to the 32-bit dxc.exe.

- Tried this with the most recent dxc build from Appveyor

- Tried forcing the read in code size to a multiple of 4 by padding with zeros - this causes a new error saying that the SPIR-V magic number is invalid.

Adam Miles
Adam Miles

Sounds like a question best directed to the Issues area of the DirectXCompiler GitHub repo.

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group
WFP
WFP

Thanks, I was waiting to open a new issue just in case I had accidentally missed a build option or something, but the more combinations I try, the more I think I should just go ahead and do that.

I'll post the link to the issue here once it's open, in case it helps anyone else in the future.

Andrew Naumov
Andrew Naumov

I tried to compile your code http://shader-playground.timjones.io/7abb0a7a8455e45e6bda522c8536c6eb

and got follow errors:

D:\local\Temp\268cd6bd-54aa-48bf-9301-ae7880bf1c61.hlsl:1:3: error: 'push_constant' attribute only applies to global variables of struct type
[[vk::push_constant]]
^
D:\local\Temp\268cd6bd-54aa-48bf-9301-ae7880bf1c61.hlsl:4:4: error: 'offset' attribute only applies to fields
[[vk::offset(8)]]
^
If I change code it will compile without errors


struct PConsts
{
	[[vk::offset(8)]]
	float cb_push;
};

[[vk::push_constant]]
ConstantBuffer<PConsts> cb : register(b2);

struct PixelIn
{
	float4 posH : SV_Position;
	float3 color : COLOR;
	float2 texcoord : TEXCOORD;
};

float4 main(PixelIn pIn) : SV_Target0
{
	float3 color = pIn.color * saturate(cb.cb_push + 0.2f);
	return float4(color, 1.0f);
}

http://shader-playground.timjones.io/8fd049b53b7960b5f6a333e83195fdcb

Maybe it can help you.

WFP
WFP

?‍♂️

Thank you!!!

For the longest time I've only supported SM 5.0 for compatibility reasons, and had nearly forgotten that 5.1 added the templated ConstantBuffer type. Since DXC is 6.0 and up, of course I should have updated to the new syntax.

That's what I was missing. Changing the code as shown below fixes the issue, with all attributes properly in use and no warnings or errors.

Thanks again!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.