Jump to content
  • Advertisement
Sign in to follow this  
Migi0027

OpenGL DX11 - Shaders - Writable Textures

This topic is 2130 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 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

Share this post


Link to post
Share on other sites
Advertisement

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

 

EDIT: Not solved yet!

Edited by Migi0027

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 ? Edited by unbird

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!