Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How do you create a root signature from a DXIL shader? #2315

Closed
killerlegs opened this issue Jul 5, 2019 · 6 comments
Labels

Comments

@killerlegs
Copy link

@killerlegs killerlegs commented Jul 5, 2019

I managed to get the part but it seems to be in a different format:

ComPtr<IDxcContainerReflection> reflection;
DXCHECK(DxcCreateInstance(CLSID_DxcContainerReflection, __uuidof(IDxcContainerReflection), (void**)&reflection));

DXCHECK(reflection->Load(vs.Get()));
UINT32 shaderIdx;
DXCHECK(reflection->FindFirstPartKind(DFCC_RootSignature, &shaderIdx));
ComPtr<IDxcBlob> rootSignatureBlob;
DXCHECK(reflection->GetPartContent(shaderIdx, &rootSignatureBlob)); // gets 112 bytes

ComPtr<ID3D12RootSignature> rootSignature;
DXCHECK(device->CreateRootSignature(0, rootSignatureBlob->GetBufferPointer(), rootSignatureBlob->GetBufferSize(), IID_PPV_ARGS(&rootSignature)));

The last line returns

D3D12 ERROR: ID3D12Device::CreateRootSignature: BlobLengthInBytes parameter indicates size of 112 but this does not match pBlobWithRootSignature parameter which points to a blob whose internal size encoding is 0. If ID3DBlob was used to hold the blob, GetBufferPointer() returns the blob pointer and GetBufferSize() returns the size. [ STATE_CREATION ERROR #697: CREATE_ROOT_SIGNATURE_DESERIALIZE_FAILED]

The shader hasn't been changed since it was compiled with fxc. What's the correct way to do this? Couldn't find any documentation or sample, unfortunately.

@MrTrillian MrTrillian added the question label Jul 5, 2019
@MrTrillian

This comment has been minimized.

Copy link
Member

@MrTrillian MrTrillian commented Jul 5, 2019

@tex3d Do you know how the reflection root signature blob differs from what D3D12's CreateRootSignature expects?

@tex3d

This comment has been minimized.

Copy link
Contributor

@tex3d tex3d commented Jul 10, 2019

I believe the API expects a signed blob container with a root signature part which is the result of fxc's direct root signature target compilation or /extractrootsignature operation (which repackages the signature in a signed DXBC container). The container reflection just returns the raw serialized root signature, not wrapped in any container. It may be valid to just pass the shader blob itself to CreateRootSignature, since that's a signed blob container with a root signature part.

@killerlegs

This comment has been minimized.

Copy link
Author

@killerlegs killerlegs commented Jul 10, 2019

Indeed, it works when you pass the compiled shader blob directly to CreateRootSignature! Same with D3D12CreateRootSignatureDeserializer for root signature reflection. Thanks!

ComPtr<ID3D12RootSignature> rootSignature;
DXCHECK(device->CreateRootSignature(0, vs->GetBufferPointer(), vs->GetBufferSize(), IID_PPV_ARGS(&rootSignature)));

ComPtr<ID3D12RootSignatureDeserializer> deserializer;
DXCHECK(D3D12CreateRootSignatureDeserializer(vs->GetBufferPointer(), vs->GetBufferSize(), IID_PPV_ARGS(&deserializer)));

PS: I noticed that #pragma pack_matrix(row_major) doesn't seem to work anymore. Fortunately, you can use the -Zpr compile option instead.

@MrTrillian

This comment has been minimized.

Copy link
Member

@MrTrillian MrTrillian commented Jul 10, 2019

@killerlegs Can you file a bug for the pack_matrix issue with a repro? We have tests for the feature and haven't caught regressions from it. Also since your question is answered, let's close this issue :)

@MrTrillian MrTrillian closed this Jul 10, 2019
@killerlegs

This comment has been minimized.

Copy link
Author

@killerlegs killerlegs commented Jul 10, 2019

After some research, I found out that the pack_matrix bug has most likely already been fixed.
Bug 1635

I am still using DXC version: dxcompiler.dll: 1.3 that comes with Windows SDK 10.0.17763.132.

Thanks.

@MrTrillian

This comment has been minimized.

Copy link
Member

@MrTrillian MrTrillian commented Jul 10, 2019

Yup. There have been more changes after that bug was fixed but it was all around last december/january. More recent builds should be all good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.