Sign in to follow this  
pulo

DX11 DirectX Render to Texture problem

Recommended Posts

i was trying to render to a texture to use it for post-processing. I've read a lot of tutorials about this stuff und have tried it for myself now, but apparently i am doing something wrong.
So first of all these are the error message im getting over and over:

[CODE]
D3D11: ERROR: ID3D11DeviceContext::OMSetRenderTargets: The RenderTargetView at slot 0 is not compatable with the DepthStencilView. DepthStencilViews may only be used with RenderTargetViews if the effective dimensions of the Views are equal, as well as the Resource types, multisample count, and multisample quality. The RenderTargetView at slot 0 has (w:400,h:300,as:1), while the Resource is a Texture2D with (mc:1,mq:0). The DepthStencilView has (w:1280,h:720,as:1), while the Resource is a Texture2D with (mc:1,mq:0). D3D11_RESOURCE_MISC_TEXTURECUBE factors into the Resource type, unless GetFeatureLevel() returns D3D_FEATURE_LEVEL_10_1 or greater. [ STATE_SETTING ERROR #388: OMSETRENDERTARGETS_INVALIDVIEW ]
D3D11: ERROR: ID3D11DeviceContext::Draw: Rasterization Unit is enabled (PixelShader is not NULL or Depth/Stencil test is enabled and RasterizedStream is not D3D11_SO_NO_RASTERIZED_STREAM) but position is not provided by the last shader before the Rasterization Unit. [ EXECUTION ERROR #362: DEVICE_DRAW_POSITION_NOT_PRESENT ][/CODE]

And:

[CODE]
D3D11: ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Geometry Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (RADIUS,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]
D3D11: ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Geometry Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (TEXTUREINDEX,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]
D3D11: ERROR: ID3D11DeviceContext::Draw: Geometry Shader - Pixel Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (POSITION,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]
D3D11: ERROR: ID3D11DeviceContext::OMSetRenderTargets: The RenderTargetView at slot 0 is not compatable with the DepthStencilView. DepthStencilViews may only be used with RenderTargetViews if the effective dimensions of the Views are equal, as well as the Resource types, multisample count, and multisample quality. The RenderTargetView at slot 0 has (w:400,h:300,as:1), while the Resource is a Texture2D with (mc:1,mq:0). The DepthStencilView has (w:1280,h:720,as:1), while the Resource is a Texture2D with (mc:1,mq:0). D3D11_RESOURCE_MISC_TEXTURECUBE factors into the Resource type, unless GetFeatureLevel() returns D3D_FEATURE_LEVEL_10_1 or greater. [ STATE_SETTING ERROR #388: OMSETRENDERTARGETS_INVALIDVIEW ][/CODE]

I am pretty sure that i am misunterstanding a major aspect of this rendertarget switching and stuff.
When my DirectX Device is created i am also creating this:

[CODE] D3D11_TEXTURE2D_DESC textureDesc;
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;

ZeroMemory(&textureDesc, sizeof(textureDesc));

textureDesc.Width = 800/2;
textureDesc.Height = 600/2;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
textureDesc.SampleDesc.Count = 1;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;


pDevice->CreateTexture2D(&textureDesc, NULL, &renderTargetTextureMap);

renderTargetViewDesc.Format = textureDesc.Format;
renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
renderTargetViewDesc.Texture2D.MipSlice = 0;

.
pDevice->CreateRenderTargetView(renderTargetTextureMap, &renderTargetViewDesc, &renderTargetViewMap);

shaderResourceViewDesc.Format = textureDesc.Format;
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture2D.MipLevels = 1;

pDevice->CreateShaderResourceView(renderTargetTextureMap, &shaderResourceViewDesc, &shaderResourceViewMap);

D3DVERTEX quad[4] = {
{D3DXVECTOR3(0,0,0), D3DXVECTOR2(0,0)},
{D3DXVECTOR3(1,1,0), D3DXVECTOR2(1,1)},
{D3DXVECTOR3(1,0,0), D3DXVECTOR2(1,0)},
{D3DXVECTOR3(0,1,0), D3DXVECTOR2(0,1)}};

HRESULT hr;

D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = &quad[0];
InitData.SysMemPitch = sizeof(D3DVERTEX);
InitData.SysMemSlicePitch = 0;

D3D11_BUFFER_DESC bufferDesc;
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = 4 * InitData.SysMemPitch;
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;

V_RETURN(pDevice->CreateBuffer( &bufferDesc, &InitData, &m_pVertexBuffer ));

const D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_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 },
};
UINT numElements = sizeof( layout ) / sizeof( layout[0] );
D3DX11_PASS_DESC passDesc;
m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->GetDesc(&passDesc);

V_RETURN( pDevice->CreateInputLayout( layout, numElements, passDesc.pIAInputSignature,
passDesc.IAInputSignatureSize, &m_pInputLayout ) ); [/CODE]

So i am creating a ShaderResourceView and a RenderTargetView aswell as a cube with a vertex buffer to draw this cube where the texture will be drawn on.

Now in every frame update after ALL the other stuff was drawn im using this:


[CODE] pDevice->GetImmediateContext(&pd3dImmediateContext);
pd3dImmediateContext->OMSetRenderTargets( 1, &renderTargetViewMap, pDSV );

pd3dImmediateContext->ClearRenderTargetView(renderTargetViewMap, g_ClearColor);
ID3D11Buffer* vbs[] = { m_pVertexBuffer, };
unsigned int strides[] = { sizeof(D3DVERTEX), }, offsets[] = { 0, };

pd3dImmediateContext->IASetVertexBuffers(0,1, vbs, strides, offsets);
pd3dImmediateContext->IASetInputLayout(m_pInputLayout);
pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

//TODO: Move to header file.
ID3DX11EffectShaderResourceVariable* g_SpriteEV;

g_SpriteEV = m_pEffect->GetVariableByName("g_PostProcessTex")->AsShaderResource();

g_SpriteEV->SetResource(shaderResourceViewMap);
m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->Apply(0, pd3dImmediateContext);

pd3dImmediateContext->Draw(4, 0); [/CODE]

I have not explicitly created a depthStencilView which i would guess is my main error here. But i have no idea how to create something like this right.
I am pretty much confused about how this all is working in the background...maybe someone cares to explain this.
Am i doing anything right here or is this just wrong? [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

Thanks for anyone who cares to help.

Share this post


Link to post
Share on other sites
I see several problems with posted snipsets.
1) If you render to texture, that is smaller than your standard render target, you must change viewport to texture dimensions. (maybe last error is due to this)
2) Before you render to texture, save your targets. After you render to texture, dont forget to unbind render targets from device and restore original ones (aka. classic "screen")
3) If you render "classic way" to the screen, can you see some errors ? Because errors with shaders are not render-to-texture relevant. In DX11 rendering geometry to texture is exactly the same as classic rendering, except for render targets changes.

