Jump to content
  • Advertisement
Sign in to follow this  
Shnoutz

DX12 [D3D12] One more bug...

This topic is 837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,
 
Porting my stuff to DirectX12 is proving to be a real challenge.
 
Right now I am in the process of converting my gpu occlusion code to DX12 and I noticed something very strange.
 
First off, this bug is happening with and without using WARP adapter.
 
I have the following shader:
 
ConstantBuffer<Parameters> g_parameters : register(b0);
RWStructuredBuffer<uint> VisibleInstances : register(u0);

[numthreads(64, 1, 1)]
void cs_cullInstances(uint3 DTid : SV_DispatchThreadID)
{
    uint instance = DTid.x;
    if(instance < g_parameters.instanceCount)
         VisibleInstances[instance] = instance;
}

Inspecting the buffer reveals that all the values are "0".

 
Before you ask, "g_parameters.instanceCount" is not 0 and  the buffer was filled with 0xffff so I could see if something was actually written to it.
 
If I slightly change the shader to:
(Removing "instance")
ConstantBuffer<Parameters> g_parameters : register(b0);
RWStructuredBuffer<uint> VisibleInstances : register(u0);

[numthreads(64, 1, 1)]
void cs_cullInstances(uint3 DTid : SV_DispatchThreadID)
{
    if(DTid.x < g_parameters.instanceCount)
         VisibleInstances[DTid.x] = DTid.x;
}

Then VisibleInstances contains what I would expect.. {0, 1, 2, 3, ... }

 
I am building shaders using cs_5_1.
 
I could paste the dissassembled code but I can tell you that the only difference is that the first listing puts the value of DTid.x in r0.x before using it where DTid.x is used in the second listing.
 
Any idea what is going on?

Share this post


Link to post
Share on other sites
Advertisement

Does it make any difference if you compile the shaders as cs_5_0?

 

At least on the compiler I have here, there's only a difference in the compiled DXBC if I use /Od to disable optimisations. Are you using /Od?

Edited by Adam Miles

Share this post


Link to post
Share on other sites

I am using /Od in debug but the problem is also in release (without /Od).

 

I had to convert some shaders to build with cs_5_0 but I was able to test it.

It does appear that the problem is specific to cs_5_1 as I get the expected behavior using cs_5_0.

Share this post


Link to post
Share on other sites

No, there isn't.

 

I take it from your code snippet that you aren't providing a root signature at compile time?

Share this post


Link to post
Share on other sites

Sorry Adam I could not get back to you sooner but I found the issue and its not related to the shader compiler.

 

The problem was not "DTid.x" but "g_parameters.instanceCount".

 

After our discussion, I tried to isolate the problem in a smaller program and I could not get a 100% repro.

 

I am using root constants to pass "g_parameters.instanceCount" and in the smaller app, it was not packed the same way as in my big app.

Then I realized that root constants follows the same packing rules as constant buffers.

 

My root signature contained 7 root 32bits values to map to an hlsl struct that looks like this:

 

struct

{

    float3 minC;

        // < automatic padding here!! >

    float3 maxC;

    uint instanceCount;

};

 

I moved "instanceCount" after "minC" and it worked. I could also have added a 32bit value in the root signature to account for padding.

 

So I learned something... Treat root constants just as you would treat constant buffers (in term of packing rules).

 

Cheers!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!