gongminmin / KlayGE

KlayGE is a cross-platform open source game engine with plugin-based architecture.
http://www.klayge.org
GNU General Public License v2.0
2.1k stars 349 forks source link

how to share counted structured buffer uav between cs and ps? #200

Closed unrealTOM closed 5 years ago

unrealTOM commented 5 years ago

I'm creating my demo with KlayGE. Some problem arises.

I have a vertex buffer and a uav based on it. The uav is counted structured buffer uav. Then I pass the same uav as parameter to a pixel shader and a compute shader. In pixel shader, some data format float4 is appended to the buffer uav. When I try to fetch data from the uav in my compute shader, nothing got.

I struggled with it days, don't know what can be wrong. If more info is needed, I can paste some code for further investigation. Thanks in advance.

gongminmin commented 5 years ago

The UAV itself shouldn't be different between shader stages. It could be a bug in bindings. I'll write a test for it. Thanks.

gongminmin commented 5 years ago

New tests are added to test/UavOutput branch for writing from PS and read from CS. The content is correct, it doesn't repro what you descried.

However, the counter itself is cleared to 0 when setting to CS. Is this what you meant?

unrealTOM commented 5 years ago

I compared your test code with my code, and found that I was using the following code to bind uav to ps. '*(effect_->ParameterByName("xxx")) = uav;

I modified my code and finally got uav working. Thanks.

In DX11, there's an option whether to clear the counter when binding the uav. But I didn't find any place to do the same thing with KlayGE. I don't need such mechanism right now. Maybe the interface can be optimized in proper time.

gongminmin commented 5 years ago

There is an function to set the initial count. But the value is not used when setting a uav to CS. I'm fixing it.