Sign in to follow this  
BrentMorris

DX11 DX11 not drawing anything

Recommended Posts

Traditionally I've worked with DX9, and I've just started experimenting with DX11 without DXUT. I can't get anything to draw, despite code being more or less copied from a project that does work. PiX shows that the triangle vertices I'm trying to draw are being transformed correctly, and that it's inside the viewport. The shader I'm using is hard-rigged to return white. What kind of problem could prevent something from drawing entirely?

I'd post code if there wasn't a ton of it split across several files, but here's a pix screenshot. [img]http://public.gamedev.net//public/style_emoticons/default/happy.png[/img]

[url="http://i.imgur.com/DlEZr.png"]http://i.imgur.com/DlEZr.png[/url]

Share this post


Link to post
Share on other sites
Heheh.

Checklist of stuff I have done with descriptions, and valid checks removed for brevity.

1. Swap chain.
[CODE]
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hwnd;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = true;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapChainDesc.Flags = 0;
featureLevel = D3D_FEATURE_LEVEL_11_0;
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &mSwapChain, &mDevice, NULL, &mContext);
[/CODE]

2. Create back buffer.
[CODE]
// Get the pointer to the back buffer.
result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
// Create the render target view with the back buffer pointer.
result = mDevice->CreateRenderTargetView(backBufferPtr, NULL, &mRenderTargetView);
[/CODE]

3. Set up depth/stencil buffer and render target view
[CODE]
// Set up the description of the depth buffer.
depthBufferDesc.Width = screenWidth;
depthBufferDesc.Height = screenHeight;
depthBufferDesc.MipLevels = 1;
depthBufferDesc.ArraySize = 1;
depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthBufferDesc.SampleDesc.Count = 1;
depthBufferDesc.SampleDesc.Quality = 0;
depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthBufferDesc.CPUAccessFlags = 0;
depthBufferDesc.MiscFlags = 0;
// Create the texture for the depth buffer using the filled out description.
mDevice->CreateTexture2D(&depthBufferDesc, NULL, &mDepthStencilBuffer);
// Set up the description of the stencil state.
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
depthStencilDesc.StencilEnable = true;
depthStencilDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
depthStencilDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
// Stencil operations if pixel is front-facing.
depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
// Stencil operations if pixel is back-facing.
depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
// Create the depth stencil state.
mDevice->CreateDepthStencilState(&depthStencilDesc, &mDepthStencilState);
// Set the depth stencil state.
mContext->OMSetDepthStencilState(mDepthStencilState, 1);
// Set up the depth stencil view description.
depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthStencilViewDesc.Texture2D.MipSlice = 0;
// Create the depth stencil view.
mDevice->CreateDepthStencilView(mDepthStencilBuffer, &depthStencilViewDesc, &mDepthStencilView);

// Bind the render target view and depth stencil view to the pipeline.
mContext->OMSetRenderTargets(1, &mRenderTargetView, mDepthStencilView);
[/CODE]

4. Create rasterizer state, (although I've tried removing this entirely to no effect)
[CODE]
// Setup the raster description which will determine how and what polygons will be drawn.
rasterDesc.AntialiasedLineEnable = false;
rasterDesc.CullMode = D3D11_CULL_NONE;
rasterDesc.DepthBias = 0;
rasterDesc.DepthBiasClamp = 0.0f;
rasterDesc.DepthClipEnable = true;
rasterDesc.FillMode = D3D11_FILL_SOLID;
rasterDesc.FrontCounterClockwise = false;
rasterDesc.MultisampleEnable = false;
rasterDesc.ScissorEnable = false;
rasterDesc.SlopeScaledDepthBias = 0.0f;
// Create the rasterizer state from the description we just filled out.
mDevice->CreateRasterizerState(&rasterDesc, &mRasterState);
// Now set the rasterizer state.
mContext->RSSetState(mRasterState);
[/CODE]


5. Created the viewport
[CODE]
// Setup the viewport for rendering.
viewport.Width = (float)screenWidth;
viewport.Height = (float)screenHeight;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
viewport.TopLeftX = 0.0f;
viewport.TopLeftY = 0.0f;
// Create the viewport.
mContext->RSSetViewports(1, &viewport);
[/CODE]

6. Set the input layout.
[CODE]
D3DX11_PASS_SHADER_DESC effectVsDesc;
mPass->GetVertexShaderDesc(&effectVsDesc);
D3DX11_EFFECT_SHADER_DESC effectVsDesc2;
effectVsDesc.pShaderVariable->GetShaderDesc(effectVsDesc.ShaderIndex, &effectVsDesc2);
const void *vsCodePtr = effectVsDesc2.pBytecode;
unsigned vsCodeLen = effectVsDesc2.BytecodeLength;
D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
polygonLayout[0].SemanticName = "POSITION";
polygonLayout[0].SemanticIndex = 0;
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygonLayout[0].InputSlot = 0;
polygonLayout[0].AlignedByteOffset = 0;
polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[0].InstanceDataStepRate = 0;
polygonLayout[1].SemanticName = "TEXCOORD";
polygonLayout[1].SemanticIndex = 0;
polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
polygonLayout[1].InputSlot = 0;
polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[1].InstanceDataStepRate = 0;
GraphicsMan->GetDevice()->CreateInputLayout(polygonLayout, sizeof(polygonLayout) / sizeof(polygonLayout[0]), vsCodePtr, vsCodeLen, &mLayout);
[/CODE]

7. Set the active vertex/pixel shaders via apply() of the effect framework.

And right. I am using the D3DX11Effect framework, if there is some inherent flaw with it I don't know about.

Edit: Also I guess my topic name is ~misleading; it is showing my clear color at least.

Share this post


Link to post
Share on other sites
I am, yeah. Here's my draw call.

[CODE]
float color[] = { 160.0 / 255.0, 69.0 / 255.0, 32.0 / 255.0, 0 };
// Clear the back buffer.
mContext->ClearRenderTargetView(mRenderTargetView, color);

// Clear the depth buffer.
mContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);

// Set vertex/index buffer.
mBuffer.ApplyBuffer();

// Update camera.
mCamera.Update();

// Set shader technique, pass, vars, and apply.
mEffect.SetTechnique(0);
mEffect.SetPass(0);
Matrix mx; D3DXMatrixIdentity(&mx);
mEffect.SetVariable("World", mx);
mEffect.SetVariable("View", mCamera.GetView());
mEffect.SetVariable("Projection", mCamera.GetProjection());
mEffect.Apply();

// Draw
mContext->DrawIndexed(mBuffer.GetIndexCount(), 0, 0);

// Present
mSwapChain->Present(0, 0);

[/CODE]

Share this post


Link to post
Share on other sites
I tried flipping the indices around, but also above there's the line:
[CODE]
rasterDesc.CullMode = D3D11_CULL_NONE;
[/CODE]
on the rasterizer state description.

I'm positive whatever this is will be a stupid 'Doh mistake moment. >_>

Share this post


Link to post
Share on other sites
Hm... It seems according to the PIX triangle is on the screen. Have you tried to debug pixel in that area? You'll see whether there's anything wrong with shader output, depth pass, or maybe it's not reaching pixel shader at all?

Share this post


Link to post
Share on other sites
Debugging the pixel shows no change, except from the initial black frame buffer to the clear color.

What could prevent the pixel shader from working?


[CODE]
float4x4 World;
float4x4 View;
float4x4 Projection;
texture2D Texture;
SamplerState textureSampler {
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};

struct VertexShaderInput
{
float4 Position : POSITION0;
//float4 Normal : NORMAL0;
float2 TextureCoordinate : TEXCOORD0;
};

struct VertexShaderOutput
{
float4 Position : POSITION0;
float2 TextureCoordinate : TEXCOORD1;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;

//output.Position = input.Position;
output.Position = mul(input.Position, World);
output.Position = mul(output.Position, View);
output.Position = mul(output.Position, Projection);

output.TextureCoordinate = input.TextureCoordinate;
return output;
};

float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET
{
float3 color = float3(255, 255, 255);
color = normalize(color);
return float4(color, 1);
//return Texture.Sample(textureSampler, input.TextureCoordinate);
};

