Path: blob/21.2-virgl/src/gallium/frontends/d3d10umd/Resource.cpp
4565 views
/**************************************************************************1*2* Copyright 2012-2021 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,17* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19* USE OR OTHER DEALINGS IN THE SOFTWARE.20*21* The above copyright notice and this permission notice (including the22* next paragraph) shall be included in all copies or substantial portions23* of the Software.24*25**************************************************************************/2627/*28* Resource.cpp --29* Functions that manipulate GPU resources.30*/313233#include "Resource.h"34#include "Format.h"35#include "State.h"36#include "Query.h"3738#include "Debug.h"3940#include "util/u_math.h"41#include "util/u_rect.h"42#include "util/u_surface.h"434445/*46* ----------------------------------------------------------------------47*48* CalcPrivateResourceSize --49*50* The CalcPrivateResourceSize function determines the size of51* the user-mode display driver's private region of memory52* (that is, the size of internal driver structures, not the53* size of the resource video memory).54*55* ----------------------------------------------------------------------56*/5758SIZE_T APIENTRY59CalcPrivateResourceSize(D3D10DDI_HDEVICE hDevice, // IN60__in const D3D10DDIARG_CREATERESOURCE *pCreateResource) // IN61{62LOG_ENTRYPOINT();63return sizeof(Resource);64}656667static unsigned68translate_resource_usage( unsigned usage )69{70unsigned resource_usage = 0;7172switch (usage) {73case D3D10_DDI_USAGE_DEFAULT:74resource_usage = PIPE_USAGE_DEFAULT;75break;76case D3D10_DDI_USAGE_IMMUTABLE:77resource_usage = PIPE_USAGE_IMMUTABLE;78break;79case D3D10_DDI_USAGE_DYNAMIC:80resource_usage = PIPE_USAGE_DYNAMIC;81break;82case D3D10_DDI_USAGE_STAGING:83resource_usage = PIPE_USAGE_STAGING;84break;85default:86assert(0);87break;88}8990return resource_usage;91}929394static unsigned95translate_resource_flags(UINT flags)96{97unsigned bind = 0;9899if (flags & D3D10_DDI_BIND_VERTEX_BUFFER)100bind |= PIPE_BIND_VERTEX_BUFFER;101102if (flags & D3D10_DDI_BIND_INDEX_BUFFER)103bind |= PIPE_BIND_INDEX_BUFFER;104105if (flags & D3D10_DDI_BIND_CONSTANT_BUFFER)106bind |= PIPE_BIND_CONSTANT_BUFFER;107108if (flags & D3D10_DDI_BIND_SHADER_RESOURCE)109bind |= PIPE_BIND_SAMPLER_VIEW;110111if (flags & D3D10_DDI_BIND_RENDER_TARGET)112bind |= PIPE_BIND_RENDER_TARGET;113114if (flags & D3D10_DDI_BIND_DEPTH_STENCIL)115bind |= PIPE_BIND_DEPTH_STENCIL;116117if (flags & D3D10_DDI_BIND_STREAM_OUTPUT)118bind |= PIPE_BIND_STREAM_OUTPUT;119120return bind;121}122123124static enum pipe_texture_target125translate_texture_target( D3D10DDIRESOURCE_TYPE ResourceDimension,126UINT ArraySize)127{128assert(ArraySize >= 1);129switch(ResourceDimension) {130case D3D10DDIRESOURCE_BUFFER:131assert(ArraySize == 1);132return PIPE_BUFFER;133case D3D10DDIRESOURCE_TEXTURE1D:134return ArraySize > 1 ? PIPE_TEXTURE_1D_ARRAY : PIPE_TEXTURE_1D;135case D3D10DDIRESOURCE_TEXTURE2D:136return ArraySize > 1 ? PIPE_TEXTURE_2D_ARRAY : PIPE_TEXTURE_2D;137case D3D10DDIRESOURCE_TEXTURE3D:138assert(ArraySize == 1);139return PIPE_TEXTURE_3D;140case D3D10DDIRESOURCE_TEXTURECUBE:141assert(ArraySize % 6 == 0);142return ArraySize > 6 ? PIPE_TEXTURE_CUBE_ARRAY : PIPE_TEXTURE_CUBE;143default:144assert(0);145return PIPE_TEXTURE_1D;146}147}148149150static void151subResourceBox(struct pipe_resource *resource, // IN152UINT SubResource, // IN153unsigned *pLevel, // OUT154struct pipe_box *pBox) // OUT155{156UINT MipLevels = resource->last_level + 1;157unsigned layer;158unsigned width;159unsigned height;160unsigned depth;161162*pLevel = SubResource % MipLevels;163layer = SubResource / MipLevels;164165width = u_minify(resource->width0, *pLevel);166height = u_minify(resource->height0, *pLevel);167depth = u_minify(resource->depth0, *pLevel);168169pBox->x = 0;170pBox->y = 0;171pBox->z = 0 + layer;172pBox->width = width;173pBox->height = height;174pBox->depth = depth;175}176177178/*179* ----------------------------------------------------------------------180*181* CreateResource --182*183* The CreateResource function creates a resource.184*185* ----------------------------------------------------------------------186*/187188void APIENTRY189CreateResource(D3D10DDI_HDEVICE hDevice, // IN190__in const D3D10DDIARG_CREATERESOURCE *pCreateResource, // IN191D3D10DDI_HRESOURCE hResource, // IN192D3D10DDI_HRTRESOURCE hRTResource) // IN193{194LOG_ENTRYPOINT();195196if ((pCreateResource->MiscFlags & D3D10_DDI_RESOURCE_MISC_SHARED) ||197(pCreateResource->pPrimaryDesc &&198pCreateResource->pPrimaryDesc->DriverFlags & DXGI_DDI_PRIMARY_OPTIONAL)) {199200DebugPrintf("%s(%dx%dx%d hResource=%p)\n",201__FUNCTION__,202pCreateResource->pMipInfoList[0].TexelWidth,203pCreateResource->pMipInfoList[0].TexelHeight,204pCreateResource->pMipInfoList[0].TexelDepth,205hResource.pDrvPrivate);206DebugPrintf(" ResourceDimension = %u\n",207pCreateResource->ResourceDimension);208DebugPrintf(" Usage = %u\n",209pCreateResource->Usage);210DebugPrintf(" BindFlags = 0x%x\n",211pCreateResource->BindFlags);212DebugPrintf(" MapFlags = 0x%x\n",213pCreateResource->MapFlags);214DebugPrintf(" MiscFlags = 0x%x\n",215pCreateResource->MiscFlags);216DebugPrintf(" Format = %s\n",217FormatToName(pCreateResource->Format));218DebugPrintf(" SampleDesc.Count = %u\n", pCreateResource->SampleDesc.Count);219DebugPrintf(" SampleDesc.Quality = %u\n", pCreateResource->SampleDesc.Quality);220DebugPrintf(" MipLevels = %u\n", pCreateResource->MipLevels);221DebugPrintf(" ArraySize = %u\n", pCreateResource->ArraySize);222DebugPrintf(" pPrimaryDesc = %p\n", pCreateResource->pPrimaryDesc);223if (pCreateResource->pPrimaryDesc) {224DebugPrintf(" Flags = 0x%x\n",225pCreateResource->pPrimaryDesc->Flags);226DebugPrintf(" VidPnSourceId = %u\n", pCreateResource->pPrimaryDesc->VidPnSourceId);227DebugPrintf(" ModeDesc.Width = %u\n", pCreateResource->pPrimaryDesc->ModeDesc.Width);228DebugPrintf(" ModeDesc.Height = %u\n", pCreateResource->pPrimaryDesc->ModeDesc.Height);229DebugPrintf(" ModeDesc.Format = %u)\n",230pCreateResource->pPrimaryDesc->ModeDesc.Format);231DebugPrintf(" ModeDesc.RefreshRate.Numerator = %u\n", pCreateResource->pPrimaryDesc->ModeDesc.RefreshRate.Numerator);232DebugPrintf(" ModeDesc.RefreshRate.Denominator = %u\n", pCreateResource->pPrimaryDesc->ModeDesc.RefreshRate.Denominator);233DebugPrintf(" ModeDesc.ScanlineOrdering = %u\n",234pCreateResource->pPrimaryDesc->ModeDesc.ScanlineOrdering);235DebugPrintf(" ModeDesc.Rotation = %u\n",236pCreateResource->pPrimaryDesc->ModeDesc.Rotation);237DebugPrintf(" ModeDesc.Scaling = %u\n",238pCreateResource->pPrimaryDesc->ModeDesc.Scaling);239DebugPrintf(" DriverFlags = 0x%x\n",240pCreateResource->pPrimaryDesc->DriverFlags);241}242243}244245struct pipe_context *pipe = CastPipeContext(hDevice);246struct pipe_screen *screen = pipe->screen;247248Resource *pResource = CastResource(hResource);249250memset(pResource, 0, sizeof *pResource);251252#if 0253if (pCreateResource->pPrimaryDesc) {254pCreateResource->pPrimaryDesc->DriverFlags = DXGI_DDI_PRIMARY_DRIVER_FLAG_NO_SCANOUT;255if (!(pCreateResource->pPrimaryDesc->DriverFlags & DXGI_DDI_PRIMARY_OPTIONAL)) {256// http://msdn.microsoft.com/en-us/library/windows/hardware/ff568846.aspx257SetError(hDevice, DXGI_DDI_ERR_UNSUPPORTED);258return;259}260}261#endif262263pResource->Format = pCreateResource->Format;264pResource->MipLevels = pCreateResource->MipLevels;265266struct pipe_resource templat;267268memset(&templat, 0, sizeof templat);269270templat.target = translate_texture_target( pCreateResource->ResourceDimension,271pCreateResource->ArraySize );272273if (pCreateResource->Format == DXGI_FORMAT_UNKNOWN) {274assert(pCreateResource->ResourceDimension == D3D10DDIRESOURCE_BUFFER);275templat.format = PIPE_FORMAT_R8_UINT;276} else {277BOOL bindDepthStencil = !!(pCreateResource->BindFlags & D3D10_DDI_BIND_DEPTH_STENCIL);278templat.format = FormatTranslate(pCreateResource->Format, bindDepthStencil);279}280281templat.width0 = pCreateResource->pMipInfoList[0].TexelWidth;282templat.height0 = pCreateResource->pMipInfoList[0].TexelHeight;283templat.depth0 = pCreateResource->pMipInfoList[0].TexelDepth;284templat.array_size = pCreateResource->ArraySize;285templat.last_level = pCreateResource->MipLevels - 1;286templat.nr_samples = pCreateResource->SampleDesc.Count;287templat.nr_storage_samples = pCreateResource->SampleDesc.Count;288templat.bind = translate_resource_flags(pCreateResource->BindFlags);289templat.usage = translate_resource_usage(pCreateResource->Usage);290291if (templat.target != PIPE_BUFFER) {292if (!screen->is_format_supported(screen,293templat.format,294templat.target,295templat.nr_samples,296templat.nr_storage_samples,297templat.bind)) {298debug_printf("%s: unsupported format %s\n",299__FUNCTION__, util_format_name(templat.format));300SetError(hDevice, E_OUTOFMEMORY);301return;302}303}304305pResource->resource = screen->resource_create(screen, &templat);306if (!pResource) {307DebugPrintf("%s: failed to create resource\n", __FUNCTION__);308SetError(hDevice, E_OUTOFMEMORY);309return;310}311312pResource->NumSubResources = pCreateResource->MipLevels * pCreateResource->ArraySize;313pResource->transfers = (struct pipe_transfer **)calloc(pResource->NumSubResources,314sizeof *pResource->transfers);315316if (pCreateResource->pInitialDataUP) {317for (UINT SubResource = 0; SubResource < pResource->NumSubResources; ++SubResource) {318const D3D10_DDIARG_SUBRESOURCE_UP* pInitialDataUP =319&pCreateResource->pInitialDataUP[SubResource];320321unsigned level;322struct pipe_box box;323subResourceBox(pResource->resource, SubResource, &level, &box);324325struct pipe_transfer *transfer;326void *map;327map = pipe->transfer_map(pipe,328pResource->resource,329level,330PIPE_MAP_WRITE |331PIPE_MAP_UNSYNCHRONIZED,332&box,333&transfer);334assert(map);335if (map) {336for (int z = 0; z < box.depth; ++z) {337ubyte *dst = (ubyte*)map + z*transfer->layer_stride;338const ubyte *src = (const ubyte*)pInitialDataUP->pSysMem + z*pInitialDataUP->SysMemSlicePitch;339util_copy_rect(dst,340templat.format,341transfer->stride,3420, 0, box.width, box.height,343src,344pInitialDataUP->SysMemPitch,3450, 0);346}347pipe_transfer_unmap(pipe, transfer);348}349}350}351}352353354/*355* ----------------------------------------------------------------------356*357* CalcPrivateOpenedResourceSize --358*359* The CalcPrivateOpenedResourceSize function determines the size360* of the user-mode display driver's private shared region of memory361* (that is, the size of internal driver structures, not the size362* of the resource video memory) for an opened resource.363*364* ----------------------------------------------------------------------365*/366367SIZE_T APIENTRY368CalcPrivateOpenedResourceSize(D3D10DDI_HDEVICE hDevice, // IN369__in const D3D10DDIARG_OPENRESOURCE *pOpenResource) // IN370{371return sizeof(Resource);372}373374375/*376* ----------------------------------------------------------------------377*378* OpenResource --379*380* The OpenResource function opens a shared resource.381*382* ----------------------------------------------------------------------383*/384385void APIENTRY386OpenResource(D3D10DDI_HDEVICE hDevice, // IN387__in const D3D10DDIARG_OPENRESOURCE *pOpenResource, // IN388D3D10DDI_HRESOURCE hResource, // IN389D3D10DDI_HRTRESOURCE hRTResource) // IN390{391LOG_UNSUPPORTED_ENTRYPOINT();392SetError(hDevice, E_OUTOFMEMORY);393}394395396/*397* ----------------------------------------------------------------------398*399* DestroyResource --400*401* The DestroyResource function destroys the specified resource402* object. The resource object can be destoyed only if it is not403* currently bound to a display device, and if all views that404* refer to the resource are also destroyed.405*406* ----------------------------------------------------------------------407*/408409410void APIENTRY411DestroyResource(D3D10DDI_HDEVICE hDevice, // IN412D3D10DDI_HRESOURCE hResource) // IN413{414LOG_ENTRYPOINT();415416struct pipe_context *pipe = CastPipeContext(hDevice);417Resource *pResource = CastResource(hResource);418419if (pResource->so_target) {420pipe_so_target_reference(&pResource->so_target, NULL);421}422423for (UINT SubResource = 0; SubResource < pResource->NumSubResources; ++SubResource) {424if (pResource->transfers[SubResource]) {425pipe_transfer_unmap(pipe, pResource->transfers[SubResource]);426pResource->transfers[SubResource] = NULL;427}428}429free(pResource->transfers);430431pipe_resource_reference(&pResource->resource, NULL);432}433434435/*436* ----------------------------------------------------------------------437*438* ResourceMap --439*440* The ResourceMap function maps a subresource of a resource.441*442* ----------------------------------------------------------------------443*/444445void APIENTRY446ResourceMap(D3D10DDI_HDEVICE hDevice, // IN447D3D10DDI_HRESOURCE hResource, // IN448UINT SubResource, // IN449D3D10_DDI_MAP DDIMap, // IN450UINT Flags, // IN451__out D3D10DDI_MAPPED_SUBRESOURCE *pMappedSubResource) // OUT452{453LOG_ENTRYPOINT();454455struct pipe_context *pipe = CastPipeContext(hDevice);456Resource *pResource = CastResource(hResource);457struct pipe_resource *resource = pResource->resource;458459unsigned usage;460switch (DDIMap) {461case D3D10_DDI_MAP_READ:462usage = PIPE_MAP_READ;463break;464case D3D10_DDI_MAP_READWRITE:465usage = PIPE_MAP_READ | PIPE_MAP_WRITE;466break;467case D3D10_DDI_MAP_WRITE:468usage = PIPE_MAP_WRITE;469break;470case D3D10_DDI_MAP_WRITE_DISCARD:471usage = PIPE_MAP_WRITE;472if (resource->last_level == 0 && resource->array_size == 1) {473usage |= PIPE_MAP_DISCARD_WHOLE_RESOURCE;474} else {475usage |= PIPE_MAP_DISCARD_RANGE;476}477break;478case D3D10_DDI_MAP_WRITE_NOOVERWRITE:479usage = PIPE_MAP_WRITE | PIPE_MAP_UNSYNCHRONIZED;480break;481default:482assert(0);483return;484}485486assert(SubResource < pResource->NumSubResources);487488unsigned level;489struct pipe_box box;490subResourceBox(resource, SubResource, &level, &box);491492assert(!pResource->transfers[SubResource]);493494void *map;495map = pipe->transfer_map(pipe,496resource,497level,498usage,499&box,500&pResource->transfers[SubResource]);501if (!map) {502DebugPrintf("%s: failed to map resource\n", __FUNCTION__);503SetError(hDevice, E_FAIL);504return;505}506507pMappedSubResource->pData = map;508pMappedSubResource->RowPitch = pResource->transfers[SubResource]->stride;509pMappedSubResource->DepthPitch = pResource->transfers[SubResource]->layer_stride;510}511512513/*514* ----------------------------------------------------------------------515*516* ResourceUnmap --517*518* The ResourceUnmap function unmaps a subresource of a resource.519*520* ----------------------------------------------------------------------521*/522523void APIENTRY524ResourceUnmap(D3D10DDI_HDEVICE hDevice, // IN525D3D10DDI_HRESOURCE hResource, // IN526UINT SubResource) // IN527{528LOG_ENTRYPOINT();529530struct pipe_context *pipe = CastPipeContext(hDevice);531Resource *pResource = CastResource(hResource);532533assert(SubResource < pResource->NumSubResources);534535if (pResource->transfers[SubResource]) {536pipe_transfer_unmap(pipe, pResource->transfers[SubResource]);537pResource->transfers[SubResource] = NULL;538}539}540541542/*543*----------------------------------------------------------------------544*545* areResourcesCompatible --546*547* Check whether two resources can be safely passed to548* pipe_context::resource_copy_region method.549*550* Results:551* As above.552*553* Side effects:554* None.555*556*----------------------------------------------------------------------557*/558559static bool560areResourcesCompatible(const struct pipe_resource *src_resource, // IN561const struct pipe_resource *dst_resource) // IN562{563if (src_resource->format == dst_resource->format) {564/*565* Trivial.566*/567568return TRUE;569} else if (src_resource->target == PIPE_BUFFER &&570dst_resource->target == PIPE_BUFFER) {571/*572* Buffer resources are merely a collection of bytes.573*/574575return TRUE;576} else {577/*578* Check whether the formats are supported by579* the resource_copy_region method.580*/581582const struct util_format_description *src_format_desc;583const struct util_format_description *dst_format_desc;584585src_format_desc = util_format_description(src_resource->format);586dst_format_desc = util_format_description(dst_resource->format);587588assert(src_format_desc->block.width == dst_format_desc->block.width);589assert(src_format_desc->block.height == dst_format_desc->block.height);590assert(src_format_desc->block.bits == dst_format_desc->block.bits);591592return util_is_format_compatible(src_format_desc, dst_format_desc);593}594}595596597/*598* ----------------------------------------------------------------------599*600* ResourceCopy --601*602* The ResourceCopy function copies an entire source603* resource to a destination resource.604*605* ----------------------------------------------------------------------606*/607608void APIENTRY609ResourceCopy(D3D10DDI_HDEVICE hDevice, // IN610D3D10DDI_HRESOURCE hDstResource, // IN611D3D10DDI_HRESOURCE hSrcResource) // IN612{613LOG_ENTRYPOINT();614615Device *pDevice = CastDevice(hDevice);616if (!CheckPredicate(pDevice)) {617return;618}619620struct pipe_context *pipe = pDevice->pipe;621Resource *pDstResource = CastResource(hDstResource);622Resource *pSrcResource = CastResource(hSrcResource);623struct pipe_resource *dst_resource = pDstResource->resource;624struct pipe_resource *src_resource = pSrcResource->resource;625bool compatible;626627assert(dst_resource->target == src_resource->target);628assert(dst_resource->width0 == src_resource->width0);629assert(dst_resource->height0 == src_resource->height0);630assert(dst_resource->depth0 == src_resource->depth0);631assert(dst_resource->last_level == src_resource->last_level);632assert(dst_resource->array_size == src_resource->array_size);633634compatible = areResourcesCompatible(src_resource, dst_resource);635636/* could also use one 3d copy for arrays */637for (unsigned layer = 0; layer < dst_resource->array_size; ++layer) {638for (unsigned level = 0; level <= dst_resource->last_level; ++level) {639struct pipe_box box;640box.x = 0;641box.y = 0;642box.z = 0 + layer;643box.width = u_minify(dst_resource->width0, level);644box.height = u_minify(dst_resource->height0, level);645box.depth = u_minify(dst_resource->depth0, level);646647if (compatible) {648pipe->resource_copy_region(pipe,649dst_resource, level,6500, 0, layer,651src_resource, level,652&box);653} else {654util_resource_copy_region(pipe,655dst_resource, level,6560, 0, layer,657src_resource, level,658&box);659}660}661}662}663664665/*666* ----------------------------------------------------------------------667*668* ResourceCopyRegion --669*670* The ResourceCopyRegion function copies a source subresource671* region to a location on a destination subresource.672*673* ----------------------------------------------------------------------674*/675676void APIENTRY677ResourceCopyRegion(D3D10DDI_HDEVICE hDevice, // IN678D3D10DDI_HRESOURCE hDstResource, // IN679UINT DstSubResource, // IN680UINT DstX, // IN681UINT DstY, // IN682UINT DstZ, // IN683D3D10DDI_HRESOURCE hSrcResource, // IN684UINT SrcSubResource, // IN685__in_opt const D3D10_DDI_BOX *pSrcBox) // IN (optional)686{687LOG_ENTRYPOINT();688689Device *pDevice = CastDevice(hDevice);690if (!CheckPredicate(pDevice)) {691return;692}693694struct pipe_context *pipe = pDevice->pipe;695Resource *pDstResource = CastResource(hDstResource);696Resource *pSrcResource = CastResource(hSrcResource);697struct pipe_resource *dst_resource = pDstResource->resource;698struct pipe_resource *src_resource = pSrcResource->resource;699700unsigned dst_level = DstSubResource % (dst_resource->last_level + 1);701unsigned dst_layer = DstSubResource / (dst_resource->last_level + 1);702unsigned src_level = SrcSubResource % (src_resource->last_level + 1);703unsigned src_layer = SrcSubResource / (src_resource->last_level + 1);704705struct pipe_box src_box;706if (pSrcBox) {707src_box.x = pSrcBox->left;708src_box.y = pSrcBox->top;709src_box.z = pSrcBox->front + src_layer;710src_box.width = pSrcBox->right - pSrcBox->left;711src_box.height = pSrcBox->bottom - pSrcBox->top;712src_box.depth = pSrcBox->back - pSrcBox->front;713} else {714src_box.x = 0;715src_box.y = 0;716src_box.z = 0 + src_layer;717src_box.width = u_minify(src_resource->width0, src_level);718src_box.height = u_minify(src_resource->height0, src_level);719src_box.depth = u_minify(src_resource->depth0, src_level);720}721722if (areResourcesCompatible(src_resource, dst_resource)) {723pipe->resource_copy_region(pipe,724dst_resource, dst_level,725DstX, DstY, DstZ + dst_layer,726src_resource, src_level,727&src_box);728} else {729util_resource_copy_region(pipe,730dst_resource, dst_level,731DstX, DstY, DstZ + dst_layer,732src_resource, src_level,733&src_box);734}735}736737738/*739* ----------------------------------------------------------------------740*741* ResourceResolveSubResource --742*743* The ResourceResolveSubResource function resolves744* multiple samples to one pixel.745*746* ----------------------------------------------------------------------747*/748749void APIENTRY750ResourceResolveSubResource(D3D10DDI_HDEVICE hDevice, // IN751D3D10DDI_HRESOURCE hDstResource, // IN752UINT DstSubResource, // IN753D3D10DDI_HRESOURCE hSrcResource, // IN754UINT SrcSubResource, // IN755DXGI_FORMAT ResolveFormat) // IN756{757LOG_UNSUPPORTED_ENTRYPOINT();758}759760761/*762* ----------------------------------------------------------------------763*764* ResourceIsStagingBusy --765*766* The ResourceIsStagingBusy function determines whether a767* resource is currently being used by the graphics pipeline.768*769* ----------------------------------------------------------------------770*/771772BOOL APIENTRY773ResourceIsStagingBusy(D3D10DDI_HDEVICE hDevice, // IN774D3D10DDI_HRESOURCE hResource) // IN775{776LOG_ENTRYPOINT();777778/* ignore */779780return FALSE;781}782783784/*785* ----------------------------------------------------------------------786*787* ResourceReadAfterWriteHazard --788*789* The ResourceReadAfterWriteHazard function informs the user-mode790* display driver that the specified resource was used as an output791* from the graphics processing unit (GPU) and that the resource792* will be used as an input to the GPU.793*794* ----------------------------------------------------------------------795*/796797void APIENTRY798ResourceReadAfterWriteHazard(D3D10DDI_HDEVICE hDevice, // IN799D3D10DDI_HRESOURCE hResource) // IN800{801LOG_ENTRYPOINT();802803/* Not actually necessary */804}805806807/*808* ----------------------------------------------------------------------809*810* ResourceUpdateSubResourceUP --811*812* The ResourceUpdateSubresourceUP function updates a813* destination subresource region from a source814* system memory region.815*816* ----------------------------------------------------------------------817*/818819void APIENTRY820ResourceUpdateSubResourceUP(D3D10DDI_HDEVICE hDevice, // IN821D3D10DDI_HRESOURCE hDstResource, // IN822UINT DstSubResource, // IN823__in_opt const D3D10_DDI_BOX *pDstBox, // IN824__in const void *pSysMemUP, // IN825UINT RowPitch, // IN826UINT DepthPitch) // IN827{828LOG_ENTRYPOINT();829830Device *pDevice = CastDevice(hDevice);831if (!CheckPredicate(pDevice)) {832return;833}834835struct pipe_context *pipe = pDevice->pipe;836struct pipe_resource *dst_resource = CastPipeResource(hDstResource);837838unsigned level;839struct pipe_box box;840841if (pDstBox) {842UINT DstMipLevels = dst_resource->last_level + 1;843level = DstSubResource % DstMipLevels;844unsigned dst_layer = DstSubResource / DstMipLevels;845box.x = pDstBox->left;846box.y = pDstBox->top;847box.z = pDstBox->front + dst_layer;848box.width = pDstBox->right - pDstBox->left;849box.height = pDstBox->bottom - pDstBox->top;850box.depth = pDstBox->back - pDstBox->front;851} else {852subResourceBox(dst_resource, DstSubResource, &level, &box);853}854855struct pipe_transfer *transfer;856void *map;857map = pipe->transfer_map(pipe,858dst_resource,859level,860PIPE_MAP_WRITE | PIPE_MAP_DISCARD_RANGE,861&box,862&transfer);863assert(map);864if (map) {865for (int z = 0; z < box.depth; ++z) {866ubyte *dst = (ubyte*)map + z*transfer->layer_stride;867const ubyte *src = (const ubyte*)pSysMemUP + z*DepthPitch;868util_copy_rect(dst,869dst_resource->format,870transfer->stride,8710, 0, box.width, box.height,872src,873RowPitch,8740, 0);875}876pipe_transfer_unmap(pipe, transfer);877}878}879880881882