Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Request for Toolkit enhancement - device.ResetUnorderedAccessViews() and/or better diagnostics. #211

Closed
MichaelKoivisto opened this issue Nov 22, 2013 · 3 comments

Comments

@MichaelKoivisto
Copy link

Hi all,

I believe the Toolkit would benefit from a nice solution to the following problem:

There should be some quick way to unset UnorderedAccessViews from a GraphicsDevice. Something like device.ResetUnorderedAccessViews().

Of course, in current version someone can do it using code like

        SharpDX.Direct3D11.DeviceContext dc = device;
        dc.ComputeShader.SetUnorderedAccessView(0, null);

But a device.ResetUnorderedAccessViews() would be more handy.

Another alternative is to change EffectPass.ApplyInternal() so that it automatically unsets UnorderedAccessView from ComputeShader if you are trying to bind it as ShaderResourceView.

Typical usecase for this is pyramidal image reduction with compute shaders (e.g. for blur or similar image effects) on dx10 hardware profile using SharpDX Effects framework.

DirectX 10 hardware allows just one UnorderedAccessView to be bound to pipeline. In pyramidal image reduction, one UnorderedAccessView is used as a buffer for results from first stage. Second stage of image reduction algorithm needs to use the buffer from previous stage as input (while using another UnorderedAccessView fro output). If the buffer was bound as UnorderedAccessView, attempt to bind it as ShaderResourceView results in incorrect behavior - zero input for compute shader, but no error or exception. This is very confusing and hard to debug. Some SharpDX exception would be nice in this case. Or some automatic unsetting (inside EffectPass.ApplyInternal) of that UnorderedAccessView.

How should I proceed with possible enhancement? Should I suggest some code, or should I wait for core SharpDX developers to make a decision on this?

@ArtiomCiumac
Copy link
Contributor

It would be great if you could suggest some code via a pull request (ideally, with a sample in SharpDXToolkitSamples.sln, but this is not strictly necessary).

The functionality could have something like GraphicsDevice.SetUnorderedAccessView(<uaw's here..>) (similar to GraphicsDevice.SetRenderTargets(params RenderTargetView[] renderTargetViews)) and GraphicsDevice.ResetUnorderedAccessView() (similar to GraphicsDevice.ResetTargets()).

@xoofx
Copy link
Member

xoofx commented Nov 23, 2013

There is currently EffectPass.Unapply() that unbinds everything, it is probably not optimal but at least provide a way to do it with current API. But feel free to pull request a GraphicsDevice.ResetUnorderedAccessView() (specifying in the doc that it is for compute shaders only)

@xoofx
Copy link
Member

xoofx commented Jan 21, 2014

After double checking, actually the only way to correctly reset slots is to use EffectPass.Unapply() as dc.ComputeShader.SetUnorderedAccessView(0, null); is only going to remove the first UAV (but won't remove them on other slots if there are any). Unlike SetRenderTarget, SetUAV is working on per slot basis, so we must explicitly free the slots that were used. Using EffectPass.UnApply() is explicitly resetting these slots.

@xoofx xoofx closed this as completed Jan 21, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants