Sign in to follow this  
ybatra

DX11 Don't know RT is clearing but why primitive is not rendering

Recommended Posts

ybatra    155
// Initialize D3D
bool D3DRenderer::Initialize()
{
HRESULT hr;
D3D_DRIVER_TYPE m_pDriverType;
D3D_FEATURE_LEVEL       m_pFeatureLevel;
 
D3D_DRIVER_TYPE driverTypes[] =
    {
        D3D_DRIVER_TYPE_HARDWARE,
        D3D_DRIVER_TYPE_WARP,
        D3D_DRIVER_TYPE_REFERENCE,
    };
UINT numDriverTypes = ARRAYSIZE( driverTypes );
 
// Create the D3D device
    D3D_FEATURE_LEVEL featureLevel[]= 
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
int num= ARRAYSIZE(featureLevel);
 
    // Create device, context and swapchain
    DXGI_SWAP_CHAIN_DESC sdDesc;
    ZeroMemory(&sdDesc, sizeof(sdDesc));
sdDesc.BufferDesc.ScanlineOrdering=DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
sdDesc.BufferDesc.Scaling=DXGI_MODE_SCALING_UNSPECIFIED;
sdDesc.BufferDesc.RefreshRate.Numerator   = 60;
    sdDesc.BufferDesc.RefreshRate.Denominator = 1;
sdDesc.BufferDesc.Width                   = m_pWindow->GetWidth();
    sdDesc.BufferDesc.Height                  = m_pWindow->GetHeight();
    sdDesc.BufferDesc.Format                  = DXGI_FORMAT_R8G8B8A8_UNORM;
    sdDesc.BufferCount                        = 1;
sdDesc.BufferUsage                        = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sdDesc.SampleDesc.Count                   = 1;
    sdDesc.SampleDesc.Quality                 = 0;
    sdDesc.OutputWindow                       = m_pWindow->GetHwnd();
    sdDesc.Windowed                           = TRUE;
    
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
    {
        m_pDriverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDeviceAndSwapChain( NULL, m_pDriverType, NULL, NULL, featureLevel, num,
D3D11_SDK_VERSION, &sdDesc, &m_pSwapChain, &m_pDevice, &m_pFeatureLevel, &m_pDeviceContext );
        if( SUCCEEDED( hr ) )
            break;
    }
if(FAILED(hr))
return FALSE;
 
    // Make and set D3D11 render target objects
    hr = m_pSwapChain->GetBuffer(0, __uuidof(*m_pRTTexture2D), reinterpret_cast<void**>(&m_pRTTexture2D));
    CHECK_FAILURE(hr, "Could not create render target texture.");
 
    hr = m_pDevice->CreateRenderTargetView(m_pRTTexture2D, NULL, &m_pRTView);
    CHECK_FAILURE(hr, "Could not create render target view.");
 
 
    // Make and set depth stencil
    D3D11_TEXTURE2D_DESC dsTexDesc;
ZeroMemory(&dsTexDesc, sizeof(dsTexDesc));
    dsTexDesc.Width              = m_pWindow->GetWidth();
    dsTexDesc.Height             = m_pWindow->GetHeight();
    dsTexDesc.MipLevels          = 1;
    dsTexDesc.ArraySize          = 1;
    dsTexDesc.Format             = DXGI_FORMAT_D32_FLOAT;
    dsTexDesc.SampleDesc.Count   = 1;
    dsTexDesc.SampleDesc.Quality = 0;
    dsTexDesc.Usage              = D3D11_USAGE_DEFAULT;
    dsTexDesc.BindFlags          = D3D11_BIND_DEPTH_STENCIL;
    dsTexDesc.CPUAccessFlags     = 0;
    dsTexDesc.MiscFlags          = 0;
    hr = m_pDevice->CreateTexture2D(&dsTexDesc, NULL, &m_pDSTexture2D);
    CHECK_FAILURE(hr, "Could not create depth stencil texture.");
 
hr = m_pDevice->CreateDepthStencilView(m_pDSTexture2D, NULL, &m_pDSView);
    CHECK_FAILURE(hr, "Could not create depth stencil view.");
 
m_pDeviceContext->OMSetRenderTargets(1, &m_pRTView, m_pDSView);
 
// Set depth stencil state
    D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));
