1fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt/*
2fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt *
4fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * Permission is hereby granted, free of charge, to any person obtaining a
5fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * copy of this software and associated documentation files (the "Software"),
6fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * to deal in the Software without restriction, including without limitation
7fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * on the rights to use, copy, modify, merge, publish, distribute, sub
8fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * license, and/or sell copies of the Software, and to permit persons to whom
9fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * the Software is furnished to do so, subject to the following conditions:
10fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt *
11fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * The above copyright notice and this permission notice (including the next
12fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * paragraph) shall be included in all copies or substantial portions of the
13fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * Software.
14fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt *
15fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
23fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "device9.h"
24fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "volume9.h"
25fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "basetexture9.h" /* for marking dirty */
263f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy#include "volumetexture9.h"
27fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "nine_helpers.h"
28fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "nine_pipe.h"
29fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "nine_dump.h"
30fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
31fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "util/u_format.h"
32fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "util/u_surface.h"
33fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
34fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#define DBG_CHANNEL DBG_VOLUME
35fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
36fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
37fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstatic HRESULT
38fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_AllocateData( struct NineVolume9 *This )
39fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
40fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    unsigned size = This->layer_stride * This->desc.Depth;
41fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
42fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    DBG("(%p(This=%p),level=%u) Allocating 0x%x bytes of system memory.\n",
43fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        This->base.container, This, This->level, size);
44fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
45942778099ea597ee6b04ebdc74f506667fc7782cAxel Davy    This->data = (uint8_t *)align_calloc(size, 32);
46fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (!This->data)
47fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        return E_OUTOFMEMORY;
48fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    return D3D_OK;
49fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
50fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
51fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstatic HRESULT
52fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_ctor( struct NineVolume9 *This,
53fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                  struct NineUnknownParams *pParams,
54fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                  struct NineUnknown *pContainer,
55fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                  struct pipe_resource *pResource,
56fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                  unsigned Level,
57fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                  D3DVOLUME_DESC *pDesc )
58fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
59fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    HRESULT hr;
60fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
61fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    assert(pContainer); /* stand-alone volumes can't be created */
62fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
63fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    DBG("This=%p pContainer=%p pDevice=%p pResource=%p Level=%u pDesc=%p\n",
64fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        This, pContainer, pParams->device, pResource, Level, pDesc);
65fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
66fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    /* Mark this as a special surface held by another internal resource. */
67fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    pParams->container = pContainer;
68fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
69fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    user_assert(!(pDesc->Usage & D3DUSAGE_DYNAMIC) ||
70fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                (pDesc->Pool != D3DPOOL_MANAGED), D3DERR_INVALIDCALL);
71fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
72fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    assert(pResource || pDesc->Pool != D3DPOOL_DEFAULT);
73fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
74fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    hr = NineUnknown_ctor(&This->base, pParams);
75fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (FAILED(hr))
76fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        return hr;
77fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
78fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    pipe_resource_reference(&This->resource, pResource);
79fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
80fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->transfer = NULL;
81fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->lock_count = 0;
82fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
83fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->level = Level;
84fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->level_actual = Level;
85fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->desc = *pDesc;
86fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
87fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.screen = pParams->device->screen;
88fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.target = PIPE_TEXTURE_3D;
89fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.width0 = pDesc->Width;
90fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.height0 = pDesc->Height;
91fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.depth0 = pDesc->Depth;
92fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.last_level = 0;
93fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.array_size = 1;
94fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.nr_samples = 0;
95fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.usage = PIPE_USAGE_DEFAULT;
96fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.bind = PIPE_BIND_SAMPLER_VIEW;
97fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->info.flags = 0;
9827e438e35630819914bd42c5aa27fe6e53ebe491Axel Davy    This->info.format = d3d9_to_pipe_format_checked(This->info.screen,
9927e438e35630819914bd42c5aa27fe6e53ebe491Axel Davy                                                    pDesc->Format,
10027e438e35630819914bd42c5aa27fe6e53ebe491Axel Davy                                                    This->info.target,
10127e438e35630819914bd42c5aa27fe6e53ebe491Axel Davy                                                    This->info.nr_samples,
1026cba347530433c61b218d2b897fb57f33835b37bAxel Davy                                                    This->info.bind, FALSE,
1036cba347530433c61b218d2b897fb57f33835b37bAxel Davy                                                    pDesc->Pool == D3DPOOL_SCRATCH);
10427e438e35630819914bd42c5aa27fe6e53ebe491Axel Davy
10527e438e35630819914bd42c5aa27fe6e53ebe491Axel Davy    if (This->info.format == PIPE_FORMAT_NONE)
10627e438e35630819914bd42c5aa27fe6e53ebe491Axel Davy        return D3DERR_DRIVERINTERNALERROR;
107fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
108fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->stride = util_format_get_stride(This->info.format, pDesc->Width);
109fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->stride = align(This->stride, 4);
110fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    This->layer_stride = util_format_get_2d_size(This->info.format,
111fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                                                 This->stride, pDesc->Height);
112fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
113258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy    /* Get true format */
114258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy    This->format_conversion = d3d9_to_pipe_format_checked(This->info.screen,
115258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                                         pDesc->Format,
116258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                                         This->info.target,
117258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                                         This->info.nr_samples,
118258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                                         This->info.bind, FALSE,
119258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                                         TRUE);
120258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy    if (This->info.format != This->format_conversion) {
121258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        This->stride_conversion = nine_format_get_stride(This->format_conversion,
122258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                                         pDesc->Width);
123258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        This->layer_stride_conversion = util_format_get_2d_size(This->format_conversion,
124258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                                                This->stride_conversion,
125258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                                                pDesc->Height);
126942778099ea597ee6b04ebdc74f506667fc7782cAxel Davy        This->data_conversion = align_calloc(This->layer_stride_conversion *
127258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                             This->desc.Depth, 32);
128258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        if (!This->data_conversion)
129258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy            return E_OUTOFMEMORY;
130258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy    }
131258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy
132fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (!This->resource) {
133fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        hr = NineVolume9_AllocateData(This);
134fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        if (FAILED(hr))
135fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt            return hr;
136fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    }
137fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    return D3D_OK;
138fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
139fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
140fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstatic void
141fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_dtor( struct NineVolume9 *This )
142fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
143fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    DBG("This=%p\n", This);
144fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
1450444ef0832be74cd79fec026d552c5ffcff2cd41Axel Davy    if (This->transfer) {
1460444ef0832be74cd79fec026d552c5ffcff2cd41Axel Davy        struct pipe_context *pipe = nine_context_get_pipe_multithread(This->base.device);
1470444ef0832be74cd79fec026d552c5ffcff2cd41Axel Davy        pipe->transfer_unmap(pipe, This->transfer);
1480444ef0832be74cd79fec026d552c5ffcff2cd41Axel Davy        This->transfer = NULL;
1490444ef0832be74cd79fec026d552c5ffcff2cd41Axel Davy    }
150fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
1510444ef0832be74cd79fec026d552c5ffcff2cd41Axel Davy    /* Note: Following condition cannot happen currently, since we
1520444ef0832be74cd79fec026d552c5ffcff2cd41Axel Davy     * refcount the volume in the functions increasing
1530444ef0832be74cd79fec026d552c5ffcff2cd41Axel Davy     * pending_uploads_counter. */
154d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy    if (p_atomic_read(&This->pending_uploads_counter))
155d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy        nine_csmt_process(This->base.device);
156d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy
157dfeca90419ac50e0776a3fdb102a2975c8075391Patrick Rudolph    if (This->data)
158258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        align_free(This->data);
159258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy    if (This->data_conversion)
160258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        align_free(This->data_conversion);
161dfeca90419ac50e0776a3fdb102a2975c8075391Patrick Rudolph
162fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    pipe_resource_reference(&This->resource, NULL);
163fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
164fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    NineUnknown_dtor(&This->base);
165fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
166fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
16777d6c11f8fa87ba1070028cb036807dc8a115633Axel DavyHRESULT NINE_WINAPI
168fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_GetContainer( struct NineVolume9 *This,
169fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                          REFIID riid,
170fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                          void **ppContainer )
171fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
172f2eacef33de8d7b136b485927cb10f15d7439d48Patrick Rudolph    char guid_str[64];
173f2eacef33de8d7b136b485927cb10f15d7439d48Patrick Rudolph
174f2eacef33de8d7b136b485927cb10f15d7439d48Patrick Rudolph    DBG("This=%p riid=%p id=%s ppContainer=%p\n",
175f2eacef33de8d7b136b485927cb10f15d7439d48Patrick Rudolph        This, riid, riid ? GUID_sprintf(guid_str, riid) : "", ppContainer);
176f2eacef33de8d7b136b485927cb10f15d7439d48Patrick Rudolph
177b2f17e5f62e43ab6fd07d8752d0fc27f89f8aa37Axel Davy    (void)guid_str;
178b2f17e5f62e43ab6fd07d8752d0fc27f89f8aa37Axel Davy
179fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (!NineUnknown(This)->container)
180fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        return E_NOINTERFACE;
181fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    return NineUnknown_QueryInterface(NineUnknown(This)->container, riid, ppContainer);
182fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
183fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
184a2a1a5805fd617e7f3cc8be44dd79b50da07ebb9Ilia Mirkinstatic inline void
185fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_MarkContainerDirty( struct NineVolume9 *This )
186fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
187fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    struct NineBaseTexture9 *tex;
188fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#ifdef DEBUG
189fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    /* This is always contained by a NineVolumeTexture9. */
190fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    GUID id = IID_IDirect3DVolumeTexture9;
191fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    REFIID ref = &id;
192fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    assert(NineUnknown_QueryInterface(This->base.container, ref, (void **)&tex)
193fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt           == S_OK);
194fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    assert(NineUnknown_Release(NineUnknown(tex)) != 0);
195fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#endif
196fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
197fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    tex = NineBaseTexture9(This->base.container);
198fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    assert(tex);
199fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (This->desc.Pool == D3DPOOL_MANAGED)
200e558ce98f2b01e11ff79c29efaea2877121ae04aAxel Davy        tex->managed.dirty = TRUE;
201fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
202fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    BASETEX_REGISTER_UPDATE(tex);
203fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
204fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
20577d6c11f8fa87ba1070028cb036807dc8a115633Axel DavyHRESULT NINE_WINAPI
206fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_GetDesc( struct NineVolume9 *This,
207fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                     D3DVOLUME_DESC *pDesc )
208fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
209fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    user_assert(pDesc != NULL, E_POINTER);
210fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    *pDesc = This->desc;
211fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    return D3D_OK;
212fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
213fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
214a2a1a5805fd617e7f3cc8be44dd79b50da07ebb9Ilia Mirkininline void
215fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_AddDirtyRegion( struct NineVolume9 *This,
216fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                            const struct pipe_box *box )
217fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
2183f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy    D3DBOX dirty_region;
2193f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy    struct NineVolumeTexture9 *tex = NineVolumeTexture9(This->base.container);
220fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
221fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (!box) {
2223f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        NineVolumeTexture9_AddDirtyBox(tex, NULL);
223fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    } else {
2243f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        dirty_region.Left = box->x << This->level_actual;
2253f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        dirty_region.Top = box->y << This->level_actual;
2263f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        dirty_region.Front = box->z << This->level_actual;
2273f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        dirty_region.Right = dirty_region.Left + (box->width << This->level_actual);
2283f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        dirty_region.Bottom = dirty_region.Top + (box->height << This->level_actual);
2293f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        dirty_region.Back = dirty_region.Front + (box->depth << This->level_actual);
2303f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        NineVolumeTexture9_AddDirtyBox(tex, &dirty_region);
231fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    }
232fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
233fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
234a2a1a5805fd617e7f3cc8be44dd79b50da07ebb9Ilia Mirkinstatic inline uint8_t *
235fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_GetSystemMemPointer(struct NineVolume9 *This, int x, int y, int z)
236fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
237fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    unsigned x_offset = util_format_get_stride(This->info.format, x);
238fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
239fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    y = util_format_get_nblocksy(This->info.format, y);
240fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
241fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    assert(This->data);
242fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    return This->data + (z * This->layer_stride + y * This->stride + x_offset);
243fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
244fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
24577d6c11f8fa87ba1070028cb036807dc8a115633Axel DavyHRESULT NINE_WINAPI
246fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_LockBox( struct NineVolume9 *This,
247fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                     D3DLOCKED_BOX *pLockedVolume,
248fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                     const D3DBOX *pBox,
249fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                     DWORD Flags )
250fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
251c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy    struct pipe_context *pipe;
252fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    struct pipe_resource *resource = This->resource;
253fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    struct pipe_box box;
254fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    unsigned usage;
255fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
256fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    DBG("This=%p(%p) pLockedVolume=%p pBox=%p[%u..%u,%u..%u,%u..%u] Flags=%s\n",
257fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        This, This->base.container, pLockedVolume, pBox,
258fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        pBox ? pBox->Left : 0, pBox ? pBox->Right : 0,
259fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        pBox ? pBox->Top : 0, pBox ? pBox->Bottom : 0,
260fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        pBox ? pBox->Front : 0, pBox ? pBox->Back : 0,
261fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        nine_D3DLOCK_to_str(Flags));
262fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
26348d895aa4b2475ef0af234b832d92d0ac4a47761Patrick Rudolph    /* check if it's already locked */
26448d895aa4b2475ef0af234b832d92d0ac4a47761Patrick Rudolph    user_assert(This->lock_count == 0, D3DERR_INVALIDCALL);
26548d895aa4b2475ef0af234b832d92d0ac4a47761Patrick Rudolph
26648d895aa4b2475ef0af234b832d92d0ac4a47761Patrick Rudolph    /* set pBits to NULL after lock_count check */
26748d895aa4b2475ef0af234b832d92d0ac4a47761Patrick Rudolph    user_assert(pLockedVolume, E_POINTER);
26848d895aa4b2475ef0af234b832d92d0ac4a47761Patrick Rudolph    pLockedVolume->pBits = NULL;
26948d895aa4b2475ef0af234b832d92d0ac4a47761Patrick Rudolph
270fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    user_assert(This->desc.Pool != D3DPOOL_DEFAULT ||
271fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                (This->desc.Usage & D3DUSAGE_DYNAMIC), D3DERR_INVALIDCALL);
272fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
273fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    user_assert(!((Flags & D3DLOCK_DISCARD) && (Flags & D3DLOCK_READONLY)),
274fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                D3DERR_INVALIDCALL);
275fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
276f396cd43ab148ff77b8df3344610ee6f2224d21dAxel Davy    if (pBox && compressed_format (This->desc.Format)) { /* For volume all pools are checked */
277fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        const unsigned w = util_format_get_blockwidth(This->info.format);
278fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        const unsigned h = util_format_get_blockheight(This->info.format);
279f396cd43ab148ff77b8df3344610ee6f2224d21dAxel Davy        user_assert((pBox->Left == 0 && pBox->Right == This->desc.Width &&
280f396cd43ab148ff77b8df3344610ee6f2224d21dAxel Davy                     pBox->Top == 0 && pBox->Bottom == This->desc.Height) ||
281f396cd43ab148ff77b8df3344610ee6f2224d21dAxel Davy                    (!(pBox->Left % w) && !(pBox->Right % w) &&
282f396cd43ab148ff77b8df3344610ee6f2224d21dAxel Davy                     !(pBox->Top % h) && !(pBox->Bottom % h)),
283fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                    D3DERR_INVALIDCALL);
284fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    }
285fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
286fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (Flags & D3DLOCK_DISCARD) {
287fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE;
288fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    } else {
289fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        usage = (Flags & D3DLOCK_READONLY) ?
290fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt            PIPE_TRANSFER_READ : PIPE_TRANSFER_READ_WRITE;
291fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    }
292fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (Flags & D3DLOCK_DONOTWAIT)
293fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        usage |= PIPE_TRANSFER_DONTBLOCK;
294fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
295fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (pBox) {
2967f58ba45a8ef043fba98cdd56c122fe5e3091332Patrick Rudolph        user_assert(pBox->Right > pBox->Left, D3DERR_INVALIDCALL);
2977f58ba45a8ef043fba98cdd56c122fe5e3091332Patrick Rudolph        user_assert(pBox->Bottom > pBox->Top, D3DERR_INVALIDCALL);
2987f58ba45a8ef043fba98cdd56c122fe5e3091332Patrick Rudolph        user_assert(pBox->Back > pBox->Front, D3DERR_INVALIDCALL);
2997f58ba45a8ef043fba98cdd56c122fe5e3091332Patrick Rudolph        user_assert(pBox->Right <= This->desc.Width, D3DERR_INVALIDCALL);
3007f58ba45a8ef043fba98cdd56c122fe5e3091332Patrick Rudolph        user_assert(pBox->Bottom <= This->desc.Height, D3DERR_INVALIDCALL);
3017f58ba45a8ef043fba98cdd56c122fe5e3091332Patrick Rudolph        user_assert(pBox->Back <= This->desc.Depth, D3DERR_INVALIDCALL);
3027f58ba45a8ef043fba98cdd56c122fe5e3091332Patrick Rudolph
303fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        d3dbox_to_pipe_box(&box, pBox);
304fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        if (u_box_clip_2d(&box, &box, This->desc.Width, This->desc.Height) < 0) {
305fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt            DBG("Locked volume intersection empty.\n");
306fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt            return D3DERR_INVALIDCALL;
307fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        }
308fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    } else {
309fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height, This->desc.Depth,
310fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                 &box);
311fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    }
312fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
313d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy    if (p_atomic_read(&This->pending_uploads_counter))
314d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy        nine_csmt_process(This->base.device);
315d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy
316258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy    if (This->data_conversion) {
317258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        /* For now we only have uncompressed formats here */
318258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        pLockedVolume->RowPitch = This->stride_conversion;
319258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        pLockedVolume->SlicePitch = This->layer_stride_conversion;
320258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        pLockedVolume->pBits = This->data_conversion + box.z * This->layer_stride_conversion +
321258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                               box.y * This->stride_conversion +
322258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                               util_format_get_stride(This->format_conversion, box.x);
323258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy    } else if (This->data) {
324fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        pLockedVolume->RowPitch = This->stride;
325fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        pLockedVolume->SlicePitch = This->layer_stride;
326fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        pLockedVolume->pBits =
327fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt            NineVolume9_GetSystemMemPointer(This, box.x, box.y, box.z);
328fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    } else {
3291e64be6f91652e7e5ba60c86c379ee41bb7e4f81Axel Davy        bool no_refs = !p_atomic_read(&This->base.bind) &&
3301e64be6f91652e7e5ba60c86c379ee41bb7e4f81Axel Davy            !p_atomic_read(&This->base.container->bind);
3311e64be6f91652e7e5ba60c86c379ee41bb7e4f81Axel Davy        if (no_refs)
3321e64be6f91652e7e5ba60c86c379ee41bb7e4f81Axel Davy            pipe = nine_context_get_pipe_acquire(This->base.device);
3331e64be6f91652e7e5ba60c86c379ee41bb7e4f81Axel Davy        else
3341e64be6f91652e7e5ba60c86c379ee41bb7e4f81Axel Davy            pipe = NineDevice9_GetPipe(This->base.device);
335fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        pLockedVolume->pBits =
336c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy            pipe->transfer_map(pipe, resource, This->level, usage,
337c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy                               &box, &This->transfer);
3381e64be6f91652e7e5ba60c86c379ee41bb7e4f81Axel Davy        if (no_refs)
3391e64be6f91652e7e5ba60c86c379ee41bb7e4f81Axel Davy            nine_context_get_pipe_release(This->base.device);
340fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        if (!This->transfer) {
341fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt            if (Flags & D3DLOCK_DONOTWAIT)
342fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                return D3DERR_WASSTILLDRAWING;
343fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt            return D3DERR_DRIVERINTERNALERROR;
344fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        }
345fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        pLockedVolume->RowPitch = This->transfer->stride;
346fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        pLockedVolume->SlicePitch = This->transfer->layer_stride;
347fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    }
348fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
349fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (!(Flags & (D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY))) {
350fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        NineVolume9_MarkContainerDirty(This);
3513f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        NineVolume9_AddDirtyRegion(This, &box);
352fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    }
353fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
354fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    ++This->lock_count;
355fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    return D3D_OK;
356fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
357fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
35877d6c11f8fa87ba1070028cb036807dc8a115633Axel DavyHRESULT NINE_WINAPI
359fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_UnlockBox( struct NineVolume9 *This )
360fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
361c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy    struct pipe_context *pipe;
362c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy
363fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    DBG("This=%p lock_count=%u\n", This, This->lock_count);
364fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    user_assert(This->lock_count, D3DERR_INVALIDCALL);
365fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (This->transfer) {
36631262bbce085c69ef7a654528f509cb37415b41fAxel Davy        pipe = nine_context_get_pipe_acquire(This->base.device);
367c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy        pipe->transfer_unmap(pipe, This->transfer);
368fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        This->transfer = NULL;
36931262bbce085c69ef7a654528f509cb37415b41fAxel Davy        nine_context_get_pipe_release(This->base.device);
370fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    }
371fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    --This->lock_count;
372258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy
373258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy    if (This->data_conversion) {
374258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        struct pipe_transfer *transfer;
375258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        uint8_t *dst = This->data;
376258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        struct pipe_box box;
377258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy
378258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height, This->desc.Depth,
379258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                 &box);
380258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy
381c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy        pipe = NineDevice9_GetPipe(This->base.device);
382258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        if (!dst) {
383c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy            dst = pipe->transfer_map(pipe,
384c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy                                     This->resource,
385c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy                                     This->level,
386c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy                                     PIPE_TRANSFER_WRITE |
387c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy                                     PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
388c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy                                     &box, &transfer);
389258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy            if (!dst)
390258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                return D3D_OK;
391258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        }
392258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy
393258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        (void) util_format_translate_3d(This->info.format,
394258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        dst, This->data ? This->stride : transfer->stride,
395258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        This->data ? This->layer_stride : transfer->layer_stride,
396258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        0, 0, 0,
397258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        This->format_conversion,
398258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        This->data_conversion,
399258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        This->stride_conversion,
400258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        This->layer_stride_conversion,
401258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        0, 0, 0,
402258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        This->desc.Width, This->desc.Height,
403fe7bb46134162c9a9a18832f1746991aa78121e8Axel Davy                                        This->desc.Depth);
404258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy
405258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        if (!This->data)
406c7237e2c5c9935d80f04f2793bde9489ca6bda9dAxel Davy            pipe_transfer_unmap(pipe, transfer);
407258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy    }
408258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy
409fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    return D3D_OK;
410fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
411fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
412b75f830166eaf294e43746f1bf5630f7f2dcf30fAxel Davy/* When this function is called, we have already checked
413b75f830166eaf294e43746f1bf5630f7f2dcf30fAxel Davy * The copy regions fit the volumes */
41423e2a235dceaf1f2a7a3cf08e3c34c5068f8cc78Axel Davyvoid
415b75f830166eaf294e43746f1bf5630f7f2dcf30fAxel DavyNineVolume9_CopyMemToDefault( struct NineVolume9 *This,
416b75f830166eaf294e43746f1bf5630f7f2dcf30fAxel Davy                              struct NineVolume9 *From,
417b75f830166eaf294e43746f1bf5630f7f2dcf30fAxel Davy                              unsigned dstx, unsigned dsty, unsigned dstz,
418b75f830166eaf294e43746f1bf5630f7f2dcf30fAxel Davy                              struct pipe_box *pSrcBox )
419fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
420fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    struct pipe_resource *r_dst = This->resource;
421fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    struct pipe_box src_box;
422fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    struct pipe_box dst_box;
423fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
4247f74b9d47928979fdad445db1e0f249688c62991Stanislaw Halik    DBG("This=%p From=%p dstx=%u dsty=%u dstz=%u pSrcBox=%p\n",
4257f74b9d47928979fdad445db1e0f249688c62991Stanislaw Halik        This, From, dstx, dsty, dstz, pSrcBox);
4267f74b9d47928979fdad445db1e0f249688c62991Stanislaw Halik
427b75f830166eaf294e43746f1bf5630f7f2dcf30fAxel Davy    assert(This->desc.Pool == D3DPOOL_DEFAULT &&
428b75f830166eaf294e43746f1bf5630f7f2dcf30fAxel Davy           From->desc.Pool == D3DPOOL_SYSTEMMEM);
429fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
430fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    dst_box.x = dstx;
431fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    dst_box.y = dsty;
432fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    dst_box.z = dstz;
433fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
434fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    if (pSrcBox) {
435fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        src_box = *pSrcBox;
436fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    } else {
437fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        src_box.x = 0;
438fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        src_box.y = 0;
439fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        src_box.z = 0;
440fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        src_box.width = From->desc.Width;
441fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        src_box.height = From->desc.Height;
442fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        src_box.depth = From->desc.Depth;
443fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    }
444fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
445fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    dst_box.width = src_box.width;
446fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    dst_box.height = src_box.height;
447fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    dst_box.depth = src_box.depth;
448fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
449d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy    nine_context_box_upload(This->base.device,
450d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            &From->pending_uploads_counter,
4517089d88199d607d8a135a9605f14ec6393134205Axel Davy                            (struct NineUnknown *)This,
452d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            r_dst,
453d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            This->level,
454d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            &dst_box,
455d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            From->info.format,
456d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            From->data, From->stride,
457d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            From->layer_stride,
458d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            &src_box);
459258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy
460258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy    if (This->data_conversion)
461258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy        (void) util_format_translate_3d(This->format_conversion,
462258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        This->data_conversion,
463258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        This->stride_conversion,
464258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        This->layer_stride_conversion,
465258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        dstx, dsty, dstz,
466258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        From->info.format,
467258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        From->data, From->stride,
468258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        From->layer_stride,
469258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        src_box.x, src_box.y,
470258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        src_box.z,
471258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        src_box.width,
472258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        src_box.height,
473258ca1823c322661122d2d033c8b7facd3eb7767Axel Davy                                        src_box.depth);
474fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
475b75f830166eaf294e43746f1bf5630f7f2dcf30fAxel Davy    NineVolume9_MarkContainerDirty(This);
476fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
47723e2a235dceaf1f2a7a3cf08e3c34c5068f8cc78Axel Davy    return;
478fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
479fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
480fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtHRESULT
4813f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel DavyNineVolume9_UploadSelf( struct NineVolume9 *This,
4823f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy                        const struct pipe_box *damaged )
483fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
484fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    struct pipe_resource *res = This->resource;
4853f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy    struct pipe_box box;
486fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
4873f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy    DBG("This=%p damaged=%p data=%p res=%p\n", This, damaged,
488fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt        This->data, res);
489fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
490fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    assert(This->desc.Pool == D3DPOOL_MANAGED);
491fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    assert(res);
492fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
4933f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy    if (damaged) {
4943f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        box = *damaged;
4953f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy    } else {
4963f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        box.x = 0;
4973f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        box.y = 0;
4983f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        box.z = 0;
4993f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        box.width = This->desc.Width;
5003f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        box.height = This->desc.Height;
5013f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy        box.depth = This->desc.Depth;
502fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    }
5033f36ad732c7fbe8fd38aa852c3699101fdd5041dAxel Davy
504d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy    nine_context_box_upload(This->base.device,
505d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            &This->pending_uploads_counter,
5067089d88199d607d8a135a9605f14ec6393134205Axel Davy                            (struct NineUnknown *)This,
507d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            res,
508d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            This->level,
509d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            &box,
510d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            res->format,
511d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            This->data, This->stride,
512d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            This->layer_stride,
513d4a9b21feb890c149f0aa44b0bb6ea63a9932925Axel Davy                            &box);
514fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
515fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    return D3D_OK;
516fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
517fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
518fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
519fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtIDirect3DVolume9Vtbl NineVolume9_vtable = {
520fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    (void *)NineUnknown_QueryInterface,
521fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    (void *)NineUnknown_AddRef,
522fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    (void *)NineUnknown_Release,
523fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    (void *)NineUnknown_GetDevice, /* actually part of Volume9 iface */
524485cba7eb4f53ccd40a24d229cb7307ce4be27dePatrick Rudolph    (void *)NineUnknown_SetPrivateData,
525485cba7eb4f53ccd40a24d229cb7307ce4be27dePatrick Rudolph    (void *)NineUnknown_GetPrivateData,
526485cba7eb4f53ccd40a24d229cb7307ce4be27dePatrick Rudolph    (void *)NineUnknown_FreePrivateData,
527fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    (void *)NineVolume9_GetContainer,
528fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    (void *)NineVolume9_GetDesc,
529fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    (void *)NineVolume9_LockBox,
530fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    (void *)NineVolume9_UnlockBox
531fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt};
532fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
533fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstatic const GUID *NineVolume9_IIDs[] = {
534fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    &IID_IDirect3DVolume9,
535fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    &IID_IUnknown,
536fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    NULL
537fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt};
538fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt
539fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtHRESULT
540fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtNineVolume9_new( struct NineDevice9 *pDevice,
541fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                 struct NineUnknown *pContainer,
542fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                 struct pipe_resource *pResource,
543fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                 unsigned Level,
544fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                 D3DVOLUME_DESC *pDesc,
545fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                 struct NineVolume9 **ppOut )
546fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{
547fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt    NINE_DEVICE_CHILD_NEW(Volume9, ppOut, pDevice, /* args */
548fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt                          pContainer, pResource, Level, pDesc);
549fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}
550