• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By fs1
      I have been trying to see how the ID3DInclude, and how its methods Open and Close work.
      I would like to add a custom path for the D3DCompile function to search for some of my includes.
      I have not found any working example. Could someone point me on how to implement these functions? I would like D3DCompile to look at a custom C:\Folder path for some of the include files.
      Thanks
    • By stale
      I'm continuing to learn more about terrain rendering, and so far I've managed to load in a heightmap and render it as a tessellated wireframe (following Frank Luna's DX11 book). However, I'm getting some really weird behavior where a large section of the wireframe is being rendered with a yellow color, even though my pixel shader is hard coded to output white. 

      The parts of the mesh that are discolored changes as well, as pictured below (mesh is being clipped by far plane).

      Here is my pixel shader. As mentioned, I simply hard code it to output white:
      float PS(DOUT pin) : SV_Target { return float4(1.0f, 1.0f, 1.0f, 1.0f); } I'm completely lost on what could be causing this, so any help in the right direction would be greatly appreciated. If I can help by providing more information please let me know.
    • By evelyn4you
      Hello,
      i try to implement voxel cone tracing in my game engine.
      I have read many publications about this, but some crucial portions are still not clear to me.
      At first step i try to emplement the easiest "poor mans" method
      a.  my test scene "Sponza Atrium" is voxelized completetly in a static voxel grid 128^3 ( structured buffer contains albedo)
      b. i dont care about "conservative rasterization" and dont use any sparse voxel access structure
      c. every voxel does have the same color for every side ( top, bottom, front .. )
      d.  one directional light injects light to the voxels ( another stuctured buffer )
      I will try to say what i think is correct ( please correct me )
      GI lighting a given vertecie  in a ideal method
      A.  we would shoot many ( e.g. 1000 ) rays in the half hemisphere which is oriented according to the normal of that vertecie
      B.  we would take into account every occluder ( which is very much work load) and sample the color from the hit point.
      C. according to the angle between ray and the vertecie normal we would weigth ( cosin ) the color and sum up all samples and devide by the count of rays
      Voxel GI lighting
      In priciple we want to do the same thing with our voxel structure.
      Even if we would know where the correct hit points of the vertecie are we would have the task to calculate the weighted sum of many voxels.
      Saving time for weighted summing up of colors of each voxel
      To save the time for weighted summing up of colors of each voxel we build bricks or clusters.
      Every 8 neigbour voxels make a "cluster voxel" of level 1, ( this is done recursively for many levels ).
      The color of a side of a "cluster voxel" is the average of the colors of the four containing voxels sides with the same orientation.

      After having done this we can sample the far away parts just by sampling the coresponding "cluster voxel with the coresponding level" and get the summed up color.
      Actually this process is done be mip mapping a texture that contains the colors of the voxels which places the color of the neighbouring voxels also near by in the texture.
      Cone tracing, howto ??
      Here my understanding is confus ?? How is the voxel structure efficiently traced.
      I simply cannot understand how the occlusion problem is fastly solved so that we know which single voxel or "cluster voxel" of which level we have to sample.
      Supposed,  i am in a dark room that is filled with many boxes of different kind of sizes an i have a pocket lamp e.g. with a pyramid formed light cone
      - i would see some single voxels near or far
      - i would also see many different kind of boxes "clustered voxels" of different sizes which are partly occluded
      How do i make a weighted sum of this ligting area ??
      e.g. if i want to sample a "clustered voxel level 4" i have to take into account how much per cent of the area of this "clustered voxel" is occluded.
      Please be patient with me, i really try to understand but maybe i need some more explanation than others
      best regards evelyn
       
       
    • By Endemoniada

      Hi guys, when I do picking followed by ray-plane intersection the results are all wrong. I am pretty sure my ray-plane intersection is correct so I'll just show the picking part. Please take a look:
       
      // get projection_matrix DirectX::XMFLOAT4X4 mat; DirectX::XMStoreFloat4x4(&mat, projection_matrix); float2 v; v.x = (((2.0f * (float)mouse_x) / (float)screen_width) - 1.0f) / mat._11; v.y = -(((2.0f * (float)mouse_y) / (float)screen_height) - 1.0f) / mat._22; // get inverse of view_matrix DirectX::XMMATRIX inv_view = DirectX::XMMatrixInverse(nullptr, view_matrix); DirectX::XMStoreFloat4x4(&mat, inv_view); // create ray origin (camera position) float3 ray_origin; ray_origin.x = mat._41; ray_origin.y = mat._42; ray_origin.z = mat._43; // create ray direction float3 ray_dir; ray_dir.x = v.x * mat._11 + v.y * mat._21 + mat._31; ray_dir.y = v.x * mat._12 + v.y * mat._22 + mat._32; ray_dir.z = v.x * mat._13 + v.y * mat._23 + mat._33;  
      That should give me a ray origin and direction in world space but when I do the ray-plane intersection the results are all wrong.
      If I click on the bottom half of the screen ray_dir.z becomes negative (more so as I click lower). I don't understand how that can be, shouldn't it always be pointing down the z-axis ?
      I had this working in the past but I can't find my old code
      Please help. Thank you.
    • By turanszkij
      Hi,
      I finally managed to get the DX11 emulating Vulkan device working but everything is flipped vertically now because Vulkan has a different clipping space. What are the best practices out there to keep these implementation consistent? I tried using a vertically flipped viewport, and while it works on Nvidia 1050, the Vulkan debug layer is throwing error messages that this is not supported in the spec so it might not work on others. There is also the possibility to flip the clip scpace position Y coordinate before writing out with vertex shader, but that requires changing and recompiling every shader. I could also bake it into the camera projection matrices, though I want to avoid that because then I need to track down for the whole engine where I upload matrices... Any chance of an easy extension or something? If not, I will probably go with changing the vertex shaders.
  • Advertisement
  • Advertisement
Sign in to follow this  

DX11 DX11 - Write to Texture2D UAV, read from Texture2D SRV

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

Hello,
If anybody could please offer me some advice, I would be very grateful.

Currently, if it worked ideally: I write to a UAV Texture2D in the Pixel Shader. I then pass that Texture2D as an SRV into another shader to be read.
However currently, all that displays is the colour white that I clear the UAV with when I call the following line:

const float zero[4] = { 1, 1, 1, 1 };
DX11AppHelper::_pImmediateContext->ClearUnorderedAccessViewFloat(mUAV, zero);
 
I am currently rendering a fullscreen quad for the testing of this. Apologies if this forum post is done badly, I've never done one before.
 
Here is the the initialisation code for the Texture2D, the UAV and the SRV:
 
D3D11_TEXTURE2D_DESC dstex;
ZeroMemory(&dstex, sizeof(dstex));
dstex.Width = DX11AppHelper::_pRenderWidth;
dstex.Height = DX11AppHelper::_pRenderHeight;
dstex.MipLevels = 1;
dstex.ArraySize = 1;
dstex.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
dstex.SampleDesc.Count = 1;
dstex.Usage = D3D11_USAGE_DEFAULT;
dstex.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
dstex.CPUAccessFlags = 0;
dstex.MiscFlags = 0;
 
if (FAILED(DX11AppHelper::_pd3dDevice->CreateTexture2D(&dstex, nullptr, &mOctreeStructure)))
{
return E_FAIL;
}
 
// Create the render target views.
D3D11_UNORDERED_ACCESS_VIEW_DESC  UAVDesc;
ZeroMemory(&UAVDesc, sizeof(UAVDesc));
UAVDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
UAVDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
UAVDesc.Texture2D.MipSlice = 0;
 
if (FAILED(DX11AppHelper::_pd3dDevice->CreateUnorderedAccessView(mOctreeStructure, &UAVDesc, &mUAV)))
{
return E_FAIL;
}
 
 
// Create the resource view.
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
ZeroMemory(&SRVDesc, sizeof(SRVDesc));
SRVDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
SRVDesc.Texture2D.MostDetailedMip = 0;
SRVDesc.Texture2D.MipLevels = 1;
 
if (FAILED(DX11AppHelper::_pd3dDevice->CreateShaderResourceView(mOctreeStructure, &SRVDesc, &mSRV)))
{
return E_FAIL;
}
 
 
Here is my Pixel Shader which I write to the UAV with:
 
RWTexture2D<float4> octree;
 
//--------------------------------------------------------------------------------------
// Pixel Shader Write
//--------------------------------------------------------------------------------------
void PS(VS_OUTPUT input)
{
//float4 finalColour = float4(0.0f, 0.0f, 0.0f, 1.0f);
 
octree[uint2(input.Tex.x, input.Tex.y)] = float4(0.0f, 1.0f, 0.0f, 0.0f);
 
//return finalColour;
}
 
Here is my Pixel Shader that I read the SRV with:
 
Texture2D txDiffuse : register(t0);
 
//--------------------------------------------------------------------------------------
// Pixel Shader Read
//--------------------------------------------------------------------------------------
float4 PS(VS_OUTPUT input) : SV_Target
{
float4 textureColour = txDiffuse.Sample(samLinear, input.Tex);
 
return textureColour;
}
Edited by AlisdairTW

Share this post


Link to post
Share on other sites
Advertisement

Whenever you have any D3D problems, first check what the D3D debug layer has to say.
Create your D3D11 device using the D3D11_CREATE_DEVICE_DEBUG flag, and then enable break-on-error and break-on-warning, and then fix all the D3D errors/warnings:

ID3D11InfoQueue* debugInfoQueue = 0;
m_device->QueryInterface(IID_ID3D11InfoQueue, (void**)&debugInfoQueue);
if(debugInfoQueue) 
{
  m_debugInfoQueue->SetBreakOnSeverity( D3D11_MESSAGE_SEVERITY_CORRUPTION, TRUE );
  m_debugInfoQueue->SetBreakOnSeverity( D3D11_MESSAGE_SEVERITY_ERROR, TRUE );
  m_debugInfoQueue->SetBreakOnSeverity( D3D11_MESSAGE_SEVERITY_WARNING, TRUE );
  m_debugInfoQueue->Release();
}

For most of development you should have the debug layer enabled, and break-on-error / break-on-corruption enabled. Break-on-warning is less important, but still worth checking.

I also recommend using renderdoc to investigate why any particular D3D command isn't doing what you think it should be doing.

Apologies if this forum post is done badly, I've never done one before

Use:

[code][/code]

To format code sections properly :)

 