depthStencilDesc.DepthEnable                  = TRUE;
    depthStencilDesc.DepthWriteMask               = D3D11_DEPTH_WRITE_MASK_ALL;
    depthStencilDesc.DepthFunc                    = D3D11_COMPARISON_ALWAYS;
    depthStencilDesc.StencilEnable                = FALSE;
    hr = m_pDevice->CreateDepthStencilState(&depthStencilDesc, &m_pDSState);
    CHECK_FAILURE(hr, "Could not create depth stencil state.");
    m_pDeviceContext->OMSetDepthStencilState(m_pDSState,0);
 
    // Setup the viewport
    D3D11_VIEWPORT vp;
ZeroMemory(&vp, sizeof(vp));
    vp.Width = m_pWindow->GetWidth();
    vp.Height =m_pWindow->GetHeight();
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;
    vp.TopLeftX = 0;
    vp.TopLeftY = 0;
    m_pDeviceContext->RSSetViewports( 1, &vp );
 
// Compile the vertex shader
    ID3DBlob* pVSBlob = NULL;
    hr = CompileShaderFromFile( L"Main.fx", "VS", "vs_4_0", &pVSBlob );
    CHECK_FAILURE(hr, "Could not Compile Vertex Shader");
 
// Create the vertex shader
hr = m_pDevice->CreateVertexShader( pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), NULL, &m_pVertexShader );
CHECK_FAILURE(hr, "Could not Create Vertex Shader");
 
    // Define the input layout
    D3D11_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    };
    UINT numElements = sizeof( layout ) / sizeof( layout[0] );
 
    // Create the input layout
hr = m_pDevice->CreateInputLayout( layout, numElements, pVSBlob->GetBufferPointer(),
                                          pVSBlob->GetBufferSize(), &m_pVertexLayout );
pVSBlob->Release();
CHECK_FAILURE(hr, "Could not create ");
 
    // Set the input layout
    m_pDeviceContext->IASetInputLayout( m_pVertexLayout );
 
// Compile the pixel shader
ID3DBlob* pPSBlob = NULL;
    hr = CompileShaderFromFile( L"Main.fx", "PS", "ps_4_0", &pPSBlob );
    CHECK_FAILURE(hr, "Could not Compile Pixel Shader");
 
// Create the pixel shader
hr = m_pDevice->CreatePixelShader( pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), NULL, &m_pPixelShader);
pPSBlob->Release();
    CHECK_FAILURE(hr, "Could not create Pixel Shader");
 
    // Create vertex buffer
    SimpleVertex vertices[] =
    {
{ XMFLOAT3( -1.0f, 1.0f, 0.0f ), XMFLOAT4( 1.0f, 0.0f, 0.0f, 1.0f ) },
        { XMFLOAT3( 1.0f, 1.0f, 0.0f ), XMFLOAT4( 1.0f, 0.0f, 0.0f, 1.0f ) },
        { XMFLOAT3( -1.0f,-1.0f, 1.0f ), XMFLOAT4( 1.0f, 0.0f, 0.0f, 1.0f ) },
        { XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT4( 1.0f, 0.0f, 0.0f, 1.0f ) },
        { XMFLOAT3( 1.0f, 1.0f, 0.0f ), XMFLOAT4( 1.0f, 0.0f, 0.0f, 1.0f ) },
        { XMFLOAT3( 1.0f,-1.0f, 1.0f ), XMFLOAT4( 1.0f, 0.0f, 0.0f, 1.0f ) },
 
        { XMFLOAT3( -1.0f, 1.0f, 0.0f ), XMFLOAT4( 1.0f, 1.0f, 1.0f, 1.0f ) },
        { XMFLOAT3( 1.0f, 1.0f, 0.0f ), XMFLOAT4( 1.0f, 1.0f, 1.0f, 1.0f ) },
        { XMFLOAT3( -1.0f,-1.0f, 1.0f ), XMFLOAT4( 1.0f, 1.0f, 1.0f, 1.0f ) },
        { XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT4( 1.0f, 1.0f, 1.0f, 1.0f ) },
        { XMFLOAT3( 1.0f, 1.0f, 0.0f ), XMFLOAT4( 1.0f, 1.0f, 0.0f, 1.0f ) },
        { XMFLOAT3( 1.0f,-1.0f, 1.0f ), XMFLOAT4( 1.0f, 1.0f, 1.0f, 1.0f ) },
    };
 
    D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
    bd.Usage = D3D11_USAGE_DEFAULT;
    bd.ByteWidth = sizeof( SimpleVertex ) *12;
    bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    bd.CPUAccessFlags = 0;
    bd.MiscFlags = 0;
 
    D3D11_SUBRESOURCE_DATA InitData;
    InitData.pSysMem = vertices;
    hr = m_pDevice->CreateBuffer( &bd, &InitData, &m_pVertexBuffer );
    CHECK_FAILURE(hr, "Could not create Vertex Buffer.");
 
    // Set vertex buffer
    UINT stride = sizeof( SimpleVertex );
    UINT offset = 0;
    m_pDeviceContext->IASetVertexBuffers( 0, 1, &m_pVertexBuffer, &stride, &offset );
 
    // Set primitive topology
    m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
 
 
