Skip to content

Commit f052689

Browse files
committed
apps/d3d11: Port map_no_overwrite to D3D11.
1 parent 25e463d commit f052689

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

apps/d3d11/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set (api d3d11)
1111

1212
set (targets
1313
tri
14+
map_no_overwrite
1415
)
1516

1617
foreach (target ${targets})

apps/d3d11/map_no_overwrite.cpp

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**************************************************************************
2+
*
3+
* Copyright 2014 VMware, Inc.
4+
* Copyright 2012 Jose Fonseca
5+
* All Rights Reserved.
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
**************************************************************************/
26+
27+
28+
/*
29+
* Test case for usage of D3D11_MAP_WRITE_DISCARD with D3D11_MAP_WRITE_NO_OVERWRITE
30+
* http://msdn.microsoft.com/en-us/library/windows/desktop/bb205318.aspx#NO_OVERWRITE_DETAILS
31+
*
32+
*/
33+
#include <stdio.h>
34+
#include <stddef.h>
35+
36+
#include <initguid.h>
37+
#include <windows.h>
38+
39+
#include "compat.h"
40+
41+
#include <d3d11.h>
42+
43+
#include "com_ptr.hpp"
44+
45+
46+
int
47+
main(int argc, char *argv[])
48+
{
49+
HRESULT hr;
50+
51+
UINT Flags = 0;
52+
if (LoadLibraryA("d3d11sdklayers")) {
53+
Flags |= D3D11_CREATE_DEVICE_DEBUG;
54+
}
55+
56+
static const D3D_FEATURE_LEVEL FeatureLevels[] = {
57+
D3D_FEATURE_LEVEL_11_0,
58+
D3D_FEATURE_LEVEL_10_1,
59+
D3D_FEATURE_LEVEL_10_0
60+
};
61+
62+
com_ptr<ID3D11Device> pDevice;
63+
com_ptr<ID3D11DeviceContext> pDeviceContext;
64+
hr = D3D11CreateDevice(NULL, /* pAdapter */
65+
D3D_DRIVER_TYPE_HARDWARE,
66+
NULL, /* Software */
67+
Flags,
68+
FeatureLevels,
69+
sizeof FeatureLevels / sizeof FeatureLevels[0],
70+
D3D11_SDK_VERSION,
71+
&pDevice,
72+
NULL, /* pFeatureLevel */
73+
&pDeviceContext);
74+
if (FAILED(hr)) {
75+
return 1;
76+
}
77+
78+
UINT NumSegments = 8;
79+
UINT SegmentSize = 512;
80+
81+
D3D11_BUFFER_DESC BufferDesc;
82+
ZeroMemory(&BufferDesc, sizeof BufferDesc);
83+
BufferDesc.Usage = D3D11_USAGE_DYNAMIC;
84+
BufferDesc.ByteWidth = NumSegments * SegmentSize;
85+
BufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
86+
BufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
87+
BufferDesc.MiscFlags = 0;
88+
89+
com_ptr<ID3D11Buffer> pVertexBuffer;
90+
hr = pDevice->CreateBuffer(&BufferDesc, NULL, &pVertexBuffer);
91+
if (FAILED(hr)) {
92+
return 1;
93+
}
94+
95+
for (UINT j = 0; j < NumSegments; ++j) {
96+
D3D11_MAP MapType = j == 0 ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE;
97+
D3D11_MAPPED_SUBRESOURCE MappedResource;
98+
hr = pDeviceContext->Map(pVertexBuffer, 0, MapType, 0, &MappedResource);
99+
if (FAILED(hr)) {
100+
return 1;
101+
}
102+
103+
BYTE *pMap = (BYTE *)MappedResource.pData;
104+
105+
int c = (j % 255) + 1;
106+
memset(pMap + j*SegmentSize, c, SegmentSize);
107+
108+
pDeviceContext->Unmap(pVertexBuffer, 0);
109+
}
110+
111+
return 0;
112+
}
113+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
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 = &<pDevice>, pFeatureLevel = NULL, ppImmediateContext = &<pDeviceContext>) = S_OK
2+
ID3D11Device::CreateBuffer(this = <pDevice>, pDesc = &{ByteWidth = 4096, Usage = D3D11_USAGE_DYNAMIC, BindFlags = D3D11_BIND_VERTEX_BUFFER, CPUAccessFlags = D3D11_CPU_ACCESS_WRITE, MiscFlags = 0x0, StructureByteStride = 0}, pInitialData = NULL, ppBuffer = &<pVertexBuffer>) = S_OK
3+
ID3D11DeviceContext::Map(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0, MapType = D3D11_MAP_WRITE_DISCARD, MapFlags = 0x0, pMappedResource = &{pData = <pMap>, RowPitch = 4096, DepthPitch = 4096}) = S_OK
4+
memcpy(dest = <pMap>, src = blob(4096), n = 4096)
5+
ID3D11DeviceContext::Unmap(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0)
6+
ID3D11DeviceContext::Map(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = <pMap>, RowPitch = 4096, DepthPitch = 4096}) = S_OK
7+
memcpy(dest = <pMap>, src = blob(4096), n = 4096)
8+
ID3D11DeviceContext::Unmap(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0)
9+
ID3D11DeviceContext::Map(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = <pMap>, RowPitch = 4096, DepthPitch = 4096}) = S_OK
10+
memcpy(dest = <pMap>, src = blob(4096), n = 4096)
11+
ID3D11DeviceContext::Unmap(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0)
12+
ID3D11DeviceContext::Map(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = <pMap>, RowPitch = 4096, DepthPitch = 4096}) = S_OK
13+
memcpy(dest = <pMap>, src = blob(4096), n = 4096)
14+
ID3D11DeviceContext::Unmap(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0)
15+
ID3D11DeviceContext::Map(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = <pMap>, RowPitch = 4096, DepthPitch = 4096}) = S_OK
16+
memcpy(dest = <pMap>, src = blob(4096), n = 4096)
17+
ID3D11DeviceContext::Unmap(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0)
18+
ID3D11DeviceContext::Map(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = <pMap>, RowPitch = 4096, DepthPitch = 4096}) = S_OK
19+
memcpy(dest = <pMap>, src = blob(4096), n = 4096)
20+
ID3D11DeviceContext::Unmap(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0)
21+
ID3D11DeviceContext::Map(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = <pMap>, RowPitch = 4096, DepthPitch = 4096}) = S_OK
22+
memcpy(dest = <pMap>, src = blob(4096), n = 4096)
23+
ID3D11DeviceContext::Unmap(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0)
24+
ID3D11DeviceContext::Map(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0, MapType = D3D11_MAP_WRITE_NO_OVERWRITE, MapFlags = 0x0, pMappedResource = &{pData = <pMap>, RowPitch = 4096, DepthPitch = 4096}) = S_OK
25+
memcpy(dest = <pMap>, src = blob(4096), n = 4096)
26+
ID3D11DeviceContext::Unmap(this = <pDeviceContext>, pResource = <pVertexBuffer>, Subresource = 0)
27+
ID3D11Buffer::Release(this = <pVertexBuffer>) = 0
28+
ID3D11DeviceContext::Release(this = <pDeviceContext>) = 0
29+
ID3D11Device::Release(this = <pDevice>) = 0

0 commit comments

Comments
 (0)