VirtualBox

Ignore:
Timestamp:
May 31, 2022 5:39:55 PM (3 years ago)
Author:
vboxsync
Message:

WDDM: testcase update.

Location:
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/Makefile.kmk

    r94469 r95152  
    3939VBoxD3D11_TEMPLATE    = VBOXR3STATIC
    4040VBoxD3D11_CXXFLAGS   += -wd4458 -wd4668 -wd4838 -wd5029 -wd5039
     41VBoxD3D11_INCS       += $(PATH_ROOT)/src/VBox/Devices/Graphics/shaders
    4142VBoxD3D11_LIBS        = d3d11.lib
    4243VBoxD3D11_SOURCES     = \
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d11main.cpp

    r95081 r95152  
    438438}
    439439
     440#include "d3d11blitter.hlsl.vs.h"
     441#include "d3d11blitter.hlsl.ps.h"
     442
     443typedef struct D3D11BLITTER
     444{
     445    ID3D11Device           *pDevice;
     446    ID3D11DeviceContext    *pImmediateContext;
     447
     448    ID3D11VertexShader     *pVertexShader;
     449    ID3D11PixelShader      *pPixelShader;
     450    ID3D11SamplerState     *pSamplerState;
     451    ID3D11RasterizerState  *pRasterizerState;
     452    ID3D11BlendState       *pBlendState;
     453} D3D11BLITTER;
     454
     455
     456static void BlitRelease(D3D11BLITTER *pBlitter)
     457{
     458    D3D_RELEASE(pBlitter->pVertexShader);
     459    D3D_RELEASE(pBlitter->pPixelShader);
     460    D3D_RELEASE(pBlitter->pSamplerState);
     461    D3D_RELEASE(pBlitter->pRasterizerState);
     462    D3D_RELEASE(pBlitter->pBlendState);
     463    RT_ZERO(*pBlitter);
     464}
     465
     466
     467static HRESULT BlitInit(D3D11BLITTER *pBlitter, ID3D11Device *pDevice, ID3D11DeviceContext *pImmediateContext)
     468{
     469    HRESULT hr;
     470
     471    RT_ZERO(*pBlitter);
     472
     473    pBlitter->pDevice = pDevice;
     474    pBlitter->pImmediateContext = pImmediateContext;
     475
     476    HTEST(pBlitter->pDevice->CreateVertexShader(g_vs_blitter, sizeof(g_vs_blitter), NULL, &pBlitter->pVertexShader));
     477    HTEST(pBlitter->pDevice->CreatePixelShader(g_ps_blitter, sizeof(g_ps_blitter), NULL, &pBlitter->pPixelShader));
     478
     479    D3D11_SAMPLER_DESC SamplerDesc;
     480    SamplerDesc.Filter         = D3D11_FILTER_ANISOTROPIC;
     481    SamplerDesc.AddressU       = D3D11_TEXTURE_ADDRESS_WRAP;
     482    SamplerDesc.AddressV       = D3D11_TEXTURE_ADDRESS_WRAP;
     483    SamplerDesc.AddressW       = D3D11_TEXTURE_ADDRESS_WRAP;
     484    SamplerDesc.MipLODBias     = 0.0f;
     485    SamplerDesc.MaxAnisotropy  = 4;
     486    SamplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
     487    SamplerDesc.BorderColor[0] = 0.0f;
     488    SamplerDesc.BorderColor[1] = 0.0f;
     489    SamplerDesc.BorderColor[2] = 0.0f;
     490    SamplerDesc.BorderColor[3] = 0.0f;
     491    SamplerDesc.MinLOD         = 0.0f;
     492    SamplerDesc.MaxLOD         = 0.0f;
     493    HTEST(pBlitter->pDevice->CreateSamplerState(&SamplerDesc, &pBlitter->pSamplerState));
     494
     495    D3D11_RASTERIZER_DESC RasterizerDesc;
     496    RasterizerDesc.FillMode              = D3D11_FILL_SOLID;
     497    RasterizerDesc.CullMode              = D3D11_CULL_NONE;
     498    RasterizerDesc.FrontCounterClockwise = FALSE;
     499    RasterizerDesc.DepthBias             = 0;
     500    RasterizerDesc.DepthBiasClamp        = 0.0f;
     501    RasterizerDesc.SlopeScaledDepthBias  = 0.0f;
     502    RasterizerDesc.DepthClipEnable       = FALSE;
     503    RasterizerDesc.ScissorEnable         = FALSE;
     504    RasterizerDesc.MultisampleEnable     = FALSE;
     505    RasterizerDesc.AntialiasedLineEnable = FALSE;
     506    HTEST(pBlitter->pDevice->CreateRasterizerState(&RasterizerDesc, &pBlitter->pRasterizerState));
     507
     508    D3D11_BLEND_DESC BlendDesc;
     509    BlendDesc.AlphaToCoverageEnable = FALSE;
     510    BlendDesc.IndependentBlendEnable = FALSE;
     511    for (unsigned i = 0; i < RT_ELEMENTS(BlendDesc.RenderTarget); ++i)
     512    {
     513        BlendDesc.RenderTarget[i].BlendEnable           = FALSE;
     514        BlendDesc.RenderTarget[i].SrcBlend              = D3D11_BLEND_SRC_COLOR;
     515        BlendDesc.RenderTarget[i].DestBlend             = D3D11_BLEND_ZERO;
     516        BlendDesc.RenderTarget[i].BlendOp               = D3D11_BLEND_OP_ADD;
     517        BlendDesc.RenderTarget[i].SrcBlendAlpha         = D3D11_BLEND_SRC_ALPHA;
     518        BlendDesc.RenderTarget[i].DestBlendAlpha        = D3D11_BLEND_ZERO;
     519        BlendDesc.RenderTarget[i].BlendOpAlpha          = D3D11_BLEND_OP_ADD;
     520        BlendDesc.RenderTarget[i].RenderTargetWriteMask = 0xF;
     521    }
     522    HTEST(pBlitter->pDevice->CreateBlendState(&BlendDesc, &pBlitter->pBlendState));
     523
     524    return S_OK;
     525}
     526
     527
     528static HRESULT BlitFromTexture(D3D11BLITTER *pBlitter, ID3D11RenderTargetView *pDstRenderTargetView,
     529                               float cDstWidth, float cDstHeight, D3D11_RECT const &rectDst,
     530                               ID3D11ShaderResourceView *pSrcShaderResourceView)
     531{
     532    HRESULT hr;
     533
     534    /*
     535     * Save pipeline state.
     536     */
     537    struct
     538    {
     539        D3D11_PRIMITIVE_TOPOLOGY    Topology;
     540        ID3D11InputLayout          *pInputLayout;
     541        ID3D11Buffer               *pConstantBuffer;
     542        ID3D11VertexShader         *pVertexShader;
     543        ID3D11ShaderResourceView   *pShaderResourceView;
     544        ID3D11PixelShader          *pPixelShader;
     545        ID3D11SamplerState         *pSamplerState;
     546        ID3D11RasterizerState      *pRasterizerState;
     547        ID3D11BlendState           *pBlendState;
     548        FLOAT                       BlendFactor[4];
     549        UINT                        SampleMask;
     550        ID3D11RenderTargetView     *apRenderTargetView[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
     551        ID3D11DepthStencilView     *pDepthStencilView;
     552        UINT                        NumViewports;
     553        D3D11_VIEWPORT              aViewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
     554    } SavedState;
     555
     556    pBlitter->pImmediateContext->IAGetPrimitiveTopology(&SavedState.Topology);
     557    pBlitter->pImmediateContext->IAGetInputLayout(&SavedState.pInputLayout);
     558    pBlitter->pImmediateContext->VSGetConstantBuffers(0, 1, &SavedState.pConstantBuffer);
     559    pBlitter->pImmediateContext->VSGetShader(&SavedState.pVertexShader, NULL, NULL);
     560    pBlitter->pImmediateContext->PSGetShaderResources(0, 1, &SavedState.pShaderResourceView);
     561    pBlitter->pImmediateContext->PSGetShader(&SavedState.pPixelShader, NULL, NULL);
     562    pBlitter->pImmediateContext->PSGetSamplers(0, 1, &SavedState.pSamplerState);
     563    pBlitter->pImmediateContext->RSGetState(&SavedState.pRasterizerState);
     564    pBlitter->pImmediateContext->OMGetBlendState(&SavedState.pBlendState, SavedState.BlendFactor, &SavedState.SampleMask);
     565    pBlitter->pImmediateContext->OMGetRenderTargets(RT_ELEMENTS(SavedState.apRenderTargetView), SavedState.apRenderTargetView, &SavedState.pDepthStencilView);
     566    SavedState.NumViewports = RT_ELEMENTS(SavedState.aViewport);
     567    pBlitter->pImmediateContext->RSGetViewports(&SavedState.NumViewports, &SavedState.aViewport[0]);
     568
     569    /*
     570     * Setup pipeline for the blitter.
     571     */
     572
     573    /* Render target is first.
     574     * If the source texture is bound as a render target, then this call will unbind it
     575     * and allow to use it as the shader resource.
     576     */
     577    pBlitter->pImmediateContext->OMSetRenderTargets(1, &pDstRenderTargetView, NULL);
     578
     579    /* Input assembler. */
     580    pBlitter->pImmediateContext->IASetInputLayout(NULL);
     581    pBlitter->pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
     582
     583    /* Constant buffer. */
     584    struct
     585    {
     586        float scaleX;
     587        float scaleY;
     588        float offsetX;
     589        float offsetY;
     590    } VSConstantBuffer;
     591    VSConstantBuffer.scaleX = (float)(rectDst.right - rectDst.left) / cDstWidth;
     592    VSConstantBuffer.scaleY = (float)(rectDst.bottom - rectDst.top) / cDstHeight;
     593    VSConstantBuffer.offsetX = (float)(rectDst.right + rectDst.left) / cDstWidth - 1.0f;
     594    VSConstantBuffer.offsetY = -((float)(rectDst.bottom + rectDst.top) / cDstHeight - 1.0f);
     595
     596    D3D11_SUBRESOURCE_DATA initialData;
     597    initialData.pSysMem          = &VSConstantBuffer;
     598    initialData.SysMemPitch      = sizeof(VSConstantBuffer);
     599    initialData.SysMemSlicePitch = sizeof(VSConstantBuffer);
     600
     601    D3D11_BUFFER_DESC bd;
     602    RT_ZERO(bd);
     603    bd.ByteWidth           = sizeof(VSConstantBuffer);
     604    bd.Usage               = D3D11_USAGE_IMMUTABLE;
     605    bd.BindFlags           = D3D11_BIND_CONSTANT_BUFFER;
     606
     607    ID3D11Buffer *pConstantBuffer;
     608    HTEST(pBlitter->pDevice->CreateBuffer(&bd, &initialData, &pConstantBuffer));
     609    pBlitter->pImmediateContext->VSSetConstantBuffers(0, 1, &pConstantBuffer);
     610    D3D_RELEASE(pConstantBuffer); /* xSSetConstantBuffers "will hold a reference to the interfaces passed in." */
     611
     612    /* Vertex shader. */
     613    pBlitter->pImmediateContext->VSSetShader(pBlitter->pVertexShader, NULL, 0);
     614
     615    /* Shader resource view. */
     616    pBlitter->pImmediateContext->PSSetShaderResources(0, 1, &pSrcShaderResourceView);
     617
     618    /* Pixel shader. */
     619    pBlitter->pImmediateContext->PSSetShader(pBlitter->pPixelShader, NULL, 0);
     620
     621    /* Sampler. */
     622    pBlitter->pImmediateContext->PSSetSamplers(0, 1, &pBlitter->pSamplerState);
     623
     624    /* Rasterizer. */
     625    pBlitter->pImmediateContext->RSSetState(pBlitter->pRasterizerState);
     626
     627    /* Blend state. */
     628    static FLOAT const BlendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
     629    pBlitter->pImmediateContext->OMSetBlendState(pBlitter->pBlendState, BlendFactor, 0xffffffff);
     630
     631    /* Viewport. */
     632    D3D11_VIEWPORT Viewport;
     633    Viewport.TopLeftX = 0;
     634    Viewport.TopLeftY = 0;
     635    Viewport.Width    = cDstWidth;
     636    Viewport.Height   = cDstHeight;
     637    Viewport.MinDepth = 0.0f;
     638    Viewport.MaxDepth = 1.0f;
     639    pBlitter->pImmediateContext->RSSetViewports(1, &Viewport);
     640
     641    /* Draw. */
     642    pBlitter->pImmediateContext->Draw(4, 0);
     643
     644    /*
     645     * Restore pipeline state.
     646     */
     647    pBlitter->pImmediateContext->IASetPrimitiveTopology(SavedState.Topology);
     648    pBlitter->pImmediateContext->IASetInputLayout(SavedState.pInputLayout);
     649    D3D_RELEASE(SavedState.pInputLayout);
     650    pBlitter->pImmediateContext->VSSetConstantBuffers(0, 1, &SavedState.pConstantBuffer);
     651    D3D_RELEASE(SavedState.pConstantBuffer);
     652    pBlitter->pImmediateContext->VSSetShader(SavedState.pVertexShader, NULL, 0);
     653    D3D_RELEASE(SavedState.pVertexShader);
     654    pBlitter->pImmediateContext->PSSetShaderResources(0, 1, &SavedState.pShaderResourceView);
     655    D3D_RELEASE(SavedState.pShaderResourceView);
     656    pBlitter->pImmediateContext->PSSetShader(SavedState.pPixelShader, NULL, 0);
     657    D3D_RELEASE(SavedState.pPixelShader);
     658    pBlitter->pImmediateContext->PSSetSamplers(0, 1, &SavedState.pSamplerState);
     659    D3D_RELEASE(SavedState.pSamplerState);
     660    pBlitter->pImmediateContext->RSSetState(SavedState.pRasterizerState);
     661    D3D_RELEASE(SavedState.pRasterizerState);
     662    pBlitter->pImmediateContext->OMSetBlendState(SavedState.pBlendState, SavedState.BlendFactor, SavedState.SampleMask);
     663    D3D_RELEASE(SavedState.pBlendState);
     664    pBlitter->pImmediateContext->OMSetRenderTargets(RT_ELEMENTS(SavedState.apRenderTargetView), SavedState.apRenderTargetView, SavedState.pDepthStencilView);
     665    D3D_RELEASE_ARRAY(RT_ELEMENTS(SavedState.apRenderTargetView), SavedState.apRenderTargetView);
     666    D3D_RELEASE(SavedState.pDepthStencilView);
     667    pBlitter->pImmediateContext->RSSetViewports(SavedState.NumViewports, &SavedState.aViewport[0]);
     668
     669    return S_OK;
     670}
     671
     672
    440673int D3D11Test::Run()
    441674{
     
    454687    int cFrames = 0;
    455688    float elapsed = 0;
     689
     690    D3D11BLITTER Blitter;
     691    BlitInit(&Blitter, mOutput.pDevice, mOutput.pImmediateContext);
    456692
    457693    do
     
    533769                         * Use the shared texture from the output device.
    534770                         */
    535                         mOutput.pImmediateContext->CopyResource(pBackBuffer, mOutput.pSharedTexture);
     771                        float cDstWidth = 800.0f;
     772                        float cDstHeight = 600.0f;
     773
     774                        D3D11_RECT rectDst;
     775                        rectDst.left   = 0;
     776                        rectDst.top    = 0;
     777                        rectDst.right  = 800;
     778                        rectDst.bottom = 600;
     779
     780                        ID3D11ShaderResourceView *pShaderResourceView = 0;
     781                        HTEST(Blitter.pDevice->CreateShaderResourceView(mOutput.pSharedTexture, NULL, &pShaderResourceView));
     782
     783                        ID3D11RenderTargetView *pRenderTargetView = 0;
     784                        HTEST(Blitter.pDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView));
     785
     786                        BlitFromTexture(&Blitter, pRenderTargetView, cDstWidth, cDstHeight, rectDst, pShaderResourceView);
     787
     788                        D3D_RELEASE(pRenderTargetView);
     789                        D3D_RELEASE(pShaderResourceView);
    536790                    }
    537791                    else
     
    571825    } while (msg.message != WM_QUIT);
    572826
     827    BlitRelease(&Blitter);
    573828    return msg.wParam;
    574829}
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d11render.h

    r95081 r95152  
    3434        (ptr) = 0;            \
    3535    }                         \
     36} while (0)
     37
     38#define D3D_RELEASE_ARRAY(a_Count, a_papArray) do { \
     39    for (uint32_t i = 0; i < (a_Count); ++i) \
     40        D3D_RELEASE((a_papArray)[i]); \
    3641} while (0)
    3742
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette