Jump to content
  • Advertisement
Sign in to follow this  
Medium99

DX11 [HLSL] RWTexture lookups/sampling

This topic is 2656 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!

This is me, trying to find my way into DX11 (via SlimDX/C# if it matters), with some little experience in DX9, but I may be considered new to this, still.

If I try to use a RWTexture2D in a compute shader, I can do indexed writes with no problems, but I cannot look up any values!


RWTexture2D<float4> Tex : register(u0);

[numthreads(12, 12, 1)]
void main(uint3 threadID : SV_DispatchThreadID)
{
Tex[threadID.xy] = (float4)0; // works like a charm
float4 foo = Tex[threadID.xy]; // does not
}



The error states, that I may only do such lookups on buffers with 32 bit one-component resources. That would kind of complicate things for me (a lot), and seems a little odd. Is there really no way to read data from such a texture, or if yes, how?

Many thanks in advance!
Medium99

Share this post


Link to post
Share on other sites
Advertisement
Do you actually need to read from the same buffer that you're writing to?

Share this post


Link to post
Share on other sites
The issue came up for some additive stuff distributed threads may calculate, but I could work around this. The problem itself however, is unrelated. It would be cool if was possible somehow though :)

The combination is only here for pointing out that writing works, reading does not. It doesn't matter if I do both in the same run - I'd like to, but that wasn't the initiative for my question. Reads like this always fail in the mentioned way.

Share this post


Link to post
Share on other sites
I still couldn't figure this one out so far, and a slightly related question arose: I do miss the Effect.SetValue<T>() method I had with DX9 SlimDX - how can I pass simple externals into a compute shader with DX11? I don't want to waste a stream for a hand full of settings. As for the textures: Is this possible at all, or should I rather invest into re-thinking my approach from the bottom?

Share this post


Link to post
Share on other sites
Well what I was getting at before was that if you don't need to write to the buffer during the same shader execution you could bind it as a shader resource view rather than as an unordered access view, which should let you get around any restrictions associated with UAV's.

If you just need to pass a handful of constant values to your shader, then use a constant buffer.

Share this post


Link to post
Share on other sites
I finally stumbled across some infos related to just that on MSDN - it's organization is quite dreadful. I see that having started DX11/SM5 with compute shaders had me miss the changes in texture handling, namely that there's now the implicit texture object with methods and all, and pretty much anything else like constant buffers with the neat ways to structure it's contents.

These pages in the MSDN are hell to someone learning almost from scratch. If anyone knows of some better structured tutorials/references/notes on what can be done with SM5, preferably also how to interact with the host application, I would really appreciate a hint! I feel like having to do days of digging for actually clear as day stuff, that one just needs to know about, like the trap of not being able to bind the same resource as UAV and texture, and that RWTextures don't have the Sample() method like ordinary textures.

Thanks MJP!

Share this post


Link to post
Share on other sites
Yeah I hear you on the HLSL documentation...there's a big disconnect between the HLSL objects/methods and the D3D11 runtime objects and commands that relate to them.

Although I hear that there is a sweet book coming out in a few months that does a decent job explaining it. :P

Share this post


Link to post
Share on other sites
Hehe, nothing against a little self-advertising ;) I'd be happy to throw some bucks at thar if it was out already! Good docs are well worth the effort and the money, and I may thank you for the first in advance. Also, I just recognized your nice blog - plenty to look at, yay! I really should start doing some "normal" 3D stuff before I get all fancy with GPGPU and other ways to rape my GFX card... but it's all so interesting and promising, arghs :D

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!