From f0526891292ea5140c3a3addf455c7ba9a2eed8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 21 Aug 2014 15:33:34 +0100 Subject: [PATCH] apps/d3d11: Port map_no_overwrite to D3D11. --- apps/d3d11/CMakeLists.txt | 1 + apps/d3d11/map_no_overwrite.cpp | 113 ++++++++++++++++++++++++++++ apps/d3d11/map_no_overwrite.ref.txt | 29 +++++++ 3 files changed, 143 insertions(+) create mode 100644 apps/d3d11/map_no_overwrite.cpp create mode 100644 apps/d3d11/map_no_overwrite.ref.txt diff --git a/apps/d3d11/CMakeLists.txt b/apps/d3d11/CMakeLists.txt index 5dc68d8..a2b0bc1 100644 --- a/apps/d3d11/CMakeLists.txt +++ b/apps/d3d11/CMakeLists.txt @@ -11,6 +11,7 @@ set (api d3d11) set (targets tri + map_no_overwrite ) foreach (target ${targets}) diff --git a/apps/d3d11/map_no_overwrite.cpp b/apps/d3d11/map_no_overwrite.cpp new file mode 100644 index 0000000..d15946e --- /dev/null +++ b/apps/d3d11/map_no_overwrite.cpp @@ -0,0 +1,113 @@ +/************************************************************************** + * + * Copyright 2014 VMware, Inc. + * Copyright 2012 Jose Fonseca + * 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. + * + **************************************************************************/ + + +/* + * Test case for usage of D3D11_MAP_WRITE_DISCARD with D3D11_MAP_WRITE_NO_OVERWRITE + * http://msdn.microsoft.com/en-us/library/windows/desktop/bb205318.aspx#NO_OVERWRITE_DETAILS + * + */ +#include +#include + +#include +#include + +#include "compat.h" + +#include + +#include "com_ptr.hpp" + + +int +main(int argc, char *argv[]) +{ + HRESULT hr; + + UINT Flags = 0; + if (LoadLibraryA("d3d11sdklayers")) { + Flags |= D3D11_CREATE_DEVICE_DEBUG; + } + + static const D3D_FEATURE_LEVEL FeatureLevels[] = { + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0 + }; + + com_ptr pDevice; + com_ptr pDeviceContext; + hr = D3D11CreateDevice(NULL, /* pAdapter */ + D3D_DRIVER_TYPE_HARDWARE, + NULL, /* Software */ + Flags, + FeatureLevels, + sizeof FeatureLevels / sizeof FeatureLevels[0], + D3D11_SDK_VERSION, + &pDevice, + NULL, /* pFeatureLevel */ + &pDeviceContext); + if (FAILED(hr)) { + return 1; + } + + UINT NumSegments = 8; + UINT SegmentSize = 512; + + D3D11_BUFFER_DESC BufferDesc; + ZeroMemory(&BufferDesc, sizeof BufferDesc); + BufferDesc.Usage = D3D11_USAGE_DYNAMIC; + BufferDesc.ByteWidth = NumSegments * SegmentSize; + BufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + BufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + BufferDesc.MiscFlags = 0; + + com_ptr pVertexBuffer; + hr = pDevice->CreateBuffer(&BufferDesc, NULL, &pVertexBuffer); + if (FAILED(hr)) { + return 1; + } + + for (UINT j = 0; j < NumSegments; ++j) { + D3D11_MAP MapType = j == 0 ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE; + D3D11_MAPPED_SUBRESOURCE MappedResource; + hr = pDeviceContext->Map(pVertexBuffer, 0, MapType, 0, &MappedResource); + if (FAILED(hr)) { + return 1; + } + + BYTE *pMap = (BYTE *)MappedResource.pData; + + int c = (j % 255) + 1; + memset(pMap + j*SegmentSize, c, SegmentSize); + + pDeviceContext->Unmap(pVertexBuffer, 0); + } + + return 0; +} + diff --git a/apps/d3d11/map_no_overwrite.ref.txt b/apps/d3d11/map_no_overwrite.ref.txt new file mode 100644 index 0000000..cc52aab --- /dev/null +++ b/apps/d3d11/map_no_overwrite.ref.txt @@ -0,0 +1,29 @@ +D3D11CreateDevice(pAdapter = NULL, DriverType = D3D_DRIVER_TYPE_HARDWARE, Software = NULL, Flags = <>, pFeatureLevels = {D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0}, FeatureLevels = 3, SDKVersion = 7, ppDevice = &, pFeatureLevel = NULL, ppImmediateContext = &) = S_OK +ID3D11Device::CreateBuffer(this = , pDesc = &{ByteWidth = 4096, Usage = D3D11_USAGE_DYNAMIC, BindFlags = D3D11_BIND_VERTEX_BUFFER, CPUAccessFlags = D3D11_CPU_ACCESS_WRITE, MiscFlags = 0x0, StructureByteStride = 0}, pInitialData = NULL, ppBuffer = &) = S_OK +ID3D11DeviceContext::Map(this = , pResource = , Subresource = 0, MapType = D3D11_MAP_WRITE_DISCARD, MapFlags = 0x0, pMappedResource = &{pData = , RowPitch = 4096, DepthPitch = 4096}) = S_OK +memcpy(dest = , src = blob(4096), n = 4096) +ID3D11DeviceContext::Unmap(this = , pResource = , Subresource = 0) +ID3D11DeviceContext::Map(this = , pResource = , Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = , RowPitch = 4096, DepthPitch = 4096}) = S_OK +memcpy(dest = , src = blob(4096), n = 4096) +ID3D11DeviceContext::Unmap(this = , pResource = , Subresource = 0) +ID3D11DeviceContext::Map(this = , pResource = , Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = , RowPitch = 4096, DepthPitch = 4096}) = S_OK +memcpy(dest = , src = blob(4096), n = 4096) +ID3D11DeviceContext::Unmap(this = , pResource = , Subresource = 0) +ID3D11DeviceContext::Map(this = , pResource = , Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = , RowPitch = 4096, DepthPitch = 4096}) = S_OK +memcpy(dest = , src = blob(4096), n = 4096) +ID3D11DeviceContext::Unmap(this = , pResource = , Subresource = 0) +ID3D11DeviceContext::Map(this = , pResource = , Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = , RowPitch = 4096, DepthPitch = 4096}) = S_OK +memcpy(dest = , src = blob(4096), n = 4096) +ID3D11DeviceContext::Unmap(this = , pResource = , Subresource = 0) +ID3D11DeviceContext::Map(this = , pResource = , Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = , RowPitch = 4096, DepthPitch = 4096}) = S_OK +memcpy(dest = , src = blob(4096), n = 4096) +ID3D11DeviceContext::Unmap(this = , pResource = , Subresource = 0) +ID3D11DeviceContext::Map(this = , pResource = , Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = , RowPitch = 4096, DepthPitch = 4096}) = S_OK +memcpy(dest = , src = blob(4096), n = 4096) +ID3D11DeviceContext::Unmap(this = , pResource = , Subresource = 0) +ID3D11DeviceContext::Map(this = , pResource = , Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = , RowPitch = 4096, DepthPitch = 4096}) = S_OK +memcpy(dest = , src = blob(4096), n = 4096) +ID3D11DeviceContext::Unmap(this = , pResource = , Subresource = 0) +ID3D11Buffer::Release(this = ) = 0 +ID3D11DeviceContext::Release(this = ) = 0 +ID3D11Device::Release(this = ) = 0