Do you know this tutorial: [url="http://www.rastertek.com/dx11tut22.html"]http://www.rastertek.com/dx11tut22.html[/url]
It´s a good start and my renderer to texture is based on it. Everything works correctly.

Share this post


Link to post
Share on other sites
Hey, thanks for your advices.
I've reworked my whole Render to Texture process based on this tutorial and it gives me no errors and it seems like that i can work with the texture.
The only problem left now ist, that it seems like i cannot draw a simple square to draw my texture on anymore. This is how it looks like at the moment (with a black/ white shader):
[url="http://imgur.com/HrKXR"]http://imgur.com/HrKXR[/url]

this is the code AFTER RenderToTexture() and RenderScene():


[CODE]

Vertex v[] =
{
Vertex( -0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f ),
Vertex( -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ),
Vertex( 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f ),
Vertex( 0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ),
};

DWORD indices[] = {
0, 1, 2,
0, 2, 3,
};

HRESULT hr;

D3D11_BUFFER_DESC indexBufferDesc;
ZeroMemory( &indexBufferDesc, sizeof(indexBufferDesc) );

indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(DWORD) * 2 * 3;
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
indexBufferDesc.MiscFlags = 0;

D3D11_SUBRESOURCE_DATA iinitData;

iinitData.pSysMem = indices;
pDevice->CreateBuffer(&indexBufferDesc, &iinitData, &m_pIndexBuffer);