Do you un-bind the UAV before you bind the SRV? You're not allowed to have any particular resource simultaneously bound for writing (UAV/RTV/DSV) and for reading (SRV).

Share this post


Link to post
Share on other sites

Hello, it's AlisdairTW, I had to create another account as gamedev didn't seem to respond to me signing in with Google today for some reason.

Anywho, I have the debug layer enabled, and I am not getting any errors or warnings from it.

I believe I am correctly unbinding and binding the SRV's and UAV's each time I use them, here is the code for when I call the full screen quad, which is the shader I use to write to the Texture2D with the UAV:

const float zero[4] = { 1, 1, 1, 1 }; 
DX11AppHelper::_pImmediateContext->ClearUnorderedAccessViewFloat(mUAV, zero); 
DX11AppHelper::_pImmediateContext->OMSetRenderTargetsAndUnorderedAccessViews(0, NULL, NULL, 0, 1, &mTexture2DUAV, 0);  // Bind the Texture2D UAV 
DX11AppHelper::_pImmediateContext->IASetInputLayout(mInputLayout);   
DX11AppHelper::_pImmediateContext->VSSetShader(mVertexShader, nullptr, 0); 
DX11AppHelper::_pImmediateContext->PSSetShader(mPixelShader, nullptr, 0);   
DX11AppHelper::_pImmediateContext->PSSetSamplers(0, 1, &mSamplerLinear);   
DX11AppHelper::_pImmediateContext->IASetVertexBuffers(0, 1, &mQuadVertexBuffer, &mQuadStride, &mQuadOffset); 
DX11AppHelper::_pImmediateContext->IASetIndexBuffer(mQuadIndexBuffer, DXGI_FORMAT_R16_UINT, 0);   
DX11AppHelper::_pImmediateContext->DrawIndexed(6, 0, 0);   ID3D11UnorderedAccessView* nullUAV = nullptr; 
DX11AppHelper::_pImmediateContext->OMSetRenderTargetsAndUnorderedAccessViews(0, nullptr, nullptr, 0, 1, &nullUAV, 0);  // UnBind the Texture2D UAV

