Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Dissipate

Member Since 31 Oct 2012
Offline Last Active Mar 01 2015 07:07 PM

Topics I've Started

Can't release BackBuffer before calling SwapChain->ResizeBuffers

18 February 2015 - 01:16 AM

Hi,

 

I am trying to resize the window. I managed it before in another project (dx11 this is dx11.1) but I just can't seem to find the outstanding reference that is needed to be released before resizing the swap chain. I get the error in the output window:

 

DXGI ERROR: IDXGISwapChain::ResizeBuffers: Swapchain cannot be resized unless all outstanding buffer references have been released. [ MISCELLANEOUS ERROR #19: ]
DXGI ERROR: IDXGISwapChain::ResizeBuffers: Swapchain cannot be resized unless all outstanding buffer references have been released. [ MISCELLANEOUS ERROR #19: ]

 

I have already seen the following links that cover this in a little detail:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb205075%28v=vs.85%29.aspx#Handling_Window_Resizing and Gamedev_Duplicate_Post_Here and

Another_Duplicate_Here.

 

In the last one Erik Rufelt explains in post #17 that all references to the backbuffer must be released. The only place that I would have had a reference would have been the Direct2D class (CD2DObj), for drawing a textured quad, but I cut it out and now I'm just displaying a coloured screen. Here is the ::OnResize code that is called at the end of ::InitDirect3D and also in MsgProc's WM_SIZE handler:

 

Additional: On start up the this is called but does not seem to get released as I check with the swapchain's addref/release pairs periodically. Also I am creating the swapchain with backbuffer count of 1.

	try
	{
		assert(m_spD3DImmediateContext);
		assert(m_spD3DDevice);
		assert(m_spSwapChain);

		//ReleaseCOM(m_pRenderTargetView);
		//ReleaseCOM(m_pDepthStencilView);
		//ReleaseCOM(m_spDepthStencilBuffer);
		//m_spRenderTargetView.Reset();
		//m_spDepthStencilView.Reset();
		//m_spDepthStencilBuffer.Reset();
		//m_spDepthDisabledStencilState.Reset();

		// This is used to monitor the reference count
		auto Myref = m_spSwapChain->AddRef();
		Myref = m_spSwapChain->Release();

		ULONG RefCount = 0;

		//if (m_spDepthEnabledStencilState)
		//	RefCount = m_spDepthEnabledStencilState->Release();
		//assert(RefCount == 0); // Fails = 1
		//if (m_spDepthDisabledStencilState)
		//	RefCount = m_spDepthDisabledStencilState->Release();
		//assert(RefCount == 0);		
		m_spD3DImmediateContext->OMSetRenderTargets(0, 0, 0);	

		if (m_spDepthStencilView)
			RefCount = m_spDepthStencilView->Release();
		assert(RefCount == 0);
		if (m_spDepthStencilBuffer)
			RefCount = m_spDepthStencilBuffer->Release();
		assert(RefCount == 0);
		if (m_spRenderTargetView)
			RefCount = m_spRenderTargetView->Release();
		assert(RefCount == 0);

		//m_spRenderTargetView.Reset();
		//m_spDepthStencilView.Reset();
		//m_spDepthStencilBuffer.Reset();
		//m_spDepthDisabledStencilState.Reset();

		//assert(m_spRenderTargetView == nullptr);
		//assert(m_spDepthStencilView == nullptr);
		//assert(m_spDepthStencilBuffer == nullptr);
		//assert(m_spDepthDisabledStencilState == nullptr);

		Myref = m_spSwapChain->AddRef();
		Myref = m_spSwapChain->Release();
		
		// Resize the swap chain and recreate the render target view.
		COMERR(m_spSwapChain->ResizeBuffers(1, m_iClientWidth, m_iClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0),
			"CD3DObject::OnResize() SwapChain Could not resize.");
		ID3D11Texture2D* pBackBuffer;
		COMERR(m_spSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pBackBuffer)),
			"CD3DObject::OnResize() SwapChain could not get backbuffer.");
		COMERR(m_spD3DDevice->CreateRenderTargetView(pBackBuffer, 0, m_spRenderTargetView.GetAddressOf()),
			"CD3DObject::OnResize() Could not re-create render target view.");

		Myref = m_spSwapChain->AddRef();
		Myref = m_spSwapChain->Release();

		//ReleaseCOM(pBackBuffer);
		RefCount = pBackBuffer->Release();

		Myref = m_spSwapChain->AddRef();
		Myref = m_spSwapChain->Release();


Bizarre Quad's Triangles but a Cube is ok

04 November 2014 - 11:47 AM

Hi,
 
I am having problems drawing a quad of triangles. I am specifying the front and back of them and texture coordinates, no lighting yet. Please can you check that I am doing this correctly because it worked for my cubes that I rendered. I am getting mangled triangles. (I moved the cube back off 0,0,0).

 

 http://2014_11_04_165240.jpg

Notice below I am using an XMFLOAT3 in my program struct but a float4 Pos : POSITION; as my hlsl 'vertex in'. Is that a problem? It seems to work in the tutorial. I have tried also to have struct as XMFLOAT4 and Input Element Description as DXGI_FORMAT_R32G32B32A32_FLOAT and specify a 'w' component to experiment. But it created a quad that had one side near zero and the other stretching off into infinity. (cube at 0,0,0)
 
http://2014_11_04_170453.jpg 
 

struct stVERTEX_POS_TEX
{
    DirectX::XMFLOAT3 f3Pos;
    DirectX::XMFLOAT2 f2Tex;
};
const D3D11_INPUT_ELEMENT_DESC stPosTexIED[2] =
{
    {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
    {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0}
};
// Shader.h

#pragma pack_matrix(row_major)

#define FLIP_TEXTURE_Y 0

///////////////////////////////
// Constant Buffer Variables
///////////////////////////////
Texture2D txDiffuse    : register(t0);

SamplerState samLinear : register(s0);

cbuffer cbNeverChanges : register(b0)
{
    matrix xmView;
};

cbuffer cbOnResize     : register(b1)
{
    matrix xmProjection;
};

cbuffer cbEveryFrame   : register(b2)
{
    matrix xmWorld;
    float4 f4MeshColor;
};


/////////////////////
// Data Structures
/////////////////////
struct VS_INPUT
{
    float4 Pos : POSITION;
    float2 Tex : TEXCOORD0;
};

struct PS_INPUT
{
    float4 Pos : SV_POSITION;
    float2 Tex : TEXCOORD0;
};


/////////////////////
// Utility Functions
/////////////////////
float2 Get_Corrected_Texture_Coordinate(float2 f2TexCoord)
{
    #if FLIP_TEXTURE_Y
        return float2(f2TexCoord.x, 1.0 - f2TexCoord.y);
    #else
        return f2TexCoord;
    #endif
}
// Shader_VS.hlsl

#include "TextureMapping.h"


//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS(VS_INPUT input)
{
    PS_INPUT output = (PS_INPUT)0;

    output.Pos = mul(input.Pos,  xmWorld);
    output.Pos = mul(output.Pos, xmView);
    output.Pos = mul(output.Pos, xmProjection);

    output.Tex = input.Tex;
    
    return output;
}
// Shader_PS.hlsl

#include "TextureMapping.h"


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( PS_INPUT input) : SV_Target
{
    return txDiffuse.Sample( samLinear, input.Tex ) * f4MeshColor;
}

Below is the current situation:

http://radiate.vidmeup.com/view?q=54590fcbd11d4.flv

 

Below is when using XMFloat4 in struct

http://radiate.vidmeup.com/view?q=54590fcbd11d4.flv

 

*EDIT embedding video doesn't work


Should I try to optimise the World matrix build like this?

16 October 2014 - 02:41 PM

Hi all,

 

It seems a bit wastful to do this for every object in the application:

m_xmWorld = m_xmScale * m_xmSpin * m_xmTranslate * m_xmOrbit;

Especially if it isn't even scaling that particular frame. Or even spinning that particular frame. So my question is... is the following an optimisation? I'm trying to avoid unnecessary matrix multiplication:

// All booleans set to false each frame
// Then certain booleans set to true dependant on characteristics of movement during ::Update()

if (m_bScaling)
    m_xmWorld *= m_xmScale;

if (m_bSpinning)
    m_xmWorld *= m_xmSpin;

if (m_bTranslating)
    m_xmWorld *= m_xmTranslate;

if (m_bOrbiting)
    m_xmWorld *= m_xmOrbit;

Or are the first example's multiplications so over-optimisidly-fast that it would make no difference? Are there any problems with this idea?

 

Thanks smile.png


Problems trying to create custom shader w/XTK

23 August 2014 - 12:23 PM

Hi,

 

May I ask for your help with this issue please... (its an easy one)

 

Using: Win7, VS2012, DirectXTK

 

Error:

D3D11 ERROR: ID3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'NORMAL'/0, but the declaration doesn't provide a matching name. [ STATE_CREATION ERROR #163: CREATEINPUTLAYOUT_MISSINGELEMENT]
 

Ok I know that the NORMAL0 is supposed to be in the D3D11_INPUT_ELEMENT_DESC I am creating a custom shader and passing my own compiled shader in. Somehow the EffectFactory is overwriting the Input Element Description with its own shader description!?! Possibley from XTK/Src/VertexTypes.h. Would you kindly show me the correct way of using my own shader with DirectXTK. The Documentation is usless.

 

Question (also): How do you access the constant buffers then. To communicate with the shader?

 

Please see if I am doing this right? Also how do you access the constant buffers from the IEffect. Or do you reinterpret_cast it to DGSLEffect? ...maybe like:

m_spDGSLEffect.reset(reinterpret_cast<DGSLEffect*>(m_spEffect.get())); // ??

I have traced that it is through the DGSLEffectFactory's constructor that it creates the Pixel Shader (...::pImpl::CreatePixelShader(...)). There's so much of the private implementation that i can't touch - gonna have to augment the code with my own methods.

 

Here are fragments of my code from the knowledge I've managed to glean after weeks/months:

DGSLEffectFactory::DGSLEffectInfo info;
info.name = L"main";
info.alpha = 1.0f;
info.ambientColor = XMFLOAT3( 0.2f, 0.2f, 0.2f);
info.diffuseColor = XMFLOAT3( 0.8f, 0.8f, 0.8f );
info.pixelShader = L"VertexShader.cso";

std::unique_ptr<DGSLEffectFactory> m_spDGSLEffectFactory; // In header
std::unique_ptr<IEffect>           m_spEffect;            // In header

m_spDGSLEffectFactory.reset(new DGSLEffectFactory(g_pD3DObj->m_spD3DDevice.Get()));
m_spDGSLEffectFactory->SetDirectory(L"H:/Code/_PROGS/DXTB/x64/Debug");

m_spEffect = m_spDGSLEffectFactory->CreateDGSLEffect(info, g_pD3DObj->m_spD3DImmediateContext.Get());

D3D11_INPUT_ELEMENT_DESC stVertexDesc[] =
	{
		{"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"COLOR",       0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXCOORD",    0, DXGI_FORMAT_R32G32_FLOAT,       0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXCOORD",    1, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXCOORD",    2, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXCOORD",    3, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXCOORD",    4, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXCOORD",    5, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0}
	};

	void const* pByte;
	size_t  Size = 0;
	m_spEffect->GetVertexShaderBytecode(&pByte, &Size);

	HR(g_pD3DObj->m_spD3DDevice->CreateInputLayout(stVertexDesc, 2, pByte, Size, &m_pInputLayout));

I have asked so much and would be deeply and graciously gratified with your suggestions.


Shader Designer Fonts all Jiggled Up. VS2012 Corruption?

19 August 2014 - 09:20 AM

Hi all,

 

I didn't really know under which heading to post this.

In DGSL Shader Designer; starting it up produced this picture:

Attached File  Visual Studio Shader Designer Window.png   10.89KB   0 downloads

 

Why are the fonts all messed up? Is it supposed to be like this? What do I need to do to rectify it? I have tried turning it off and on again :P I hope I dont have to do a VS->Repair.

 

I greatly appreciate your responses.


PARTNERS