D3D11_RASTERIZER_DESC RSdesc;
ZeroMemory(&RSdesc, sizeof(RSdesc));
RSdesc.CullMode=D3D11_CULL_NONE;
RSdesc.MultisampleEnable=FALSE;
RSdesc.AntialiasedLineEnable=FALSE;
RSdesc.DepthClipEnable=TRUE;
RSdesc.FillMode=D3D11_FILL_SOLID;
RSdesc.FrontCounterClockwise=FALSE;
RSdesc.ScissorEnable=FALSE;
 
m_pDevice->CreateRasterizerState(&RSdesc, &m_pRasterStateNoCulling);  
m_pDeviceContext->RSSetState(m_pRasterStateNoCulling);
 
//Create TExture for Staging resource
    D3D11_TEXTURE2D_DESC descStaging;
ZeroMemory(&descStaging, sizeof(descStaging));
    descStaging.Width = m_pWindow->GetWidth();;
    descStaging.Height= m_pWindow->GetHeight();;
    descStaging.MipLevels = 1;
    descStaging.ArraySize = 1;
    descStaging.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    descStaging.SampleDesc.Count = 1;
    descStaging.SampleDesc.Quality = 0;
    descStaging.Usage = D3D11_USAGE_STAGING;
    descStaging.BindFlags = 0;
    descStaging.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
    descStaging.MiscFlags = 0;
    hr=m_pDevice->CreateTexture2D(&descStaging,NULL,&m_sRTTexture2D);
    CHECK_FAILURE(hr, "Could not create texture for staging resource.");
return true;
}
 
//--------------------------------------------------------------------------------------
// Helper for compiling shaders with D3DX11
//--------------------------------------------------------------------------------------
HRESULT D3DRenderer::CompileShaderFromFile( WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut )
{
    HRESULT hr = S_OK;
 
    DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif
 
    ID3DBlob* pErrorBlob;
    hr = D3DCompileFromFile(szFileName, NULL, NULL, szEntryPoint, szShaderModel, 
        dwShaderFlags, 0, ppBlobOut, &pErrorBlob);
    if( FAILED(hr) )
    {
        if( pErrorBlob != NULL )
            OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
        if( pErrorBlob ) pErrorBlob->Release();
        return hr;
    }
    if( pErrorBlob ) pErrorBlob->Release();
 
    return S_OK;
}

Run(TestCase* pTest)
{
    strcpy_s(m_lastError, "");
    ClearRenderTargetView();
    ClearDepthStencilView();
 
    // Render before NVAPI test enabled
m_pDeviceContext->VSSetShader( m_pVertexShader, NULL, 0 );
m_pDeviceContext->PSSetShader( m_pPixelShader, NULL, 0 );
    m_pDeviceContext->Draw( 6, 0 );

}

Share this post


Link to post
Share on other sites
Jason Z    6436

You will not get many responses with a post like this.  In general, you should try to describe the problem more thoroughly (and not only in the subject line...).  What have you tried, and what symptoms do you see?  Where did your code come from - was it based on a known working program, or is it completely new code?

 

Information like this will help others help you.

Share this post


Link to post
Share on other sites
ybatra    155

I tried rendering some geometry on to the back buffer, with enabling Z testing. but I found that "ClearRenderTargetView()" is clearing the render target(Backbuffer), but draw call was not successful. I meant primitives are not drawing onto the backbuffer.  

Share this post


Link to post
Share on other sites
ybatra    155

I tried rendering some geometry on to the back buffer, with enabling Z testing. but I found that "ClearRenderTargetView()" is clearing the render target(Backbuffer), but draw call was not successful. I meant primitives are not drawing onto the backbuffer.  

even I disabled the Z testing, still I was getting the same results.

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  

  • Similar Content

    • By RubenRS
      How do i open an image to use it as Texture2D information without D3DX11CreateShaderResourceViewFromFile? And how it works for different formats like (JPG, PNG, BMP, DDS,  etc.)?
      I have an (512 x 512) image with font letters, also i have the position and texcoord of every letter. The main idea is that i want to obtain the image pixel info, use the position and texcoords to create a new texture with one letter and render it. Or am I wrong in something?
    • By thmfrnk
      Hey,
      I found a very interesting blog post here: https://bartwronski.com/2017/04/13/cull-that-cone/
      However, I didn't really got how to use his "TestConeVsSphere" test in 3D (last piece of code on his post). I have the frustumCorners of a 2D Tile cell in ViewSpace and my 3D Cone Origin and Direction, so where to place the "testSphere"? I thought about to also move the Cone into viewspace and put the sphere to the Center of the Cell with the radius of half-cellsize, however what about depth? A sphere does not have inf depth?
      I am missing anything? Any Ideas?
      Thx, Thomas
    • By Modymek
      hi all
      I want to enable and disable shader in MPCH Media player Classic
      the MPCH have shader option using HLSL shaders
      I want the shader to read each file extension before it plays the file
      so if the video file name is video.GR.Mp4 it will play it in Grayscale shader 
      if it is not and standard file name Video.Mp4 without GR. unique extension so it plays standard without shader or end the shader
      here is the shader I have for grayscale
      // $MinimumShaderProfile: ps_2_0
      sampler s0 : register(s0);
      float4 main(float2 tex : TEXCOORD0) : COLOR {
          float c0 = dot(tex2D(s0, tex), float4(0.299, 0.587, 0.114, 0));
          return c0;
      }
       
      I want to add if or block stantement or bloean to detect file name before it call the shader in order to go to the procedure or disable it or goto end direct without it
       
      any thoughts or help
    • By noodleBowl
      I've gotten to part in my DirectX 11 project where I need to pass the MVP matrices to my vertex shader. And I'm a little lost when it comes to the use of the constant buffer with the vertex shader
      I understand I need to set up the constant buffer just like any other buffer:
      1. Create a buffer description with the D3D11_BIND_CONSTANT_BUFFER flag 2. Map my matrix data into the constant buffer 3. Use VSSetConstantBuffers to actually use the buffer But I get lost at the VertexShader part, how does my vertex shader know to use this constant buffer when we get to the shader side of things
      In the example I'm following I see they have this as their vertex shader, but I don't understand how the shader knows to use the MatrixBuffer cbuffer. They just use the members directly. What if there was multiple cbuffer declarations like the Microsoft documentation says you could have?
      //Inside vertex shader cbuffer MatrixBuffer { matrix worldMatrix; matrix viewMatrix; matrix projectionMatrix; }; struct VertexInputType { float4 position : POSITION; float4 color : COLOR; }; struct PixelInputType { float4 position : SV_POSITION; float4 color : COLOR; }; PixelInputType ColorVertexShader(VertexInputType input) { PixelInputType output; // Change the position vector to be 4 units for proper matrix calculations. input.position.w = 1.0f; // Calculate the position of the vertex against the world, view, and projection matrices. output.position = mul(input.position, worldMatrix); output.position = mul(output.position, viewMatrix); output.position = mul(output.position, projectionMatrix); // Store the input color for the pixel shader to use. output.color = input.color; return output; }  
    • By gomidas
      I am trying to add normal map to my project I have an example of a cube: 
      I have normal in my shader I think. Then I set shader resource view for texture (NOT BUMP)
                  device.ImmediateContext.PixelShader.SetShaderResource(0, textureView);             device.ImmediateContext.Draw(VerticesCount,0); What should I do to set my normal map or how it is done in dx11 generally example c++?
  • Popular Now