Last active
March 14, 2020 20:15
-
-
Save yorung/24d4b21143b316fc250fc3a15043e73d to your computer and use it in GitHub Desktop.
[DX12] Extract root signature binary from a shader binary created with D3DCompileFromFile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| ComPtr<ID3DBlob> vertexShader = afCompileHLSL(shaderName, "VSMain", "vs_5_0"); | |
| ComPtr<ID3DBlob> pixelShader = afCompileHLSL(shaderName, "PSMain", "ps_5_0"); | |
| ComPtr<ID3DBlob> rootSignatureBlob; | |
| ComPtr<ID3D12RootSignature> rootSignature; | |
| if (S_OK == D3DGetBlobPart(vertexShader->GetBufferPointer(), vertexShader->GetBufferSize(), D3D_BLOB_ROOT_SIGNATURE, 0, &rootSignatureBlob)) | |
| { | |
| device->CreateRootSignature(0, rootSignatureBlob->GetBufferPointer(), rootSignatureBlob->GetBufferSize(), IID_PPV_ARGS(&rootSignature)); | |
| } | |
| ... | |
| ComPtr<ID3DBlob> afCompileHLSL(const char* name, const char* entryPoint, const char* target) | |
| { | |
| char path[MAX_PATH]; | |
| sprintf_s(path, sizeof(path), "hlsl/%s.hlsl", name); | |
| #ifdef _DEBUG | |
| UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION; | |
| #else | |
| UINT flags = D3DCOMPILE_ENABLE_STRICTNESS; | |
| #endif | |
| ComPtr<ID3DBlob> blob, err; | |
| WCHAR wname[MAX_PATH]; | |
| MultiByteToWideChar(CP_ACP, 0, path, -1, wname, dimof(wname)); | |
| HRESULT hr = D3DCompileFromFile(wname, nullptr, nullptr, entryPoint, target, flags, 0, &blob, &err); | |
| if (err) { | |
| MessageBoxA(nullptr, (const char*)err->GetBufferPointer(), name, MB_OK | MB_ICONERROR); | |
| } | |
| return blob; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment