• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
pnt1614

DX11
how to solve "Resource being set to OM UnorderedAccessView slot 1 is still bound on input" error?

4 posts in this topic

I am trying to modify OIT example by yakiimo [url="http://www.yakiimo3d.com/2010/07/25/dx11-order-independent-transparency-with-msaa/"]http://www.yakiimo3d...ency-with-msaa/[/url] but there is some problems that I do not know to solve. First, I got a wrong rendering result and in Output message, I got "ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews: Resource being set to OM UnorderedAccessView slot 1 is still bound on input"

The yakiimo's result:
[img]http://img823.imageshack.us/img823/6963/origml.jpg[/img]

My result
[img]http://img15.imageshack.us/img15/4998/mineul.jpg[/img]

The simplesampe11.cpp (render function)
[CODE]
HRESULT hr;
// If the settings dialog is being shown, then render it instead of rendering the app's scene
if( g_SettingsDlg.IsActive() )
{
g_SettingsDlg.OnRender( fElapsedTime );
return;
}
// Get the projection & view matrix from the camera class
D3DXMATRIX mWorld = *g_Camera.GetWorldMatrix();
D3DXMATRIX mView = *g_Camera.GetViewMatrix();
D3DXMATRIX mProj = *g_Camera.GetProjMatrix();
D3DXMATRIX mWorldViewProjection = mWorld * mView * mProj;
D3DXMATRIX mViewProjection = mView * mProj;

#pragma region backup RS and DST
ID3D11RasterizerState* pOldState;
pd3dImmediateContext->RSGetState( &pOldState );
ID3D11DepthStencilState* pDepthStencilStateStored = NULL;
UINT stencilRef;
pd3dImmediateContext->OMGetDepthStencilState( &pDepthStencilStateStored, &stencilRef );
#pragma endregion

const DXGI_SURFACE_DESC* pBackBufferDesc = DXUTGetDXGIBackBufferSurfaceDesc();

#pragma region configure values like constant buffetrs, rs, dst
D3D11_MAPPED_SUBRESOURCE MappedResource;
V( pd3dImmediateContext->Map( g_pPS_CB, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) );
PS_CB* pPS_CB = ( PS_CB* )MappedResource.pData;
pPS_CB->nFrameWidth = pBackBufferDesc->Width;
pPS_CB->nFrameHeight = pBackBufferDesc->Height;
pd3dImmediateContext->Unmap( g_pPS_CB, 0 );
pd3dImmediateContext->PSSetConstantBuffers( 0, 1, &g_pPS_CB );
pd3dImmediateContext->RSSetState( g_pRS );
pd3dImmediateContext->OMSetDepthStencilState( g_pDepthStencilState, 0 );
#pragma endregion

g_storeFragments.OnRender( pd3dImmediateContext, pd3dDevice, &mWorld, &mViewProjection,
g_pFragmentLinkUAV, g_pStartOffsetUAV, pBackBufferDesc, g_pPS_CB );

ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView();
ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView();
pd3dImmediateContext->OMSetRenderTargets( 1, &pRTV, pDSV );
float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
pd3dImmediateContext->OMSetDepthStencilState( g_pDepthStencilState, 0 );
pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor );

gsortFragmentsAndRender.OnRender( pd3dImmediateContext, pd3dDevice, pBackBufferDesc,
g_pFragmentLinkSRV, g_pStartOffsetSRV, g_pPS_CB );

#pragma region restore and release RS with DST
pd3dImmediateContext->RSSetState( pOldState );
SAFE_RELEASE( pOldState );

pd3dImmediateContext->OMSetDepthStencilState( pDepthStencilStateStored, stencilRef );
SAFE_RELEASE( pDepthStencilStateStored );
SAFE_RELEASE( pRTV );
SAFE_RELEASE( pDSV );
#pragma endregion

#pragma region the others
DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
g_HUD.OnRender( fElapsedTime );
g_SampleUI.OnRender( fElapsedTime );
RenderText();
DXUT_EndPerfEvent();
static DWORD dwTimefirst = GetTickCount();
if ( GetTickCount() - dwTimefirst > 5000 )
{
OutputDebugString( DXUTGetFrameStats( DXUTIsVsyncEnabled() ) );
OutputDebugString( L"\n" );
dwTimefirst = GetTickCount();
}
#pragma endregion
[/CODE]


the StoreFragments.cpp (render function)
[CODE]
HRESULT hr;

#pragma region clear Render target & depth stencil & UAV
float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView();
pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor );
ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView();
pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0f, 0 );

static const UINT clearValueUINT[1] = { 0xFFFFFFFF };
pd3dImmediateContext->ClearUnorderedAccessViewUint( pStartOffsetUAV, clearValueUINT );
#pragma endregion

#pragma region update constant buffers
D3D11_MAPPED_SUBRESOURCE MappedResource;
V( pd3dImmediateContext->Map( m_pVS_CB, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) );
VS_CB* pVS_CB = ( VS_CB* )MappedResource.pData;
D3DXMatrixTranspose( &pVS_CB->m_mWorldViewProjection, pmViewProj );
pd3dImmediateContext->Unmap( m_pVS_CB, 0 );
pd3dImmediateContext->VSSetConstantBuffers( 0, 1, &m_pVS_CB );
#pragma endregion

#pragma region set UAV & RTV
ID3D11UnorderedAccessView* pUAVs[2];
pUAVs[0] = pFragmentLinkUAV;
pUAVs[1] = pStartOffsetUAV;
UINT Indices[] = {0, 0};
pd3dImmediateContext->OMSetRenderTargetsAndUnorderedAccessViews( 0, NULL, pDSV, 0, 2, pUAVs, Indices );
#pragma endregion

#pragma region set VB & render
UINT uStrides = sizeof( SCENE_VERTEX );
UINT uOffsets = 0;
pd3dImmediateContext->IASetVertexBuffers( 0, 1, &m_pVB, &uStrides, &uOffsets );
pd3dImmediateContext->IASetIndexBuffer( NULL, DXGI_FORMAT_R32_UINT, 0 );
pd3dImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );
pd3dImmediateContext->IASetInputLayout( m_pVertexLayout );
pd3dImmediateContext->VSSetShader( m_pVS, NULL, 0 );
pd3dImmediateContext->PSSetShader( m_pPS, NULL, 0 );
pd3dImmediateContext->Draw( 4, 0 );

uOffsets = 4*sizeof( SCENE_VERTEX );
pd3dImmediateContext->IASetVertexBuffers( 0, 1, &m_pVB, &uStrides, &uOffsets );
pd3dImmediateContext->Draw( 4, 0 );

uOffsets = 8*sizeof( SCENE_VERTEX );
pd3dImmediateContext->IASetVertexBuffers( 0, 1, &m_pVB, &uStrides, &uOffsets );
pd3dImmediateContext->Draw( 4, 0 );
#pragma endregion
[/CODE]


The SortAndRenderFragments.cpp (render function)
[CODE]
#pragma region Save the old viewport
D3D11_VIEWPORT vpOld[D3D11_VIEWPORT_AND_SCISSORRECT_MAX_INDEX];
UINT nViewPorts = 1;
pd3dImmediateContext->RSGetViewports( &nViewPorts, vpOld );
#pragma endregion

#pragma region Setup the viewport to match the backbuffer
D3D11_VIEWPORT vp;
vp.Width = static_cast< float >( pBackBufferDesc->Width );
vp.Height = static_cast< float >( pBackBufferDesc->Height );
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
pd3dImmediateContext->RSSetViewports( 1, &vp );
#pragma endregion

#pragma region setup buffer and render
UINT strides = sizeof( SCREEN_VERTEX );
UINT offsets = 0;
ID3D11Buffer* pBuffers[1] = { m_pVB };
pd3dImmediateContext->IASetInputLayout( m_pQuadLayout );
pd3dImmediateContext->IASetVertexBuffers( 0, 1, pBuffers, &strides, &offsets );
pd3dImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );
ID3D11ShaderResourceView* aRViews[ 2 ] = { pFragmentLinkSRV, pStartOffsetSRV };
pd3dImmediateContext->PSSetShaderResources( 0, 2, aRViews );
pd3dImmediateContext->VSSetShader( m_pVS, NULL, 0 );
pd3dImmediateContext->PSSetShader( m_pPS, NULL, 0 );
pd3dImmediateContext->Draw( 4, 0 );
#pragma endregion

// Restore the Old viewport
pd3dImmediateContext->RSSetViewports( nViewPorts, vpOld );
[/CODE]

The StoreFragments.hlsl, it is the same with original one
[CODE]
#include "OITShaderCommon.h"
cbuffer cbPerObject : register( b0 )
{
matrix g_mWorldViewProjection : packoffset( c0 );
}
struct SceneVS_Input
{
float4 pos : POSITION;
float4 color : COLOR;
};
struct SceneVS_Output
{
float4 pos : SV_POSITION;
float4 color : COLOR0;
};
// Fragment And Link Buffer
RWStructuredBuffer< FragmentLink > FLBuffer : register( u0 );
// Start Offset Buffer
RWByteAddressBuffer StartOffsetBuffer : register( u1 );
//----------------------------Vertex shader---------------------------
SceneVS_Output SceneVS( SceneVS_Input input )
{
SceneVS_Output output;

output.color = input.color;
output.pos = mul(input.pos, g_mWorldViewProjection );

return output;
}
//Store fragments into a linked-list buffer.
[earlydepthstencil]
void StoreFragmentsPS( SceneVS_Output input )
{
uint x = input.pos.x; // [0,g_nFrameWidth]
uint y = input.pos.y; // [0,g_nFrameHeight]
// Create fragment data.
uint4 nColor = saturate( input.color ) * 255;
FragmentLink element;
element.fragmentData.nColor = (nColor.x) | (nColor.y << 8) | (nColor.z << 16) | (nColor.a << 24);
element.fragmentData.fDepth = input.pos.z;
// Increment and get current pixel count.
uint nPixelCount= FLBuffer.IncrementCounter();
// Read and update Start Offset Buffer.
uint nIndex = y * g_nFrameWidth + x;
uint nStartOffsetAddress = 4 * nIndex;
uint nOldStartOffset;
StartOffsetBuffer.InterlockedExchange(
nStartOffsetAddress, nPixelCount, nOldStartOffset );
// Store fragment link.
element.nNext = nOldStartOffset;
FLBuffer[ nPixelCount ] = element;
}
[/CODE]

The SortAndRenderFragments.hlsl
[CODE]
#include "OITShaderCommon.h"
StructuredBuffer<FragmentLink> FragmentLinkSRV : register(t0);
Buffer<uint> StartOffsetSRV : register(t1);
struct QuadVSinput
{
float4 pos : POSITION;
};
struct QuadVS_Output
{
float4 pos : SV_POSITION;
};
/**
Draw full screen quad.
*/
QuadVS_Output QuadVS( QuadVSinput Input )
{
QuadVS_Output Output;
Output.pos = Input.pos;
return Output;
}
// Max hardcoded.
// We're in trouble if the fragment linked list is larger than 32...
#define TEMPORARY_BUFFER_MAX 32
/**
Sort and render fragments.
*/
float4 SortFragmentsPS( QuadVS_Output input ) : SV_Target0
{
// index to current pixel.
uint nIndex = (uint)input.pos.y * g_nFrameWidth + (uint)input.pos.x;

FragmentData aData[ TEMPORARY_BUFFER_MAX ]; // temporary buffer
int anIndex[ TEMPORARY_BUFFER_MAX ]; // index array for the tempory buffer
uint nNumFragment = 0; // number of fragments in current pixel's linked list.
uint nNext = StartOffsetSRV[ nIndex ]; // get first fragment from the start offset buffer.

// early exit if no fragments in the linked list.
if( nNext == 0xFFFFFFFF ) {
return float4( 0.0, 0.0, 0.0, 0.0 );
}

// Read and store linked list data to the temporary buffer.
while( nNext != 0xFFFFFFFF )
{
FragmentLink element = FragmentLinkSRV[nNext];
aData[ nNumFragment ] = element.fragmentData;
anIndex[ nNumFragment ] = nNumFragment;
++nNumFragment;
nNext = element.nNext;
}
uint N2 = 1 << (int)(ceil(log2(nNumFragment)));

// bitonic sort implementation needs on pow2 data.
for(int i = nNumFragment; i < N2; i++)
{
anIndex[i] = i;
aData[i].fDepth = 1.1f;
}
// Unoptimized sorting. (Bitonic Sort)

// loop from Merge( 2 ) to Merge( nCount )
for( int nMergeSize=2; nMergeSize<=N2; nMergeSize=nMergeSize*2 )
{
// Merge( nCount ) requires log2( nCount ) merges. Merge( nCount/2 ) -> Merge( 2 )
for( int nMergeSubSize=nMergeSize>>1; nMergeSubSize>0; nMergeSubSize=nMergeSubSize>>1 )
{
// compare and swap elements
for( int nElem=0; nElem<N2; ++nElem )
{
int nSwapElem = nElem^nMergeSubSize;
// check to make sure to only swap once
if( nSwapElem > nElem )
{
// sort in increasing order
if ( ( nElem & nMergeSize ) == 0 && aData[ anIndex[ nElem ] ].fDepth>aData[ anIndex[ nSwapElem ] ].fDepth )
{
int temp = anIndex[ nElem ];
anIndex[ nElem ] = anIndex[ nSwapElem ];
anIndex[ nSwapElem ] = temp;
}
// sort in descending order
if ( ( nElem & nMergeSize ) != 0 && aData[ anIndex[ nElem ] ].fDepth<aData[ anIndex[ nSwapElem ] ].fDepth )
{
int temp = anIndex[ nElem ];
anIndex[ nElem ] = anIndex[ nSwapElem ];
anIndex[ nSwapElem ] = temp;
}
}
}
}
}
// Now blend the sorted fragments.
float4 result = 0.0f;
for( int x = nNumFragment-1; x >= 0; --x )
{
uint nColor = aData[ anIndex[ x ] ].nColor;
float4 color;
color.r = ( (nColor >> 0) & 0xFF ) / 255.0f;
color.g = ( (nColor >> 8) & 0xFF ) / 255.0f;
color.b = ( (nColor >> 16) & 0xFF ) / 255.0f;
color.a = ( (nColor >> 24) & 0xFF ) / 255.0f;
result = lerp( result, color, color.a );
}

result.a = 1.0f;
return result;
}
[/CODE]

Anybody help me, please? Thank in advance. Edited by steven166
0

Share this post


Link to post
Share on other sites
If you get that message then your resource is still bound as an SRV to one of the shader stages. The error message should tell you which stage, otherwise you can use PIX to find out pretty quickly. You need to unbind the resource from whatever stage it's bound to before binding it as a UAV, which you can do by binding a NULL SRV to the appropriate slot. Looking at your code, it looks like you probably still have your resource bound to the pixel shader stage. Edited by MJP
1

Share this post


Link to post
Share on other sites
Thank MJP for reply, you are right because I bound it to the pixel shader stage, and I have no experience with DX11, so how can I bind a NULL SRV to the appropriate slot, in this case it is slot 1?

I only just modidy this statement, right?
pd3dImmediateContext->OMSetRenderTargetsAndUnorderedAccessViews( 0, NULL, pDSV, 0, 2, pUAVs, Indices );
into
UAVs[0] = NULL;
UAVs[1] = NULL
pd3dImmediateContext->OMSetRenderTargetsAndUnorderedAccessViews( 0, NULL, pDSV, 0, 2, pUAVs, Indices );
0

Share this post


Link to post
Share on other sites
One more thing, when I used PIX, I got an message "ID3D11DeviceContext::ClearRenderTargetView using D3D11 Render Target View 0x021F5EF0, while that object had an external refcount of 0....', so what does that mean?
0

Share this post


Link to post
Share on other sites
It must look like this. It's verbose, but there you have it.

[CODE]
ID3D11ShaderResourceView* pNullSRV = NULL;
m_pContext->CSSetShaderResources(0, 1, &pNullSRV);

ID3D11UnorderedAccessView* pNullUAV = NULL;
m_pContext->CSSetUnorderedAccessViews(0, 1, &pNullUAV, NULL);
[/CODE]
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By lonewolff
      Hi Guys,
      I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
      Any advice would be greatly appreciated
    • By MarcusAseth
      bool InitDirect3D::Init() { if (!D3DApp::Init()) { return false; } //Additional Initialization //Disable Alt+Enter Fullscreen Toggle shortkey IDXGIFactory* factory; CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory)); factory->MakeWindowAssociation(mhWindow, DXGI_MWA_NO_WINDOW_CHANGES); factory->Release(); return true; }  
      As stated on the title and displayed on the code above, regardless of it Alt+Enter still takes effect...
      I recall something from the book during the swapChain creation, where in order to create it one has to use the same factory used to create the ID3D11Device, therefore I tested and indeed using that same factory indeed it work.
      How is that one particular factory related to my window and how come the MakeWindowAssociation won't take effect with a newly created factory?
      Also what's even the point of being able to create this Factories if they won't work,?(except from that one associated with the ID3D11Device) 
    • By ProfL
      Can anyone recommend a wrapper for Direct3D 11 that is similarly simple to use as SFML? I don't need all the image formats etc. BUT I want a simple way to open a window, allocate a texture, buffer, shader.
    • By lucky6969b
      Q1:
      Since there is no more fixed pipeline rendering in DX11, for every part of rendering in DX11, do I need to create a brand-new vertex shader and pixel shader... or at least I have to find one relevant online. If you work on skinned meshes and other effects originally worked in DX9 fixed pipeline, do I have to rework everything by now?
       
      Q2:
      For assimp, if it originally was designed for DX9, like it is coupled to a DX9 device for creating meshes and materials etc. Do I have to add in the DX11 device in the assimp, or can I just leave the assimp to remain in DX9 and after the meshes are loaded, I just convert the vertex buffers and index buffers into DX11 buffers?
      Thanks
      Jack
    • By MarcusAseth
      This header is mentioned in the book I'm reading but there is no documentation on msdn... Is it like an... outdated and abandoned header?
      If so, what's the current default/recomended library for handling errors with directX?
  • Popular Now