Jump to content
  • Advertisement
Sign in to follow this  

DX11 DX11 not drawing anything

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

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. happy.png


Share this post

Link to post
Share on other sites

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

1. Swap chain.

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.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);

2. Create back buffer.

// 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);

3. Set up depth/stencil buffer and render target view

// 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);

4. Create rasterizer state, (although I've tried removing this entirely to no effect)

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

5. Created the viewport

// 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);

6. Set the input layout.

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

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.

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.

// Update camera.

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

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

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

Share this post

Link to post
Share on other sites
I tried flipping the indices around, but also above there's the line:

rasterDesc.CullMode = D3D11_CULL_NONE;

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?

float4x4 World;
float4x4 View;
float4x4 Projection;
texture2D Texture;
SamplerState textureSampler {
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()));

Share this post

Link to post
Share on other sites

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

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.

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.

mD3D11DeviceContext->OMSetBlendState(0, 0, 0xFFFFFFFF);
mD3D11DeviceContext->OMSetDepthStencilState(0, 0);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!