Sign in to follow this  

DX11 DirectX Render to Texture problem

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

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
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

This topic is 1989 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.

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
      628730
    • Total Posts
      2984427
  • Similar Content

    • By GreenGodDiary
      Having some issues with a geometry shader in a very basic DX app.
      We have an assignment where we are supposed to render a rotating textured quad, and in the geometry shader duplicate this quad and offset it by its normal. Very basic stuff essentially.
      My issue is that the duplicated quad, when rendered in front of the original quad, seems to fail the Z test and thus the original quad is rendered on top of it.
      Whats even weirder is that this only happens for one of the triangles in the duplicated quad, against one of the original quads triangles.

      Here's a video to show you what happens: Video (ignore the stretched textures)

      Here's my GS: (VS is simple passthrough shader and PS is just as basic)
      struct VS_OUT { float4 Pos : SV_POSITION; float2 UV : TEXCOORD; }; struct VS_IN { float4 Pos : POSITION; float2 UV : TEXCOORD; }; cbuffer cbPerObject : register(b0) { float4x4 WVP; }; [maxvertexcount(6)] void main( triangle VS_IN input[3], inout TriangleStream< VS_OUT > output ) { //Calculate normal float4 faceEdgeA = input[1].Pos - input[0].Pos; float4 faceEdgeB = input[2].Pos - input[0].Pos; float3 faceNormal = normalize(cross(faceEdgeA.xyz, faceEdgeB.xyz)); //Input triangle, transformed for (uint i = 0; i < 3; i++) { VS_OUT element; VS_IN vert = input[i]; element.Pos = mul(vert.Pos, WVP); element.UV = vert.UV; output.Append(element); } output.RestartStrip(); for (uint j = 0; j < 3; j++) { VS_OUT element; VS_IN vert = input[j]; element.Pos = mul(vert.Pos + float4(faceNormal, 0.0f), WVP); element.Pos.xyz; element.UV = vert.UV; output.Append(element); } }  
      I havent used geometry shaders much so im not 100% on what happens behind the scenes.
      Any tips appreciated! 
    • By mister345
      Hi, I'm building a game engine using DirectX11 in c++.
      I need a basic physics engine to handle collisions and motion, and no time to write my own.
      What is the easiest solution for this? Bullet and PhysX both seem too complicated and would still require writing my own wrapper classes, it seems. 
      I found this thing called PAL - physics abstraction layer that can support bullet, physx, etc, but it's so old and no info on how to download or install it.
      The simpler the better. Please let me know, thanks!
    • By Hexaa
      I try to draw lines with different thicknesses using the geometry shader approach from here:
      https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader
      It seems to work great on my development machine (some Intel HD). However, if I try it on my target (Nvidia NVS 300, yes it's old) I get different results. See the attached images. There
      seem to be gaps in my sine signal that the NVS 300 device creates, the intel does what I want and expect in the other picture.
      It's a shame, because I just can't figure out why. I expect it to be the same. I get no Error in the debug output, with enabled native debugging. I disabled culling with CullMode.None. Could it be some z-fighting? I have little clue about it but I tested to play around with the RasterizerStateDescription and DepthBias properties with no success, no change at all. Maybe I miss something there?
      I develop the application with SharpDX btw.
      Any clues or help is very welcome
       


    • By Beny Benz
      Hi,
      I'm currently trying to write a shader which shoud compute a fast fourier transform of some data, manipulating the transformed data, do an inverse FFT an then displaying the result as vertex offset and color. I use Unity3d and HLSL as shader language. One of the main problems is that the data should not be passed from CPU to GPU for every frame if possible. My original plan was to use a vertex shader and do the fft there, but I fail to find out how to store changing data betwen shader calls/passes. I found a technique called ping-ponging which seems to be based on writing and exchangeing render targets, but I couldn't find an example for HLSL as a vertex shader yet.
      I found https://social.msdn.microsoft.com/Forums/en-US/c79a3701-d028-41d9-ad74-a2b3b3958383/how-to-render-to-multiple-render-targets-in-hlsl?forum=xnaframework
      which seem to use COLOR0 and COLOR1 as such render targets.
      Is it even possible to do such calculations on the gpu only? (/in this shader stage?, because I need the result of the calculation to modify the vertex offsets there)
      I also saw the use of compute shaders in simmilar projects (ocean wave simulation), do they realy copy data between CPU / GPU for every frame?
      How does this ping-ponging / rendertarget switching technique work in HLSL?
      Have you seen an example of usage?
      Any answer would be helpfull.
      Thank you
      appswert
    • By ADDMX
      Hi
      Just a simple question about compute shaders (CS5, DX11).
      Do the atomic operations (InterlockedAdd in my case) should work without any issues on RWByteAddressBuffer and be globaly coherent ?
      I'v come back from CUDA world and commited fairly simple kernel that does some job, the pseudo-code is as follows:
      (both kernels use that same RWByteAddressBuffer)
      first kernel does some job and sets Result[0] = 0;
      (using Result.Store(0, 0))
      I'v checked with debugger, and indeed the value stored at dword 0 is 0
      now my second kernel
      RWByteAddressBuffer Result;  [numthreads(8, 8, 8)] void main() {     for (int i = 0; i < 5; i++)     {         uint4 v0 = DoSomeCalculations1();         uint4 v1 = DoSomeCalculations2();         uint4 v2 = DoSomeCalculations3();                  if (v0.w == 0 && v1.w == 0 && v2.w)             continue;         //    increment counter by 3, and get it previous value         // this should basically allocate space for 3 uint4 values in buffer         uint prev;         Result.InterlockedAdd(0, 3, prev);                  // this fills the buffer with 3 uint4 values (+1 is here as the first 16 bytes is occupied by DrawInstancedIndirect data)         Result.Store4((prev+0+1)*16, v0);         Result.Store4((prev+1+1)*16, v1);         Result.Store4((prev+2+1)*16, v2);     } } Now I invoke it with Dispatch(4,4,4)
      Now I use DrawInstancedIndirect to draw the buffer, but ocassionaly there is missed triangle here and there for a frame, as if the atomic counter does not work as expected
      do I need any additional synchronization there ?
      I'v tried 'AllMemoryBarrierWithGroupSync' at the end of kernel, but without effect.
      If I do not use atomic counter, and istead just output empty vertices (that will transform into degenerated triangles) the all is OK - as if I'm missing some form of synchronization, but I do not see such a thing in DX11.
      I'v tested on both old and new nvidia hardware (680M and 1080, the behaviour is that same).
       
  • Popular Now