Here is the code to then execute the second shader, and I am also binding and then unbinding the SRV before and after.

DX11AppHelper::_pImmediateContext->OMSetRenderTargets(1, &_pRenderTargetViews[0], nullptr);
DX11AppHelper::_pImmediateContext->ClearRenderTargetView(_pRenderTargetViews[0], _pClearColour);
DX11AppHelper::_pImmediateContext->IASetInputLayout(,InputLayout);
DX11AppHelper::_pImmediateContext->VSSetShader(mVertexShader, nullptr, 0);
 
DX11AppHelper::_pImmediateContext->PSSetShader(mPixelShader, nullptr, 0);
DX11AppHelper::_pImmediateContext->VSSetConstantBuffers(0, 1, &,ConstantBuffer);
DX11AppHelper::_pImmediateContext->PSSetConstantBuffers(0, 1, &,ConstantBuffer);
 
DX11AppHelper::_pImmediateContext->PSSetShaderResources(0, 1, &mTexture2DSRV)); // Bind SRV
DX11AppHelper::_pImmediateContext->IASetVertexBuffers(0, 1, &_pQuadVertexBuffer, &_pQuadStride, &_pQuadOffset);
DX11AppHelper::_pImmediateContext->IASetIndexBuffer(_pQuadIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
DX11AppHelper::_pImmediateContext->UpdateSubresource(DX11AppHelper::_pConstantBuffer, 0, nullptr, &cb, 0, 0);
DX11AppHelper::_pImmediateContext->DrawIndexed(6, 0, 0);
ID3D11ShaderResourceView* nullShaderResourceView nullShaderResourceView = nullptr;
DX11AppHelper::_pImmediateContext->PSSetShaderResources(0, 1, &nullShaderResourceView); // Unbind SRV

I believe I am doing it correctly?

 

All I am getting on my screen is the cleared white colour of the UAV from the line:

 

const float zero[4] = { 1, 1, 1, 1 };
DX11AppHelper::_pImmediateContext->ClearUnorderedAccessViewFloat(mUAV, zero); 

 

Which makes me think I am setting the UAV incorrectly for the first shader perhaps?

Edited by Alisdair101

Share this post


Link to post
Share on other sites
Same problem as another guy here recently, the bracket operator use non normalized coordinate, use trunc(sv_position.xy) for the writing.

Share this post


Link to post
Share on other sites

That is amazing, thank you.

It is working in that regard now, however the endgame of my work is to selectively pick which pixel I want to write to, as I want to store non-image data in the Texture2D, I want to store quad tree data, and I am bit confused as to why I cannot just tell it to write to pixel (x, y) of my choosing.

e.g. octree[0, 0] = float4(0.0f, 1.0f, 0.0f, 0.0f);

then octree[0, 1] = float4(1.0f, 1.0f, 0.0f, 0.0f); and so on

How would I go about doing that, or is that not posssible?

Share this post


Link to post
Share on other sites

That's possible, yes. In fact you demonstrated that you knew how to write it in your first post:

octree[uint2(0, 1)] = float4(1,1,0,0);

octree[uint2(9,12)] = somethingElse; etc

Share this post


Link to post
Share on other sites

That is amazing, thank you.

It is working in that regard now, however the endgame of my work is to selectively pick which pixel I want to write to, as I want to store non-image data in the Texture2D, I want to store quad tree data, and I am bit confused as to why I cannot just tell it to write to pixel (x, y) of my choosing.

e.g. octree[0, 0] = float4(0.0f, 1.0f, 0.0f, 0.0f);

then octree[0, 1] = float4(1.0f, 1.0f, 0.0f, 0.0f); and so on

How would I go about doing that, or is that not posssible?

You can. What he is saying is that there's a very high chance that input.Tex.x & input.Tex.y are floats in range [0; 1] when they should be uint in range [0; texWidth) and range [0; texHeight).

So basically when you write to pixel location (0.75; 0.75) you end up writing to (0, 0) (the first pixel) instead of writing to (768; 384) of a 1024x512 texture.

Share this post


Link to post
Share on other sites

Cheers for all the help guys, one last question.

I am writing to the UAV correctly, thanks again everyone. Is there any way of effectively debugging the data in the Texture3D?

Edited by Alisdair101

Share this post


Link to post
Share on other sites

No problem :) The main question has been solved, is it possible for someone else to mark it as solved as I cannot gain access to my original account as for some reason, as GameDev doesn't like my logging in with Google.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement