I'm new to DXR, so please

If I got it right, when we want to compile a ray tracing shader using the DirectX Shader Compiler, we need to specify lib_6_* as the target profile.

Now assume I've got a HLSL file containing a single ray generation shader RayGen whose root signature is specified by a RootSignature attribute of the form

#define MyRS "RootFlags(LOCAL_ROOT_SIGNATURE),"  \
        "DescriptorTable("                  \
            "UAV(u0, numDescriptors = 1),"  \
            "SRV(t0, numDescriptors = 1))"
void RayGen() {}

Using IDxcCompiler::Compile, I'm able to compile both the shader itself using the target profile lib_6_3 and the root signature using the target profile rootsig_1_1, but if I got it right it's not possible to invoke IDxcCompiler::Compile such that the created IDxcBlob contains both the shader and the root signature. (I've tried to add the argument -rootsig-define MyRS to the call for the compilation of the shader, but it seems to me that the compiler expects the root signature specified in this way to be a global root signature.)

So, I end up with two IDxcBlob's. Is there any possibility to "merge" them into a single one which can later be used to specify the shader as well in a call of ID3D12Device5::CreateRootSignature?


1 Answer 1


ID3D12Device::CreateRootSignature expects a pointer to the data, as well as the data length. You could combine your shader and root signature into one blob, but you'd need to know the offset from the start of the file to your signature (or if the signature were first, then when you create a shader you would need to know the offset from the start of the file to the compiled DXIL).

You could create a file that looked like this:


Then when you load your custom file, you would have all of the data and data lengths at your disposal.

To write an IDxcBlob, you can access the raw data and size via it's functions:

struct IDxcBlob : public IUnknown {
  virtual LPVOID STDMETHODCALLTYPE GetBufferPointer(void) = 0;
  virtual SIZE_T STDMETHODCALLTYPE GetBufferSize(void) = 0;

Then just write the data to a file with something like fwrite:

fwrite(blob->GetBufferPointer(), 1, blob->GetBufferSize(), fileHandle);
  • \$\begingroup\$ Thank you for your answer. How would I actually combine/concatenate two blobs into a single one? \$\endgroup\$
    – 0xbadf00d
    Commented Apr 11, 2021 at 7:46
  • \$\begingroup\$ @0xbadf00d, I've updated the answer to show how to access the blob data. \$\endgroup\$ Commented Apr 12, 2021 at 8:21
  • \$\begingroup\$ Thank you for your update. What I've actually meant is whether there is a utility in the API allowing me to merge two blobs. However, meanwhile I've seen that there is another way to specify a root signature in HLSL. The only problem is that when I'm trying to use this and compile the code with target profile "lib_6_3" I'm receiving the following compiler error: "The module cannot be validated by the version of the validator currently attached." I wasn't able to find anything on google. \$\endgroup\$
    – 0xbadf00d
    Commented Apr 12, 2021 at 14:10
  • \$\begingroup\$ Do you know what the cause of this is? \$\endgroup\$
    – 0xbadf00d
    Commented Apr 12, 2021 at 14:10
  • \$\begingroup\$ There's no API to merge blobs, as it's just a simple operation that can be achieved manually. I don't know anything about the error message, perhaps try a new question. \$\endgroup\$ Commented Apr 13, 2021 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .