blob: ca0d8a8b11a2e0129099c9538c29688004f2ff4b [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
Nicolas Capensee16f0d2015-07-16 17:40:10 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
Nicolas Capensee16f0d2015-07-16 17:40:10 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
Nicolas Capensee16f0d2015-07-16 17:40:10 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
Nicolas Capensee16f0d2015-07-16 17:40:10 -040014
15#include "Direct3DVolume9.hpp"
16
17#include "Direct3DDevice9.hpp"
18#include "Direct3DResource9.hpp"
19#include "Direct3DVolumeTexture9.hpp"
20#include "Direct3DSurface9.hpp"
21#include "Resource.hpp"
22#include "Debug.hpp"
23
24#include <assert.h>
25
26namespace D3D9
27{
28 bool isLockable(D3DPOOL pool, unsigned long usage)
29 {
30 return (pool != D3DPOOL_DEFAULT) || (usage & D3DUSAGE_DYNAMIC);
31 }
32
Alexis Hetu9c6d5222016-11-29 17:02:14 -050033 Direct3DVolume9::Direct3DVolume9(Direct3DDevice9 *device, Direct3DVolumeTexture9 *container, int width, int height, int depth, D3DFORMAT format, D3DPOOL pool, unsigned long usage)
Nicolas Capensbfa23b32017-12-11 10:06:37 -050034 : device(device), Surface(container->getResource(), width, height, depth, 0, 1, translateFormat(format), isLockable(pool, usage), false), container(container), width(width), height(height), depth(depth), format(format), pool(pool), lockable(isLockable(pool, usage)), usage(usage)
Nicolas Capensee16f0d2015-07-16 17:40:10 -040035 {
36 resource = new Direct3DResource9(device, D3DRTYPE_VOLUME, pool, memoryUsage(width, height, depth, format));
37 resource->bind();
38 }
39
40 Direct3DVolume9::~Direct3DVolume9()
41 {
42 resource->unbind();
43 }
44
Nicolas Capens3b9e1ea2017-06-12 12:43:48 -040045 void *Direct3DVolume9::lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)
46 {
47 return Surface::lockInternal(x, y, z, lock, client);
48 }
49
50 void Direct3DVolume9::unlockInternal()
51 {
52 Surface::unlockInternal();
53 }
54
Nicolas Capensee16f0d2015-07-16 17:40:10 -040055 long __stdcall Direct3DVolume9::QueryInterface(const IID &iid, void **object)
56 {
57 CriticalSection cs(device);
58
59 TRACE("");
60
61 if(iid == IID_IDirect3DVolume9 ||
62 iid == IID_IUnknown)
63 {
64 AddRef();
65 *object = this;
66
67 return S_OK;
68 }
69
70 *object = 0;
71
72 return NOINTERFACE(iid);
73 }
74
75 unsigned long __stdcall Direct3DVolume9::AddRef()
76 {
77 TRACE("");
78
79 return container->AddRef();
80 }
81
82 unsigned long __stdcall Direct3DVolume9::Release()
83 {
84 TRACE("");
85
86 return container->Release();
87 }
88
89 long Direct3DVolume9::FreePrivateData(const GUID &guid)
90 {
91 CriticalSection cs(device);
92
93 TRACE("");
94
95 return resource->FreePrivateData(guid);
96 }
97
98 long Direct3DVolume9::GetContainer(const IID &iid, void **container)
99 {
100 CriticalSection cs(device);
101
102 TRACE("");
103
104 if(!container)
105 {
106 return INVALIDCALL();
107 }
108
109 long result = this->container->QueryInterface(iid, container);
110
111 if(result == S_OK)
112 {
113 return D3D_OK;
114 }
115
116 return INVALIDCALL();
117 }
118
119 long Direct3DVolume9::GetDesc(D3DVOLUME_DESC *description)
120 {
121 CriticalSection cs(device);
122
123 TRACE("");
124
125 if(!description)
126 {
127 return INVALIDCALL();
128 }
129
130 description->Format = format;
131 description->Type = D3DRTYPE_VOLUME;
132 description->Usage = usage;
133 description->Pool = pool;
134 description->Width = width;
135 description->Height = height;
136 description->Depth = depth;
137
138 return D3D_OK;
139 }
140
141 long Direct3DVolume9::GetDevice(IDirect3DDevice9 **device)
142 {
143 CriticalSection cs(this->device);
144
145 TRACE("");
146
147 return resource->GetDevice(device);
148 }
149
150 long Direct3DVolume9::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
151 {
152 CriticalSection cs(device);
153
154 TRACE("");
155
156 return resource->GetPrivateData(guid, data, size);
157 }
158
159 long Direct3DVolume9::LockBox(D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags)
160 {
161 CriticalSection cs(device);
162
163 TRACE("");
164
165 if(!lockedVolume)
166 {
167 return INVALIDCALL();
168 }
169
170 lockedVolume->RowPitch = 0;
171 lockedVolume->SlicePitch = 0;
172 lockedVolume->pBits = 0;
173
174 if(!lockable)
175 {
176 return INVALIDCALL();
177 }
178
179 lockedVolume->RowPitch = getExternalPitchB();
180 lockedVolume->SlicePitch = getExternalSliceB();
181
182 sw::Lock lock = sw::LOCK_READWRITE;
183
184 if(flags & D3DLOCK_DISCARD)
185 {
186 lock = sw::LOCK_DISCARD;
187 }
188
189 if(flags & D3DLOCK_READONLY)
190 {
191 lock = sw::LOCK_READONLY;
192 }
193
194 if(box)
195 {
196 lockedVolume->pBits = lockExternal(box->Left, box->Top, box->Front, lock, sw::PUBLIC);
197 }
198 else
199 {
200 lockedVolume->pBits = lockExternal(0, 0, 0, lock, sw::PUBLIC);
201 }
202
203 return D3D_OK;
204 }
205
206 long Direct3DVolume9::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
207 {
208 CriticalSection cs(device);
209
210 TRACE("");
211
212 return resource->SetPrivateData(guid, data, size, flags);
213 }
214
215 long Direct3DVolume9::UnlockBox()
216 {
217 CriticalSection cs(device);
218
219 TRACE("");
220
221 unlockExternal();
222
223 return D3D_OK;
224 }
225
226 sw::Format Direct3DVolume9::translateFormat(D3DFORMAT format)
227 {
228 return Direct3DSurface9::translateFormat(format);
229 }
230
231 unsigned int Direct3DVolume9::memoryUsage(int width, int height, int depth, D3DFORMAT format)
232 {
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500233 return Surface::size(width, height, depth, 0, 1, translateFormat(format));
Nicolas Capensee16f0d2015-07-16 17:40:10 -0400234 }
235}