// Fill in the subresource data.
D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = &v[0];
InitData.SysMemPitch = sizeof(Vertex);
InitData.SysMemSlicePitch = 0;

D3D11_BUFFER_DESC bufferDesc;
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = 4 * InitData.SysMemPitch;
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;

V_RETURN(pDevice->CreateBuffer( &bufferDesc, &InitData, &m_pVertexBuffer ));

const D3D11_INPUT_ELEMENT_DESC layout[] = // http://msdn.microsoft.com/en-us/library/bb205117%28v=vs.85%29.aspx
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_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 },
};
UINT numElements = sizeof( layout ) / sizeof( layout[0] );
D3DX11_PASS_DESC passDesc;
m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->GetDesc(&passDesc);

V_RETURN( pDevice->CreateInputLayout( layout, numElements, passDesc.pIAInputSignature,
passDesc.IAInputSignatureSize, &m_pInputLayout ) );


ID3D11Buffer* vbs[] = { m_pVertexBuffer, };
unsigned int strides[] = { sizeof(D3DVERTEX), }, offsets[] = { 0, };

pd3dImmediateContext->IASetVertexBuffers(0,1, vbs, strides, offsets);
pd3dImmediateContext->IASetIndexBuffer( m_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
pd3dImmediateContext->IASetInputLayout(m_pInputLayout);
pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

//TODO: Move to header file.
ID3DX11EffectShaderResourceVariable* g_SpriteEV;

g_SpriteEV = m_pEffect->GetVariableByName("g_PostProcessTex")->AsShaderResource();

g_SpriteEV->SetResource(m_shaderResourceView);
m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->Apply(0, pd3dImmediateContext);

pd3dImmediateContext->DrawIndexed( 6, 0, 0 );

g_SpriteEV->SetResource(NULL);
m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->Apply(0, pd3dImmediateContext);
[/CODE]

If you want me to post all the code for the different render processes just let me know. Edited by pulo

Share this post


Link to post
Share on other sites
Okay...i found one of my problems..the stride of the vertex buffer was set to an "old" value.. Now i've set up the square with these values:

[CODE]
Vertex v[] =
{
Vertex( -1.f, -1.f, 0.f ),
Vertex( 1.f, -1.f, 0.f ),
Vertex( 1.f, 1.f, 0.f ),
Vertex( -1.f, 1.f, 0.f ),
};
DWORD indices[] = {
0, 1, 2,
0, 2, 3,
};
[/CODE]

But it produces this:

[url="http://imgur.com/EsmV3"]http://imgur.com/EsmV3[/url]

so basically it splits the whole thing in 4 parts. There are some things i've noticed aswell.
1. The Texture on the square seems to be exaclty mirrored (this could be fixed through the shader though)
2. The 4 tiles are not present at the beginning - i have to move my camera just a little bit then it appears.
3. Its disappearing in random intervals. Edited by pulo

Share this post


Link to post
Share on other sites
Do you have correct TEXCOORDs ? Also try to turn off DepthBuffer and DepthWrites.

I am setting my full screen quad this way:
[CODE]
float startX = -1;
float startY = -1;
float endX = 1;
float endY = 1;

MyMath::Vector3 vecA = MyMath::Vector3(startX, startY, 0);
MyMath::Vector3 vecB = MyMath::Vector3(endX , startY, 0);
MyMath::Vector3 vecC = MyMath::Vector3(startX, endY, 0);
MyMath::Vector3 vecD = MyMath::Vector3(endX , endY, 0);

std::vector<QuadVertex> pos;
QuadVertex a = {vecA.X, vecA.Y, vecA.Z, 0, 1, 0};
QuadVertex b = {vecB.X, vecB.Y, vecB.Z, 1, 1, 1};
QuadVertex c = {vecC.X, vecC.Y, vecC.Z, 0, 0, 3};
QuadVertex d = {vecD.X, vecD.Y, vecD.Z, 1, 0, 2};

std::vector<short> ind;
ind.push_back(0); ind.push_back(1); ind.push_back(2);
ind.push_back(2); ind.push_back(1); ind.push_back(3);
[/CODE]

Share this post


Link to post
Share on other sites
Hey,

thanks for your help. I really appreciate it. Your hint with the TexCoords was a hit. I was using an old calculation for them. Now i can render the whole texture over my scene with a black and white shader. I have a few questions / problems left though:

1. I understand that for the coordinate system for rendering 0,0 is the center and -1,-1 is the lower left corner, isnt it? But what about the texture coordinates. If i understand the numbers correctly there 0,0 is the upper left corner? Why is there such a difference?
2. My shader seems not to be active at first startup , i have to move my camera a bit before it comes active.
3. The shader effect seems to disappear from time to time (random)

I have tried to disable the depth for the Stencil with something like this:

[CODE]
D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
ID3D11DepthStencilState* m_depthDisabledStencilState;
depthDisabledStencilDesc.DepthEnable = false;
depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
depthDisabledStencilDesc.StencilEnable = true;
depthDisabledStencilDesc.StencilReadMask = 0xFF;
depthDisabledStencilDesc.StencilWriteMask = 0xFF;
depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
pd3dDevice->CreateDepthStencilState(&depthDisabledStencilDesc, &m_depthDisabledStencilState);
pd3dImmediateContext->OMSetDepthStencilState(m_depthDisabledStencilState, 1);


g_PostProcessing->RenderPostProcess(pd3dDevice, g_Camera, g_ClearColor);

depthDisabledStencilDesc.DepthEnable = true;
pd3dDevice->CreateDepthStencilState(&depthDisabledStencilDesc, &m_depthDisabledStencilState);
pd3dImmediateContext->OMSetDepthStencilState(m_depthDisabledStencilState, 1);
[/CODE]

The renderpostprocess call is rendering the quad with the texture on the screen after RenderToTexture() and RenderScene() was called.

Share this post


Link to post
Share on other sites
I was able to solve all the problems by just setting the DepthStencilState to DepthEnable = false in the shader file :)
Thanks for your help!

Share this post


Link to post
Share on other sites
Hello again,

now i have researched some stuff and there are some open questions in my mind which i hope some of you can answer me. I am now trying to downsample the rendered texture to the 4th of the original size. After that i want to use a bloom effect or something and (upsample?) it again to merge it with the original rendered scene.
Now my question is fairly simple: how can i let my original texture (full screen size) walk through some shader passes so at the end i will have a downsampled texture with effects and the original texture to work with?
i dont understand how to work with multiple passes. How do i pass the texture from one pass to another and at the end merge the original one with the edited one?
Thanks in advance

Share this post


Link to post
Share on other sites
You basically create two rendertargets. Size doesn't matter - they just need to be big enough for the largest (typically your screen dimensions).

So, in pass 1 you draw from target 0 to target 1 as a half-sized quad (the size of the quad doesn't have to be the same as your render target size).
In pass 2 you draw from 1 to 0 as a half-sized quad (halving again the half size from above).
Repeat until you get it down to the size you want, flipping the render targets each pass.

After the final pass you set back your default render target, then draw from the target set in the final pass to this.

[b]Edit[/b]: silly me, I forgot that with D3D11 you can autogen mipmaps from a render target. I've never used this, but it does present another option for you that may be faster. Edited by mhagain

Share this post


Link to post
Share on other sites
I think i understood this. But i cant really image how to draw from one target to another? is it a simple draw() call with a fullscreen quad textured by the texture i want to pass and the render target i want to use next?

Share this post


Link to post
Share on other sites
The only thing i dont understand is you i pass one texture from pass to pass. Is this a simple Draw() call with just the render target set, or is there a "better" way?

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  

  • Forum Statistics

    • Total Topics
      627719
    • Total Posts
      2978790
  • Similar Content

    • By Baemz
      Hello,
      I've been working on some culling-techniques for a project. We've built our own engine so pretty much everything is built from scratch. I've set up a frustum with the following code, assuming that the FOV is 90 degrees.
      float angle = CU::ToRadians(45.f); Plane<float> nearPlane(Vector3<float>(0, 0, aNear), Vector3<float>(0, 0, -1)); Plane<float> farPlane(Vector3<float>(0, 0, aFar), Vector3<float>(0, 0, 1)); Plane<float> right(Vector3<float>(0, 0, 0), Vector3<float>(angle, 0, -angle)); Plane<float> left(Vector3<float>(0, 0, 0), Vector3<float>(-angle, 0, -angle)); Plane<float> up(Vector3<float>(0, 0, 0), Vector3<float>(0, angle, -angle)); Plane<float> down(Vector3<float>(0, 0, 0), Vector3<float>(0, -angle, -angle)); myVolume.AddPlane(nearPlane); myVolume.AddPlane(farPlane); myVolume.AddPlane(right); myVolume.AddPlane(left); myVolume.AddPlane(up); myVolume.AddPlane(down); When checking the intersections I am using a BoundingSphere of my models, which is calculated by taking the average position of all vertices and then choosing the furthest distance to a vertex for radius. The actual intersection test looks like this, where the "myFrustum90" is the actual frustum described above.
      The orientationInverse is the viewMatrix in this case.
      bool CFrustum::Intersects(const SFrustumCollider& aCollider) { CU::Vector4<float> position = CU::Vector4<float>(aCollider.myCenter.x, aCollider.myCenter.y, aCollider.myCenter.z, 1.f) * myOrientationInverse; return myFrustum90.Inside({ position.x, position.y, position.z }, aCollider.myRadius); } The Inside() function looks like this.
      template <typename T> bool PlaneVolume<T>::Inside(Vector3<T> aPosition, T aRadius) const { for (unsigned short i = 0; i < myPlaneList.size(); ++i) { if (myPlaneList[i].ClassifySpherePlane(aPosition, aRadius) > 0) { return false; } } return true; } And this is the ClassifySpherePlane() function. (The plane is defined as a Vector4 called myABCD, where ABC is the normal)
      template <typename T> inline int Plane<T>::ClassifySpherePlane(Vector3<T> aSpherePosition, float aSphereRadius) const { float distance = (aSpherePosition.Dot(myNormal)) - myABCD.w; // completely on the front side if (distance >= aSphereRadius) { return 1; } // completely on the backside (aka "inside") if (distance <= -aSphereRadius) { return -1; } //sphere intersects the plane return 0; }  
      Please bare in mind that this code is not optimized nor well-written by any means. I am just looking to get it working.
      The result of this culling is that the models seem to be culled a bit "too early", so that the culling is visible and the models pops away.
      How do I get the culling to work properly?
      I have tried different techniques but haven't gotten any of them to work.
      If you need more code or explanations feel free to ask for it.

      Thanks.
       
    • By evelyn4you
      hi,
      i have read very much about the binding of a constantbuffer to a shader but something is still unclear to me.
      e.g. when performing :   vertexshader.setConstantbuffer ( buffer,  slot )
       is the buffer bound
      a.  to the VertexShaderStage
      or
      b. to the VertexShader that is currently set as the active VertexShader
      Is it possible to bind a constantBuffer to a VertexShader e.g. VS_A and keep this binding even after the active VertexShader has changed ?
      I mean i want to bind constantbuffer_A  to VS_A, an Constantbuffer_B to VS_B  and  only use updateSubresource without using setConstantBuffer command every time.

      Look at this example:
      SetVertexShader ( VS_A )
      updateSubresource(buffer_A)
      vertexshader.setConstantbuffer ( buffer_A,  slot_A )
      perform drawcall       ( buffer_A is used )

      SetVertexShader ( VS_B )
      updateSubresource(buffer_B)
      vertexshader.setConstantbuffer ( buffer_B,  slot_A )
      perform drawcall   ( buffer_B is used )
      SetVertexShader ( VS_A )
      perform drawcall   (now which buffer is used ??? )
       
      I ask this question because i have made a custom render engine an want to optimize to
      the minimum  updateSubresource, and setConstantbuffer  calls
       
       
       
       
       
    • By noodleBowl
      I got a quick question about buffers when it comes to DirectX 11. If I bind a buffer using a command like:
      IASetVertexBuffers IASetIndexBuffer VSSetConstantBuffers PSSetConstantBuffers  and then later on I update that bound buffer's data using commands like Map/Unmap or any of the other update commands.
      Do I need to rebind the buffer again in order for my update to take effect? If I dont rebind is that really bad as in I get a performance hit? My thought process behind this is that if the buffer is already bound why do I need to rebind it? I'm using that same buffer it is just different data
       
    • By Rockmover
      I am really stuck with something that should be very simple in DirectX 11. 
      1. I can draw lines using a PC (position, colored) vertices and a simple shader just fine.
      2. I can draw 3D triangles using PCN (position, colored, normal) vertices just fine (even transparency and SpecularBlinnPhong shaders).
       
      However, if I'm using my 3D shader, and I want to draw my PC lines in the same scene how can I do that?
       
      If I change my lines to PCN and pass them to the 3D shader with my triangles, then the lighting screws them all up.  I only want the lighting for the 3D triangles, but no SpecularBlinnPhong/Lighting for the lines (just PC). 
      I am sure this is because if I change the lines to PNC there is not really a correct "normal" for the lines.  
      I assume I somehow need to draw the 3D triangles using one shader, and then "switch" to another shader and draw the lines?  But I have no clue how to use two different shaders in the same scene.  And then are the lines just drawn on top of the triangles, or vice versa (maybe draw order dependent)?  
      I must be missing something really basic, so if anyone can just point me in the right direction (or link to an example showing the implementation of multiple shaders) that would be REALLY appreciated.
       
      I'm also more than happy to post my simple test code if that helps as well!
       
      THANKS SO MUCH IN ADVANCE!!!
    • By Reitano
      Hi,
      I am writing a linear allocator of per-frame constants using the DirectX 11.1 API. My plan is to replace the traditional constant allocation strategy, where most of the work is done by the driver behind my back, with a manual one inspired by the DirectX 12 and Vulkan APIs.
      In brief, the allocator maintains a list of 64K pages, each page owns a constant buffer managed as a ring buffer. Each page has a history of the N previous frames. At the beginning of a new frame, the allocator retires the frames that have been processed by the GPU and frees up the corresponding space in each page. I use DirectX 11 queries for detecting when a frame is complete and the ID3D11DeviceContext1::VS/PSSetConstantBuffers1 methods for binding constant buffers with an offset.
      The new allocator appears to be working but I am not 100% confident it is actually correct. In particular:
      1) it relies on queries which I am not too familiar with. Are they 100% reliable ?
      2) it maps/unmaps the constant buffer of each page at the beginning of a new frame and then writes the mapped memory as the frame is built. In pseudo code:
      BeginFrame:
          page.data = device.Map(page.buffer)
          device.Unmap(page.buffer)
      RenderFrame
          Alloc(size, initData)
              ...
              memcpy(page.data + page.start, initData, size)
          Alloc(size, initData)
              ...
              memcpy(page.data + page.start, initData, size)
      (Note: calling Unmap at the end of a frame prevents binding the mapped constant buffers and triggers an error in the debug layer)
      Is this valid ? 
      3) I don't fully understand how many frames I should keep in the history. My intuition says it should be equal to the maximum latency reported by IDXGIDevice1::GetMaximumFrameLatency, which is 3 on my machine. But, this value works fine in an unit test while on a more complex demo I need to manually set it to 5, otherwise the allocator starts overwriting previous frames that have not completed yet. Shouldn't the swap chain Present method block the CPU in this case ?
      4) Should I expect this approach to be more efficient than the one managed by the driver ? I don't have meaningful profile data yet.
      Is anybody familiar with the approach described above and can answer my questions and discuss the pros and cons of this technique based on his experience ? 
      For reference, I've uploaded the (WIP) allocator code at https://paste.ofcode.org/Bq98ujP6zaAuKyjv4X7HSv.  Feel free to adapt it in your engine and please let me know if you spot any mistakes
      Thanks
      Stefano Lanza
       
  • Popular Now