From: Jose Fonseca Date: Wed, 5 May 2021 13:51:34 +0000 (+0100) Subject: d3d10sw: Add a sanity test. X-Git-Tag: upstream/21.2.3~3226 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bd16133572292f61ab5c808431ff9fa0c878fc29;p=platform%2Fupstream%2Fmesa.git d3d10sw: Add a sanity test. Reviewed-by: Roland Scheidegger Acked-by: Jesse Natalie Part-of: --- diff --git a/src/gallium/targets/d3d10sw/meson.build b/src/gallium/targets/d3d10sw/meson.build index 4e9a8dc..fe8632d 100644 --- a/src/gallium/targets/d3d10sw/meson.build +++ b/src/gallium/targets/d3d10sw/meson.build @@ -43,3 +43,17 @@ libd3d10sw = shared_library( name_prefix : '', # otherwise mingw will create libd3d10sw.dll install : true, ) + +if with_tests + test( + 'd3d10sw', + executable( + 'test_d3d10sw', + files('tests/tri.cpp'), + cpp_args : [cpp_msvc_compat_args], + dependencies : [cpp.find_library('d3d11')], + link_with : [libd3d10sw], + ), + suite : ['d3d10sw'], + ) +endif diff --git a/src/gallium/targets/d3d10sw/tests/tri.cpp b/src/gallium/targets/d3d10sw/tests/tri.cpp new file mode 100644 index 0000000..2dab882 --- /dev/null +++ b/src/gallium/targets/d3d10sw/tests/tri.cpp @@ -0,0 +1,294 @@ +/************************************************************************** + * + * Copyright 2012-2021 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + **************************************************************************/ + + +#include +#include +#include + +#include +#include + +#include + +#include + +using Microsoft::WRL::ComPtr; + +#include "tri_vs_4_0.h" +#include "tri_ps_4_0.h" + + +int +main(int argc, char *argv[]) +{ + HRESULT hr; + + HINSTANCE hInstance = GetModuleHandle(nullptr); + + WNDCLASSEX wc = { + sizeof(WNDCLASSEX), + CS_CLASSDC, + DefWindowProc, + 0, + 0, + hInstance, + nullptr, + nullptr, + nullptr, + nullptr, + "tri", + nullptr + }; + RegisterClassEx(&wc); + + const int WindowWidth = 250; + const int WindowHeight = 250; + + DWORD dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW | WS_VISIBLE; + + RECT rect = {0, 0, WindowWidth, WindowHeight}; + AdjustWindowRect(&rect, dwStyle, FALSE); + + HWND hWnd = CreateWindow(wc.lpszClassName, + "Simple example using DirectX10", + dwStyle, + CW_USEDEFAULT, CW_USEDEFAULT, + rect.right - rect.left, + rect.bottom - rect.top, + nullptr, + nullptr, + hInstance, + nullptr); + if (!hWnd) { + return EXIT_FAILURE; + } + + UINT Flags = 0; + hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_NULL, 0, D3D11_CREATE_DEVICE_DEBUG, nullptr, 0, D3D11_SDK_VERSION, nullptr, nullptr, nullptr); + if (SUCCEEDED(hr)) { + Flags |= D3D11_CREATE_DEVICE_DEBUG; + } + + static const D3D_FEATURE_LEVEL FeatureLevels[] = { + D3D_FEATURE_LEVEL_10_0 + }; + + HMODULE hSoftware = LoadLibraryA("d3d10sw.dll"); + if (!hSoftware) { + return EXIT_FAILURE; + } + + DXGI_SWAP_CHAIN_DESC SwapChainDesc; + ZeroMemory(&SwapChainDesc, sizeof SwapChainDesc); + SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;; + SwapChainDesc.BufferDesc.RefreshRate.Numerator = 60; + SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1; + SwapChainDesc.SampleDesc.Quality = 0; + SwapChainDesc.SampleDesc.Count = 1; + SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + SwapChainDesc.BufferCount = 2; + SwapChainDesc.OutputWindow = hWnd; + SwapChainDesc.Windowed = true; + SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; + + ComPtr pDevice; + ComPtr pDeviceContext; + ComPtr pSwapChain; + hr = D3D11CreateDeviceAndSwapChain(nullptr, + D3D_DRIVER_TYPE_SOFTWARE, + hSoftware, + Flags, + FeatureLevels, + _countof(FeatureLevels), + D3D11_SDK_VERSION, + &SwapChainDesc, + &pSwapChain, + &pDevice, + nullptr, /* pFeatureLevel */ + &pDeviceContext); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + + ComPtr pDXGIDevice; + hr = pDevice->QueryInterface(IID_IDXGIDevice, (void **)&pDXGIDevice); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + + ComPtr pAdapter; + hr = pDXGIDevice->GetAdapter(&pAdapter); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + + DXGI_ADAPTER_DESC Desc; + hr = pAdapter->GetDesc(&Desc); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + + printf("using %S\n", Desc.Description); + + ComPtr pBackBuffer; + hr = pSwapChain->GetBuffer(0, IID_ID3D11Texture2D, (void **)&pBackBuffer); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + + D3D11_RENDER_TARGET_VIEW_DESC RenderTargetViewDesc; + ZeroMemory(&RenderTargetViewDesc, sizeof RenderTargetViewDesc); + RenderTargetViewDesc.Format = SwapChainDesc.BufferDesc.Format; + RenderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + RenderTargetViewDesc.Texture2D.MipSlice = 0; + + ComPtr pRenderTargetView; + hr = pDevice->CreateRenderTargetView(pBackBuffer.Get(), &RenderTargetViewDesc, &pRenderTargetView); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + + pDeviceContext->OMSetRenderTargets(1, pRenderTargetView.GetAddressOf(), nullptr); + + + const float clearColor[4] = { 0.3f, 0.1f, 0.3f, 1.0f }; + pDeviceContext->ClearRenderTargetView(pRenderTargetView.Get(), clearColor); + + ComPtr pVertexShader; + hr = pDevice->CreateVertexShader(g_VS, sizeof g_VS, nullptr, &pVertexShader); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + + struct Vertex { + float position[4]; + float color[4]; + }; + + static const D3D11_INPUT_ELEMENT_DESC InputElementDescs[] = { + { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(Vertex, position), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(Vertex, color), D3D11_INPUT_PER_VERTEX_DATA, 0 } + }; + + ComPtr pVertexLayout; + hr = pDevice->CreateInputLayout(InputElementDescs, + _countof(InputElementDescs), + g_VS, sizeof g_VS, + &pVertexLayout); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + + pDeviceContext->IASetInputLayout(pVertexLayout.Get()); + + ComPtr pPixelShader; + hr = pDevice->CreatePixelShader(g_PS, sizeof g_PS, nullptr, &pPixelShader); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + + pDeviceContext->VSSetShader(pVertexShader.Get(), nullptr, 0); + pDeviceContext->PSSetShader(pPixelShader.Get(), nullptr, 0); + + static const Vertex vertices[] = { + { { -0.9f, -0.9f, 0.5f, 1.0f}, { 0.8f, 0.0f, 0.0f, 0.1f } }, + { { 0.9f, -0.9f, 0.5f, 1.0f}, { 0.0f, 0.9f, 0.0f, 0.1f } }, + { { 0.0f, 0.9f, 0.5f, 1.0f}, { 0.0f, 0.0f, 0.7f, 0.1f } }, + }; + + D3D11_BUFFER_DESC BufferDesc; + ZeroMemory(&BufferDesc, sizeof BufferDesc); + BufferDesc.Usage = D3D11_USAGE_DYNAMIC; + BufferDesc.ByteWidth = sizeof vertices; + BufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + BufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + BufferDesc.MiscFlags = 0; + + D3D11_SUBRESOURCE_DATA BufferData; + BufferData.pSysMem = vertices; + BufferData.SysMemPitch = 0; + BufferData.SysMemSlicePitch = 0; + + ComPtr pVertexBuffer; + hr = pDevice->CreateBuffer(&BufferDesc, &BufferData, &pVertexBuffer); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + + UINT Stride = sizeof(Vertex); + UINT Offset = 0; + pDeviceContext->IASetVertexBuffers(0, 1, pVertexBuffer.GetAddressOf(), &Stride, &Offset); + + D3D11_VIEWPORT ViewPort; + ViewPort.TopLeftX = 0; + ViewPort.TopLeftY = 0; + ViewPort.Width = WindowWidth; + ViewPort.Height = WindowHeight; + ViewPort.MinDepth = 0.0f; + ViewPort.MaxDepth = 1.0f; + pDeviceContext->RSSetViewports(1, &ViewPort); + + D3D11_RASTERIZER_DESC RasterizerDesc; + ZeroMemory(&RasterizerDesc, sizeof RasterizerDesc); + RasterizerDesc.CullMode = D3D11_CULL_NONE; + RasterizerDesc.FillMode = D3D11_FILL_SOLID; + RasterizerDesc.FrontCounterClockwise = true; + RasterizerDesc.DepthClipEnable = true; + ComPtr pRasterizerState; + hr = pDevice->CreateRasterizerState(&RasterizerDesc, &pRasterizerState); + if (FAILED(hr)) { + return EXIT_FAILURE; + } + pDeviceContext->RSSetState(pRasterizerState.Get()); + + pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + + pDeviceContext->Draw(_countof(vertices), 0); + + pSwapChain->Present(0, 0); + + Sleep(1000); + + ID3D11Buffer *pNullBuffer = nullptr; + UINT NullStride = 0; + UINT NullOffset = 0; + pDeviceContext->IASetVertexBuffers(0, 1, &pNullBuffer, &NullStride, &NullOffset); + + pDeviceContext->OMSetRenderTargets(0, nullptr, nullptr); + + pDeviceContext->IASetInputLayout(nullptr); + + pDeviceContext->VSSetShader(nullptr, nullptr, 0); + + pDeviceContext->PSSetShader(nullptr, nullptr, 0); + + pDeviceContext->RSSetState(nullptr); + + DestroyWindow(hWnd); + + return EXIT_SUCCESS; +} + diff --git a/src/gallium/targets/d3d10sw/tests/tri_ps_4_0.h b/src/gallium/targets/d3d10sw/tests/tri_ps_4_0.h new file mode 100755 index 0000000..27583cb --- /dev/null +++ b/src/gallium/targets/d3d10sw/tests/tri_ps_4_0.h @@ -0,0 +1,76 @@ +#if 0 +// +// Generated by Microsoft (R) D3D Shader Disassembler +// +// +// fxc /nologo /Qstrip_reflect /T ps_4_0 /E PS /Fh +// Z:/projects/apitrace/tests/apps/d3dcommon/tri_ps_4_0.h +// Z:/projects/apitrace/tests/apps/d3dcommon/tri.fx +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// COLOR 0 xyzw 1 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v1.xyzw +dcl_output o0.xyzw +mov o0.xyzw, v1.xyzw +ret +// Approximately 0 instruction slots used +#endif + +const BYTE g_PS[] = +{ + 68, 88, 66, 67, 89, 62, + 128, 137, 52, 137, 121, 63, + 223, 129, 145, 249, 18, 101, + 85, 245, 1, 0, 0, 0, + 244, 0, 0, 0, 3, 0, + 0, 0, 44, 0, 0, 0, + 128, 0, 0, 0, 180, 0, + 0, 0, 73, 83, 71, 78, + 76, 0, 0, 0, 2, 0, + 0, 0, 8, 0, 0, 0, + 56, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 68, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 67, 79, 76, 79, 82, 0, + 171, 171, 79, 83, 71, 78, + 44, 0, 0, 0, 1, 0, + 0, 0, 8, 0, 0, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 84, 97, 114, + 103, 101, 116, 0, 171, 171, + 83, 72, 68, 82, 56, 0, + 0, 0, 64, 0, 0, 0, + 14, 0, 0, 0, 98, 16, + 0, 3, 242, 16, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 242, 32, 16, 0, + 0, 0, 0, 0, 70, 30, + 16, 0, 1, 0, 0, 0, + 62, 0, 0, 1 +}; diff --git a/src/gallium/targets/d3d10sw/tests/tri_vs_4_0.h b/src/gallium/targets/d3d10sw/tests/tri_vs_4_0.h new file mode 100755 index 0000000..c338838 --- /dev/null +++ b/src/gallium/targets/d3d10sw/tests/tri_vs_4_0.h @@ -0,0 +1,93 @@ +#if 0 +// +// Generated by Microsoft (R) D3D Shader Disassembler +// +// +// fxc /nologo /Qstrip_reflect /T vs_4_0 /E VS /Fh +// Z:/projects/apitrace/tests/apps/d3dcommon/tri_vs_4_0.h +// Z:/projects/apitrace/tests/apps/d3dcommon/tri.fx +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// COLOR 0 xyzw 1 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float xyzw +// COLOR 0 xyzw 1 NONE float xyzw +// +vs_4_0 +dcl_input v0.xyzw +dcl_input v1.xyzw +dcl_output_siv o0.xyzw, position +dcl_output o1.xyzw +mov o0.xyzw, v0.xyzw +mov o1.xyzw, v1.xyzw +ret +// Approximately 0 instruction slots used +#endif + +const BYTE g_VS[] = +{ + 68, 88, 66, 67, 97, 176, + 115, 92, 95, 18, 113, 92, + 95, 52, 139, 63, 171, 185, + 4, 206, 1, 0, 0, 0, + 64, 1, 0, 0, 3, 0, + 0, 0, 44, 0, 0, 0, + 124, 0, 0, 0, 208, 0, + 0, 0, 73, 83, 71, 78, + 72, 0, 0, 0, 2, 0, + 0, 0, 8, 0, 0, 0, + 56, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 15, 0, 0, + 65, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 15, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 76, 0, 0, 0, + 2, 0, 0, 0, 8, 0, + 0, 0, 56, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 68, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 80, + 79, 83, 73, 84, 73, 79, + 78, 0, 67, 79, 76, 79, + 82, 0, 171, 171, 83, 72, + 68, 82, 104, 0, 0, 0, + 64, 0, 1, 0, 26, 0, + 0, 0, 95, 0, 0, 3, + 242, 16, 16, 0, 0, 0, + 0, 0, 95, 0, 0, 3, + 242, 16, 16, 0, 1, 0, + 0, 0, 103, 0, 0, 4, + 242, 32, 16, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 1, 0, 0, 0, + 54, 0, 0, 5, 242, 32, + 16, 0, 0, 0, 0, 0, + 70, 30, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 242, 32, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 1, 0, 0, 0, 62, 0, + 0, 1 +};