Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

DX11 not drawing anything


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 DementedCarrot   Members   -  Reputation: 141

Like
0Likes
Like

Posted 24 April 2012 - 11:12 PM

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. Posted Image

http://i.imgur.com/DlEZr.png

#2 jameszhao00   Members   -  Reputation: 269

Like
0Likes
Like

Posted 24 April 2012 - 11:59 PM

set render target? :D

#3 DementedCarrot   Members   -  Reputation: 141

Like
0Likes
Like

Posted 25 April 2012 - 12:17 AM

Heheh.

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

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.
mContext->RSSetState(mRasterState);


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

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.

#4 MJP   Moderators   -  Reputation: 5418

Like
0Likes
Like

Posted 25 April 2012 - 12:50 AM

You don't seem to be clearing your depth buffer.

#5 DementedCarrot   Members   -  Reputation: 141

Like
0Likes
Like

Posted 25 April 2012 - 12:53 AM

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



#6 Ripiz   Members   -  Reputation: 521

Like
0Likes
Like

Posted 25 April 2012 - 01:03 AM

Maybe triangle is backfacing?

#7 DementedCarrot   Members   -  Reputation: 141

Like
0Likes
Like

Posted 25 April 2012 - 01:06 AM

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

#8 Ripiz   Members   -  Reputation: 521

Like
0Likes
Like

Posted 25 April 2012 - 01:23 AM

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?

#9 DementedCarrot   Members   -  Reputation: 141

Like
0Likes
Like

Posted 25 April 2012 - 01:41 AM

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 {
    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()));
    }
};


#10 Ripiz   Members   -  Reputation: 521

Like
0Likes
Like

Posted 25 April 2012 - 02:05 AM

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->RSSetState(0);
mD3D11DeviceContext->OMSetBlendState(0, 0, 0xFFFFFFFF);
mD3D11DeviceContext->OMSetDepthStencilState(0, 0);


#11 DementedCarrot   Members   -  Reputation: 141

Like
0Likes
Like

Posted 25 April 2012 - 02:14 AM

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.


Right on. Posted Image
At least my clear color isn't gray.

Also commenting those out changes nothing.

#12 Ripiz   Members   -  Reputation: 521

Like
0Likes
Like

Posted 25 April 2012 - 02:34 AM

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;

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:
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()));
   }
};

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

#13 DementedCarrot   Members   -  Reputation: 141

Like
0Likes
Like

Posted 25 April 2012 - 02:51 AM

No difference :P

Thanks for looking

#14 kauna   Members   -  Reputation: 1131

Like
0Likes
Like

Posted 25 April 2012 - 04:57 AM

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;


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

Cheers!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS