Sign in to follow this  

WP8 Depth Buffer works in Emulator, not on the ARM device

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

Hi all.

 

I'm trying to display a scene on windows phone 8 using D3D11. I got it to work without a Depth Buffer (using mostly Windows phone SDK sample). But now I actually need a depth buffer to render the scene correctly. I got it to work with a depth buffer on the Windows Phone Emulator (win32 build), but when I test it on any windows phone (ARM build), I get nothing (black screen).

 

So I must hit something that the graphic card on my computer understands (that is the only part of the windows phone emulator that is not fully emulated I think) but that the graphic card on the actual phone doesn't get.

 

Please if you have any idea let me know. Here is my code:

  UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;

  D3D_FEATURE_LEVEL featureLevels[] = 
  {
    D3D_FEATURE_LEVEL_9_3
  };

  // Create the Direct3D 11 API device object and a corresponding context.
  ComPtr<ID3D11Device> device;
  ComPtr<ID3D11DeviceContext> context;
  ThrowIfFailed(
    D3D11CreateDevice(
    nullptr, // Specify nullptr to use the default adapter.
    D3D_DRIVER_TYPE_HARDWARE,
    nullptr,
    creationFlags, // Set set debug and Direct2D compatibility flags.
    featureLevels, // List of feature levels this app can support.
    ARRAYSIZE(featureLevels),
    D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION.
    &device, // Returns the Direct3D device created.
    &m_featureLevel, // Returns feature level of device created.
    &context // Returns the device immediate context.
    )
    );

  // Get the Direct3D 11.1 API device and context interfaces.
  ThrowIfFailed(
    device.As(&m_d3dDevice)
    );

  ThrowIfFailed(
    context.As(&m_d3dContext)
    );

 
 CD3D11_TEXTURE2D_DESC renderTargetDesc(
    DXGI_FORMAT_B8G8R8A8_UNORM,
    static_cast<UINT>(m_renderTargetSize.Width),
    static_cast<UINT>(m_renderTargetSize.Height),
    1,
    1,
    D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE
    );
  renderTargetDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE;

  // Allocate a 2-D surface as the render target buffer.
  ThrowIfFailed(
    m_d3dDevice->CreateTexture2D(
    &renderTargetDesc,
    nullptr,
    &m_renderTarget
    )
    );

  ThrowIfFailed(
    m_d3dDevice->CreateRenderTargetView(
    m_renderTarget.Get(),
    nullptr,
    &m_renderTargetView
    )
    );
  
  // Create a depth stencil view.
 CD3D11_TEXTURE2D_DESC depthBufferDesc(
    DXGI_FORMAT_D24_UNORM_S8_UINT,
    static_cast<UINT>(m_renderTargetSize.Width),
    static_cast<UINT>(m_renderTargetSize.Height),
    1,
    1,
    D3D11_BIND_DEPTH_STENCIL); //tried with D3D11_BIND_RENDER_TARGET with a format DXGI_FORMAT_R24G8_TYPELESS in didn't change anything

  ThrowIfFailed(
    m_d3dDevice->CreateTexture2D(
    &depthBufferDesc,
    nullptr,
    &m_depthStencilBuffer
    )
    );

  D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
// 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 = 0xFF;
depthStencilDesc.StencilWriteMask = 0xFF;

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

  ThrowIfFailed(
    m_d3dDevice->CreateDepthStencilState(
    &depthStencilDesc,
    &m_depthStencilState
    )
    );

  m_d3dContext->OMSetDepthStencilState(m_depthStencilState.Get(), 1);
  
  CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(
    D3D11_DSV_DIMENSION_TEXTURE2D, DXGI_FORMAT_D24_UNORM_S8_UINT, 0);
  ThrowIfFailed(
    m_d3dDevice->CreateDepthStencilView(
    m_depthStencilBuffer.Get(),
    &depthStencilViewDesc,
    &m_depthStencilView
    )
    );
  m_d3dContext->OMSetRenderTargets(1, m_renderTargetView.GetAddressOf(), m_depthStencilView.Get());

  CD3D11_VIEWPORT viewport(
    0.0f,
    0.0f,
    m_renderTargetSize.Width,
    m_renderTargetSize.Height
    );

  m_d3dContext->RSSetViewports(1, &viewport);

... Before Draw ...
  
const float midnightBlue[] = { 245.0f/255.0f, 241.0/255.0f, 196.0f/255.0f, 1.000f };
	m_d3dContext->ClearRenderTargetView(
		m_renderTargetView.Get(),
		midnightBlue
		);

  m_d3dContext->ClearDepthStencilView(
        m_depthStencilView.Get(),
        D3D11_CLEAR_DEPTH,
        1.0f,
        0
        );

  m_d3dContext->OMSetRenderTargets(1, m_renderTargetView.GetAddressOf(), m_depthStencilView.Get()); //This only works in the Emulator.
  //m_d3dContext->OMSetRenderTargets(1, m_renderTargetView.GetAddressOf(), nullptr); This works fine but doesn't use the Depth buffer, so the scene is not very good.

Share this post


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