XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

Debug in Direct3D10

Last post 08-01-2008 12:16 PM by MasterYoda2004. 7 replies.
  • 03-09-2008 6:03 PM

    Debug in Direct3D10

    Hello to everyone!!

    I used Direct3D9 for 1 year and learned a lot of things (shaders, skinned meshes...), ok.
    In particoular, i used debug dll and SDK installed automatically Visual Studio Extension that allowed D3D debug Directly from Visual Studio (in the output window there were a lot of D3D messages like Infos, but also debug, like wrong procedures, memory leaks) and it was very useful.

    In D3D10 i'm not able to find the same feature.
    I've enabled in D3D10 tab of DirectX Control Panel the Debug selecting my projects folder (./VisualStudio 9/Projects) and now if there are some problems it lanchs an exception and in output windows i can find the error...but not every time.
    For example
       
        //In upper part of my cpp file
        #define CHECK_HR(t) if (t != S_OK) {MessageBox(NULL,"Error",NULL,MB_OK);}

        //After device creation...
        hr = scritta->DrawText(NULL,"Ceccio!",-1,&rect,DT_LEFT,D3DXCOLOR(3,0,2,2));
        CHECK_HR(hr);

    If i try to run the code, it gives me the error messagebox, but in output windows there is nothing that can help me!
    Is there a way to analize any kind of Direct3D10 message?
    Here is complete source code if it can help you.

    #define CHECK_HR(t) if (t != S_OK) {MessageBox(NULL,"Error",NULL,MB_OK);}

    #include <windows.h>
    #include <d3d10.h>
    #include <d3dx10.h>

    #pragma comment(lib,"d3d10.lib")
    #pragma comment(lib,"d3dx10.lib")

    void InitD3D10();
    void Chiudi();
    void Render();

    //Oggetti fondamentali per finestra vuota
    const char g_szClassName[] = "myWindowClass";
    ID3D10Device *device; //Device
    IDXGISwapChain *swapChain; //Swapchain
    ID3D10RenderTargetView *RenderTarget; //RenderTarget
    ID3D10DepthStencilView *depthstencil; //Depth Stencil
    HWND hwnd;
    HRESULT hr;

    //Oggetti addizionali
    ID3DX10Font *scritta;


    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
            case WM_CLOSE:
                Chiudi();
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;

            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        MSG Msg;

        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = g_szClassName;
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

        RegisterClassEx(&wc);

        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            g_szClassName,
            "DirectX10",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
            NULL, NULL, hInstance, NULL);

        if(hwnd == NULL)
        {
            MessageBox(NULL, "Creazione della Finestra Fallita!", "Errore!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }

        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);

        InitD3D10();

        D3DX10CreateFont(device,24,0,FW_BOLD,1,false,DEFAULT_CHARSET,OUT_TT_ONLY_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH,"Arial",&scritta);


        ZeroMemory(&Msg,sizeof(MSG));

        while( WM_QUIT != Msg.message )
        {
            if( PeekMessage( &Msg, NULL, 0, 0, PM_REMOVE ) )
            {
                TranslateMessage( &Msg );
                DispatchMessage( &Msg );
            }
            else
            {
                Render();
            }
        }


        return Msg.wParam;
    }


    void InitD3D10()
    {


        {
       
            DXGI_SWAP_CHAIN_DESC sd;
            memset(&sd,0,sizeof(sd));

            sd.BufferCount = 1;
            sd.BufferDesc.Height = 800;
            sd.BufferDesc.Width = 600;
            sd.BufferDesc.RefreshRate.Numerator = 60;
            sd.BufferDesc.RefreshRate.Denominator = 1;
            sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
            sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
            sd.OutputWindow = hwnd;
            sd.Windowed = true;
            sd.SampleDesc.Count = 1;
            sd.SampleDesc.Quality = 0;

            D3D10CreateDeviceAndSwapChain(NULL,D3D10_DRIVER_TYPE_HARDWARE,NULL,0,D3D10_SDK_VERSION,&sd,&swapChain,&device);

        }

            ID3D10Texture2D *backbuffer;

           
            swapChain->GetBuffer(0,__uuidof(backbuffer),(LPVOID*)&backbuffer);
            device->CreateRenderTargetView(backbuffer,NULL,&RenderTarget);
            backbuffer->Release();
           
                ID3D10Texture2D *stenciltext;
            {
                D3D10_TEXTURE2D_DESC d;
                d.CPUAccessFlags = 0;
                d.Usage = D3D10_USAGE_DEFAULT;
                d.Width = 800;
                d.Height = 600;
                d.MipLevels = 1;
                d.Format = DXGI_FORMAT_D32_FLOAT;
                d.ArraySize = 1;
                d.SampleDesc.Count = 1;
                d.SampleDesc.Quality = 0;
                d.BindFlags = D3D10_BIND_DEPTH_STENCIL;
                d.MiscFlags = 0;

                device->CreateTexture2D(&d,0,&stenciltext);
            }
            {
                D3D10_DEPTH_STENCIL_VIEW_DESC p;
                p.Format = DXGI_FORMAT_D32_FLOAT;
                p.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
                p.Texture2DArray.MipSlice = 0;

                device->CreateDepthStencilView(stenciltext,&p,&depthstencil);
                stenciltext->Release();
            }

            device->OMSetRenderTargets(0,&RenderTarget,depthstencil);
           
            {
                D3D10_VIEWPORT vp;
                vp.Width = 800;
                vp.Height = 600;
                vp.MinDepth = 0.0f;
                vp.MaxDepth = 1.0f;
                vp.TopLeftX = 0;

                device->RSSetViewports(0,&vp);
            }       

    }

    void Render()
    {
        float color[4] = { 0, 0, 1, 0};
        device->ClearRenderTargetView(RenderTarget,color);

        RECT rect;
        rect.left=20;
        rect.right=600;
        rect.top=150;
        rect.bottom=400;
        hr = scritta->DrawText(NULL,"Ceccio!",-1,&rect,DT_LEFT,D3DXCOLOR(3,0,2,2));
        //CHECK_HR(hr); If i use this Macro next line gives me an exception!
        swapChain->Present(0,0);
    }

    void Chiudi()
    {
        device->ClearState();
        depthstencil->Release();
        swapChain->Release();
        RenderTarget->Release();
        device->Release();
    }

  • 03-09-2008 6:22 PM In reply to

    Re: Debug in Direct3D10

    You need to add the D3D10_CREATE_DEVICE_DEBUG flag to your creation call. But you need to be careful. If you release an application with this flag it will only run on systems where the SDK is installed.

  • 03-10-2008 9:46 AM In reply to

    Re: Debug in Direct3D10

    I've add the flag in D3D10CreateDeviceAndSwapChain but nothing changed.
    From the guide, i've found that i've to create a ID3D10InfoQueue interface by making a QueryInterface from the device...and then? How can i read messages?

    There is not way to show messages in output window of Visual Studio?
    Thank you again!
  • 03-12-2008 3:22 AM In reply to

    Re: Debug in Direct3D10

    If you enable the debug layer you should be able to see the messages in the output window of the debugger. You should check if you don’t have force the debug layer to off for your application in the control panel.

  • 03-12-2008 11:57 AM In reply to

    Re: Debug in Direct3D10

    I've found the error: DrawText() function does not give an HRESULT, but an int!
    So if int = 0 then the function failed. I checked like an HRESULT and so there where every time error!

    Anyway, the D3D10 debug it's very different than D3D9 one. The new debug layer does not say me infos about Device, SwapChain, does not say me anything about memory leaks...

    Sob.
  • 03-13-2008 5:20 PM In reply to

    Re: Debug in Direct3D10

    I ask your help again, please.
    The Direct3D debug output does not say me nothing about this code, but i can't see the words on the screen!
    Thank you!!

    #define D3DDEBUG
    #define CHECK_HR(t) if (FAILED(hr)) {MessageBox(NULL,"Error",NULL,MB_OK);}

    #include <windows.h>
    #include <d3d10.h>
    #include <d3dx10.h>
    #pragma comment(lib,"d3d10.lib")

    #ifdef D3DDEBUG
    #    pragma comment(lib,"d3dx10d.lib") //Libreria d3dx di debug
    #else
    #    pragma comment(lib,"d3dx10.lib")
    #endif

    void InitD3D10();
    void Chiudi();
    void Render();

    //Oggetti fondamentali per finestra vuota
    const char g_szClassName[] = "myWindowClass";
    ID3D10Device *device; //Device
    IDXGISwapChain *swapChain; //Swapchain
    ID3D10RenderTargetView *RenderTarget; //RenderTarget
    ID3D10DepthStencilView *depthstencil; //Depth Stencil surface
    HWND hwnd;
    #ifdef D3DDEBUG
    HRESULT hr;
    #endif

    //Oggetti addizionali
    ID3DX10Font *scritta;


    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
            case WM_CLOSE:
                Chiudi();
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;

            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        MSG Msg;

        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = g_szClassName;
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

        RegisterClassEx(&wc);

        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            g_szClassName,
            "Fonts in DirectX10",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
            NULL, NULL, hInstance, NULL);

    #ifdef D3DDEBUG

        if(hwnd == NULL)
        {
            MessageBox(NULL, "Creazione della Finestra Fallita!", "Errore!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }

    #endif

        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);

        InitD3D10();

    #ifdef D3DDEBUG
        hr = D3DX10CreateFont( device, 10, 9, 1600, 1, FALSE, DEFAULT_CHARSET,OUT_RASTER_PRECIS, ANTIALIASED_QUALITY,FF_DONTCARE,"Arial", &scritta);
        CHECK_HR(hr);
    #else
        D3DX10CreateFont( device, 10, 9, 1600, 1, FALSE, DEFAULT_CHARSET,OUT_RASTER_PRECIS, ANTIALIASED_QUALITY,FF_DONTCARE,"Arial", &scritta);
    #endif

        ZeroMemory(&Msg,sizeof(MSG));

        while( WM_QUIT != Msg.message )
        {
            if( PeekMessage( &Msg, NULL, 0, 0, PM_REMOVE ) )
            {
                TranslateMessage( &Msg );
                DispatchMessage( &Msg );
            }
            else
            {
                Render();
            }
        }


        return Msg.wParam;
    }


    void InitD3D10()
    {


        {
       
            DXGI_SWAP_CHAIN_DESC sd;
            memset(&sd,0,sizeof(sd));

            sd.BufferCount = 1;
            sd.BufferDesc.Height = 800;
            sd.BufferDesc.Width = 600;
            sd.BufferDesc.RefreshRate.Numerator = 60;
            sd.BufferDesc.RefreshRate.Denominator = 1;
            sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
            sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
            sd.OutputWindow = hwnd;
            sd.Windowed = true;
            sd.SampleDesc.Count = 1;
            sd.SampleDesc.Quality = 0;
    #ifdef D3DDEBUG
            hr = D3D10CreateDeviceAndSwapChain(NULL,D3D10_DRIVER_TYPE_HARDWARE,NULL,D3D10_CREATE_DEVICE_DEBUG,D3D10_SDK_VERSION,&sd,&swapChain,&device);
            CHECK_HR(hr);
    #else
             D3D10CreateDeviceAndSwapChain(NULL,D3D10_DRIVER_TYPE_HARDWARE,NULL,D3D10_CREATE_DEVICE_DEBUG,D3D10_SDK_VERSION,&sd,&swapChain,&device);
    #endif
        }

            ID3D10Texture2D *backbuffer;
    #ifdef D3DDEBUG
            hr  = swapChain->GetBuffer(0,__uuidof(backbuffer),(LPVOID*)&backbuffer);
            CHECK_HR(hr);
            hr = device->CreateRenderTargetView(backbuffer,NULL,&RenderTarget);
            CHECK_HR(hr);
    #else
            swapChain->GetBuffer(0,__uuidof(backbuffer),(LPVOID*)&backbuffer);
            device->CreateRenderTargetView(backbuffer,NULL,&RenderTarget);
    #endif
            backbuffer->Release();
           
                ID3D10Texture2D *stenciltext;
            {
                D3D10_TEXTURE2D_DESC d;
                d.CPUAccessFlags = 0;
                d.Usage = D3D10_USAGE_DEFAULT;
                d.Width = 800;
                d.Height = 600;
                d.MipLevels = 1;
                d.Format = DXGI_FORMAT_D32_FLOAT;
                d.ArraySize = 1;
                d.SampleDesc.Count = 1;
                d.SampleDesc.Quality = 0;
                d.BindFlags = D3D10_BIND_DEPTH_STENCIL;
                d.MiscFlags = 0;
    #ifdef D3DDEBUG
                hr = device->CreateTexture2D(&d,0,&stenciltext);
                CHECK_HR(hr);
    #else
                 device->CreateTexture2D(&d,0,&stenciltext);
    #endif
            }

            {
                D3D10_DEPTH_STENCIL_VIEW_DESC p;
                p.Format = DXGI_FORMAT_D32_FLOAT;
                p.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
                p.Texture2DArray.MipSlice = 0;

    #ifdef D3DDEBUG
                hr = device->CreateDepthStencilView(stenciltext,&p,&depthstencil);
                CHECK_HR(hr);
    #else
                device->CreateDepthStencilView(stenciltext,&p,&depthstencil);

    #endif
                device->OMSetRenderTargets(0,&RenderTarget,depthstencil);
                stenciltext->Release();
            }

           
            {
                D3D10_VIEWPORT vp;
                vp.Width = 800;
                vp.Height = 600;
                vp.MinDepth = 0.0f;
                vp.MaxDepth = 1.0f;
                vp.TopLeftX = 0;

                device->RSSetViewports(0,&vp);
            }       

    }

    void Render()
    {
        float color[4] = { 1, 1, 0, 0};
        device->ClearRenderTargetView(RenderTarget,color);

        RECT rect;
        memset(&rect,0,sizeof(RECT));
            scritta->DrawText(NULL,"Ceccio",-1,&rect,DT_CALCRECT,D3DXCOLOR(0xFFFFFFFF));
            scritta->DrawText(NULL,"Ceccio",-1,&rect,DT_LEFT|DT_TOP,D3DXCOLOR(0xFFFFFFFF));

    #ifdef D3DDEBUG
            hr = swapChain->Present(0,0);
            CHECK_HR(hr);
    #else
            swapChain->Present(0,0);
    #endif

    }

    void Chiudi()
    {
        scritta->Release();
        depthstencil->Release();
        swapChain->Release();
        RenderTarget->Release();
        device->Release();
    }

  • 04-11-2008 11:37 AM In reply to

    Re: Debug in Direct3D10

    I am having similiar problems. I use the  March 2008 SDK on a NVIDIA GT 8800. I havent been able to get any debug messages out in the Visual Studio output console.

    The DirectX10 Control Panel under Vista seems to be disabled.

    Anyone had any luck with the new debug layer?

     

     

     

     

     

     

  • 08-01-2008 12:16 PM In reply to

    Re: Debug in Direct3D10

    Make sure you link with the debug library:

    d3dx10d.lib

     

     


Page 1 of 1 (8 items) Previous Next