DX11 - Shaders - Writable Textures

Started by
24 comments, last by Migi0027 10 years, 7 months ago

Hi guys, wink.png

I'm researching techniques for scene voxelization, and so far, only few papers has been found, but I found a great one! So now I'm in the process of creating the shader, but a problem stroke my mind, the paper is based on OpenGl (Theory is the same), and OpenGl has completely re-writable textures, in the shader, like so:


imageStore(voxelColor, voxelPos, outColor);

// voxelColor -> 3D Texture
// voxelPos   -> xyz Position of texture
// outColor, well, the data needed to be written

How can this be achieved with Directx 11 with HLSL? (Maybe I forgot something... Like usual tongue.png )

Thanks, as usual!

-MIGI0027

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Advertisement
Pixel and Compute shaders can both write to textures if you use RWTexture objects; http://msdn.microsoft.com/en-us/library/windows/desktop/ff471511(v=vs.85).aspx

Thanks for making me aware of that, but I thought that you could only output data from the computer shader, is it possible to write to it in the pixel shader?

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

On D3D11/SM5 hardware yes; compute and pixel are the only stages which can write out.

D3D11.1 expands UAV support to all stages so you can write from basically anywhere.

Damn, sorry, didn't fully read your comment, sorry about that... unsure.png

EDIT: Not solved yet!

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Sorry to annoy you further, but I have one last question regarding this topic.

Q: Do you send the 3D Texture (in this case), just like a read only shader resource [DeviceContext->XSSetShaderResources(....)], or do they require a different method?

-MIGI0027

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

You don't use a shader resource view, you need to create an unordered access view (UAV) for the texture that you want to write to. To bind it to a compute shader you use CSSetUnorderedAccessViews, and to a pixel shader you use OMSetRenderTargetsAndUnorderedAccessViews.

Hi again, thanks btw! happy.png

Another question...

How would one send such a resource to the GPU for reading to the PS, without setting any render targets. Here's my questions:

  • When calling OMSetRenderTargetsAndUnorderedAccessViews, if you set the backbuffer, numRTS, RTS to NULL, does it set the render targets to NULL, or does it skip the placement of the render targets.
  • Is there a way of treating the content of an UAV as a SRV?

Thanks

-MIGI0027

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

When calling OMSetRenderTargetsAndUnorderedAccessViews, if you set the backbuffer, numRTS, RTS to NULL, does it set the render targets to NULL, or does it skip the placement of the render targets.

Not that I have tried (never used UAVs with pixel shaders), but docs are somewhat clear.

Specify NULL to set none.

If that doesn't work, use a array with explicit NULLs.

Is there a way of treating the content of an UAV as a SRV?


Nope, it's a different view, you have to create one. IIRC one can create an arbitrary amount of views for any resource. You only need to make sure that the corresponding bind flag was set when creating the resource and you don't have read/write hazards. So in this case don't bind both the UAV and SRV at once. You won't need to anyway, UAVs are read and write. Not saying that it is always a good idea to do, sometimes a ping-pong approach with two resources is better or even the only possibility.

By the way: You made me curious. You don't mind posting links to that papers, please ?

Unbird, thanks! (You too MJP, Phantom).

Paper: http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-SparseVoxelization.pdf

I've read one or two more, but I don't have their address right now, forgot them wacko.png ...

Thanks! Again...

-MIGI0027

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

This topic is closed to new replies.

Advertisement