# DX12 [D3D12] One more bug...

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

## 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.

ConstantBuffer<Parameters> g_parameters : register(b0);
RWStructuredBuffer<uint> VisibleInstances : register(u0);

{
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);

{
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 on other sites

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?

##### 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 on other sites
Is there a way to get unbounded descriptor tables on 5_0 profiles?

##### 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 on other sites
I do not, i build it in c++

##### Share on other sites

Are you in a position to build a small repro and send it our way?

##### Share on other sites

I think so yes. I'll get to it tonight.

##### 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 on other sites
This is that we should be validating more strictly I think. Thanks for pointing it out to us.

1. 1
Rutin
25
2. 2
3. 3
JoeJ
19
4. 4
5. 5

• 11
• 11
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631753
• Total Posts
3002099
×