technique11 Textured
{
pass p0
{
SetVertexShader(CompileShader(vs_5_0, VertexShaderFunction()));
SetPixelShader(CompileShader(ps_5_0, PixelShaderFunction()));
}
};
[/CODE]

Share this post


Link to post
Share on other sites
[quote name='DementedCarrot' timestamp='1335339709' post='4934646']
[CODE]
float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET
{
float3 color = float3(255, 255, 255);
color = normalize(color);
return float4(color, 1);
//return Texture.Sample(textureSampler, input.TextureCoordinate);
};
[/CODE]
[/quote]

Shader colors range from 0.0 to 1.0. If you normalize (255, 255, 255) it'll be about (0.58, 0.58, 0.58) and that's just gray.
You could simply do [i]return float4(1, 1, 1, 1)[/i] to return white color.

Try to remove blending/depth states, just to see if there's anything wrong with those. DirectX will use default values if no state is set.
[CODE]
mD3D11DeviceContext->RSSetState(0);
mD3D11DeviceContext->OMSetBlendState(0, 0, 0xFFFFFFFF);
mD3D11DeviceContext->OMSetDepthStencilState(0, 0);
[/CODE]

Share this post


Link to post
Share on other sites
[quote]
Shader colors range from 0.0 to 1.0. If you normalize (255, 255, 255) it'll be about (0.58, 0.58, 0.58) and that's just gray.
You could simply do return float4(1, 1, 1, 1) to return white color.[/quote]

Right on. [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]
At least my clear color isn't gray.

Also commenting those out changes nothing.

Share this post


Link to post
Share on other sites
It seems you send 3 floats for position to the shader:
[CODE]
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
[/CODE]
However in the shader you try to accept 4 floats:
[CODE]
float4 Position : POSITION0;
[/CODE]

Also I think you have to use SV_POSITION for vertex's output position, not POSITION0 like you do.

If I haven't made any mistake shader should look like this:
[CODE]
float4x4 World;
float4x4 View;
float4x4 Projection;
texture2D Texture;

SamplerState textureSampler {
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};

struct VertexShaderInput {
float3 Position : POSITION0;
float2 TextureCoordinate : TEXCOORD0;
};

struct VertexShaderOutput {
float4 Position : SV_POSITION;
float2 TextureCoordinate : TEXCOORD0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input) {
VertexShaderOutput output;

output.Position = mul(float4(input.Position, 1), World);
output.Position = mul(output.Position, View);
output.Position = mul(output.Position, Projection);
output.TextureCoordinate = input.TextureCoordinate;

return output;
};

float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET {
return float4(1, 1, 1, 1)
};

technique11 Textured {
pass p0 {
SetVertexShader(CompileShader(vs_5_0, VertexShaderFunction()));
SetPixelShader(CompileShader(ps_5_0, PixelShaderFunction()));
}
};
[/CODE]

P.S. I'm not sure if these things might cause your issue, I just try to find differences between your code and mine.

Share this post


Link to post
Share on other sites
[quote name='Ripiz' timestamp='1335342870' post='4934662']
it seems you send 3 floats for position to the shader:
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
However in the shader you try to accept 4 floats:
float4 Position : POSITION0;
[/quote]

It is correct to send 3 floats and read 4 floats. The shader sets the w-component to 1 automatically.

Cheers!

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  

  • Partner Spotlight

  • Forum Statistics

    • Total Topics
      627642
    • Total Posts
      2978354
  • Similar Content

    • 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
       
    • By Matt Barr
      Hey all. I've been working with compute shaders lately, and was hoping to build out some libraries to reuse code. As a prerequisite for my current project, I needed to sort a big array of data in my compute shader, so I was going to implement quicksort as a library function. My implementation was going to use an inout array to apply the changes to the referenced array.

      I spent half the day yesterday debugging in visual studio before I realized that the solution, while it worked INSIDE the function, reverted to the original state after returning from the function.

      My hack fix was just to inline the code, but this is not a great solution for the future.  Any ideas? I've considered just returning an array of ints that represents the sorted indices.
  • Popular Now