* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE. */
+#include "iunknown.h"
#include "surface9.h"
#include "device9.h"
#include "nine_helpers.h"
#include "nine_pipe.h"
#include "nine_dump.h"
+#include "nine_state.h"
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
#define DBG_CHANNEL DBG_SURFACE
+static void
+NineSurface9_CreatePipeSurfaces( struct NineSurface9 *This );
+
HRESULT
NineSurface9_ctor( struct NineSurface9 *This,
struct NineUnknownParams *pParams,
D3DSURFACE_DESC *pDesc )
{
HRESULT hr;
- union pipe_color_union rgba = {0};
- struct pipe_surface *surf;
- struct pipe_context *pipe = pParams->device->pipe;
bool allocate = !pContainer && pDesc->Format != D3DFMT_NULL;
D3DMULTISAMPLE_TYPE multisample_type;
/* Make sure there's a Desc */
assert(pDesc);
- /* D3DUSAGE_DYNAMIC isn't allowed on managed buffers */
- user_assert(!(pDesc->Usage & D3DUSAGE_DYNAMIC) ||
- (pDesc->Pool != D3DPOOL_MANAGED), D3DERR_INVALIDCALL);
-
assert(allocate || pResource || user_buffer ||
pDesc->Format == D3DFMT_NULL);
assert(!allocate || (!pResource && !user_buffer));
This->base.info.last_level = 0;
This->base.info.array_size = 1;
This->base.info.nr_samples = multisample_type;
+ This->base.info.nr_storage_samples = multisample_type;
This->base.info.usage = PIPE_USAGE_DEFAULT;
This->base.info.bind = PIPE_BIND_SAMPLER_VIEW; /* StretchRect */
if (pDesc->Usage & D3DUSAGE_RENDERTARGET) {
This->base.info.bind |= PIPE_BIND_RENDER_TARGET;
} else if (pDesc->Usage & D3DUSAGE_DEPTHSTENCIL) {
+ if (!depth_stencil_format(pDesc->Format))
+ return D3DERR_INVALIDCALL;
This->base.info.bind = d3d9_get_pipe_depth_format_bindings(pDesc->Format);
if (TextureType)
This->base.info.bind |= PIPE_BIND_SAMPLER_VIEW;
if (FAILED(hr))
return hr;
- This->pipe = This->base.base.device->pipe;
This->transfer = NULL;
This->texture = TextureType;
if (This->base.resource && (pDesc->Usage & D3DUSAGE_DYNAMIC))
This->base.resource->flags |= NINE_RESOURCE_FLAG_LOCKABLE;
+ if (This->base.resource && (pDesc->Usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)))
+ NineSurface9_CreatePipeSurfaces(This);
+
/* TODO: investigate what else exactly needs to be cleared */
- if (This->base.resource && (pDesc->Usage & D3DUSAGE_RENDERTARGET)) {
- surf = NineSurface9_GetSurface(This, 0);
- pipe->clear_render_target(pipe, surf, &rgba, 0, 0, pDesc->Width, pDesc->Height, false);
- }
+ if (This->base.resource && (pDesc->Usage & D3DUSAGE_RENDERTARGET))
+ nine_context_clear_render_target(pParams->device, This, 0, 0, 0, pDesc->Width, pDesc->Height);
NineSurface9_Dump(This);
{
DBG("This=%p\n", This);
- if (This->transfer)
- NineSurface9_UnlockRect(This);
+ if (This->transfer) {
+ struct pipe_context *pipe = nine_context_get_pipe_multithread(This->base.base.device);
+ pipe->transfer_unmap(pipe, This->transfer);
+ This->transfer = NULL;
+ }
+
+ /* Note: Following condition cannot happen currently, since we
+ * refcount the surface in the functions increasing
+ * pending_uploads_counter. */
+ if (p_atomic_read(&This->pending_uploads_counter))
+ nine_csmt_process(This->base.base.device);
pipe_surface_reference(&This->surface[0], NULL);
pipe_surface_reference(&This->surface[1], NULL);
NineResource9_dtor(&This->base);
}
-struct pipe_surface *
-NineSurface9_CreatePipeSurface( struct NineSurface9 *This, const int sRGB )
+static void
+NineSurface9_CreatePipeSurfaces( struct NineSurface9 *This )
{
- struct pipe_context *pipe = This->pipe;
- struct pipe_screen *screen = pipe->screen;
+ struct pipe_context *pipe;
+ struct pipe_screen *screen = NineDevice9_GetScreen(This->base.base.device);
struct pipe_resource *resource = This->base.resource;
struct pipe_surface templ;
enum pipe_format srgb_format;
assert(resource);
srgb_format = util_format_srgb(resource->format);
- if (sRGB && srgb_format != PIPE_FORMAT_NONE &&
- screen->is_format_supported(screen, srgb_format,
- resource->target, 0, resource->bind))
- templ.format = srgb_format;
- else
- templ.format = resource->format;
+ if (srgb_format == PIPE_FORMAT_NONE ||
+ !screen->is_format_supported(screen, srgb_format,
+ resource->target, 0, 0, resource->bind))
+ srgb_format = resource->format;
+
+ memset(&templ, 0, sizeof(templ));
+ templ.format = resource->format;
templ.u.tex.level = This->level;
templ.u.tex.first_layer = This->layer;
templ.u.tex.last_layer = This->layer;
- This->surface[sRGB] = pipe->create_surface(pipe, resource, &templ);
- assert(This->surface[sRGB]);
- return This->surface[sRGB];
+ pipe = nine_context_get_pipe_acquire(This->base.base.device);
+
+ This->surface[0] = pipe->create_surface(pipe, resource, &templ);
+
+ memset(&templ, 0, sizeof(templ));
+ templ.format = srgb_format;
+ templ.u.tex.level = This->level;
+ templ.u.tex.first_layer = This->layer;
+ templ.u.tex.last_layer = This->layer;
+
+ This->surface[1] = pipe->create_surface(pipe, resource, &templ);
+
+ nine_context_get_pipe_release(This->base.base.device);
+
+ assert(This->surface[0]); /* TODO: Handle failure */
+ assert(This->surface[1]);
}
#ifdef DEBUG
DBG("This=%p riid=%p id=%s ppContainer=%p\n",
This, riid, riid ? GUID_sprintf(guid_str, riid) : "", ppContainer);
+ (void)guid_str;
+
if (!ppContainer) return E_POINTER;
/* Return device for OffscreenPlainSurface, DepthStencilSurface and RenderTarget */
DWORD Flags )
{
struct pipe_resource *resource = This->base.resource;
+ struct pipe_context *pipe;
struct pipe_box box;
unsigned usage;
} else {
u_box_origin_2d(This->desc.Width, This->desc.Height, &box);
}
+ box.z = This->layer;
user_warn(This->desc.Format == D3DFMT_NULL);
+ if (p_atomic_read(&This->pending_uploads_counter))
+ nine_csmt_process(This->base.base.device);
+
if (This->data_conversion) {
/* For now we only have uncompressed formats here */
pLockedRect->Pitch = This->stride_conversion;
box.y);
}
} else {
+ bool no_refs = !p_atomic_read(&This->base.base.bind) &&
+ !(This->base.base.container && p_atomic_read(&This->base.base.container->bind));
DBG("mapping pipe_resource %p (level=%u usage=%x)\n",
resource, This->level, usage);
- pLockedRect->pBits = This->pipe->transfer_map(This->pipe, resource,
- This->level, usage, &box,
- &This->transfer);
+ /* if the object is not bound internally, there can't be any pending
+ * operation with the surface in the queue */
+ if (no_refs)
+ pipe = nine_context_get_pipe_acquire(This->base.base.device);
+ else
+ pipe = NineDevice9_GetPipe(This->base.base.device);
+ pLockedRect->pBits = pipe->transfer_map(pipe, resource,
+ This->level, usage, &box,
+ &This->transfer);
+ if (no_refs)
+ nine_context_get_pipe_release(This->base.base.device);
if (!This->transfer) {
DBG("transfer_map failed\n");
if (Flags & D3DLOCK_DONOTWAIT)
HRESULT NINE_WINAPI
NineSurface9_UnlockRect( struct NineSurface9 *This )
{
+ struct pipe_context *pipe;
DBG("This=%p lock_count=%u\n", This, This->lock_count);
user_assert(This->lock_count, D3DERR_INVALIDCALL);
if (This->transfer) {
- This->pipe->transfer_unmap(This->pipe, This->transfer);
+ pipe = nine_context_get_pipe_acquire(This->base.base.device);
+ pipe->transfer_unmap(pipe, This->transfer);
+ nine_context_get_pipe_release(This->base.base.device);
This->transfer = NULL;
}
--This->lock_count;
u_box_origin_2d(This->desc.Width, This->desc.Height, &box);
+ pipe = NineDevice9_GetPipe(This->base.base.device);
if (!dst) {
- dst = This->pipe->transfer_map(This->pipe,
- This->base.resource,
- This->level,
- PIPE_TRANSFER_WRITE |
- PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
- &box, &transfer);
+ dst = pipe->transfer_map(pipe,
+ This->base.resource,
+ This->level,
+ PIPE_TRANSFER_WRITE |
+ PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
+ &box, &transfer);
if (!dst)
return D3D_OK;
}
This->desc.Width, This->desc.Height);
if (!This->data)
- pipe_transfer_unmap(This->pipe, transfer);
+ pipe_transfer_unmap(pipe, transfer);
}
return D3D_OK;
}
const POINT *pDestPoint,
const RECT *pSourceRect )
{
- struct pipe_context *pipe = This->pipe;
- struct pipe_transfer *transfer = NULL;
struct pipe_resource *r_dst = This->base.resource;
- struct pipe_box dst_box;
- uint8_t *map = NULL;
+ struct pipe_box dst_box, src_box;
int src_x, src_y, dst_x, dst_y, copy_width, copy_height;
assert(This->base.pool == D3DPOOL_DEFAULT &&
u_box_2d_zslice(dst_x, dst_y, This->layer,
copy_width, copy_height, &dst_box);
-
- map = pipe->transfer_map(pipe,
- r_dst,
- This->level,
- PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE,
- &dst_box, &transfer);
- if (!map)
- return;
-
- /* Note: if formats are the sames, it will revert
- * to normal memcpy */
- (void) util_format_translate(r_dst->format,
- map, transfer->stride,
- 0, 0,
- From->base.info.format,
- From->data, From->stride,
- src_x, src_y,
- copy_width, copy_height);
-
- pipe_transfer_unmap(pipe, transfer);
+ u_box_2d_zslice(src_x, src_y, 0,
+ copy_width, copy_height, &src_box);
+
+ nine_context_box_upload(This->base.base.device,
+ &From->pending_uploads_counter,
+ (struct NineUnknown *)This,
+ r_dst,
+ This->level,
+ &dst_box,
+ From->base.info.format,
+ From->data, From->stride,
+ 0, /* depth = 1 */
+ &src_box);
if (This->data_conversion)
(void) util_format_translate(This->format_conversion,
NineSurface9_CopyDefaultToMem( struct NineSurface9 *This,
struct NineSurface9 *From )
{
- struct pipe_context *pipe = This->pipe;
+ struct pipe_context *pipe;
struct pipe_resource *r_src = From->base.resource;
struct pipe_transfer *transfer;
struct pipe_box src_box;
u_box_origin_2d(This->desc.Width, This->desc.Height, &src_box);
src_box.z = From->layer;
+ if (p_atomic_read(&This->pending_uploads_counter))
+ nine_csmt_process(This->base.base.device);
+
+ pipe = NineDevice9_GetPipe(This->base.base.device);
p_src = pipe->transfer_map(pipe, r_src, From->level,
PIPE_TRANSFER_READ,
&src_box, &transfer);
NineSurface9_UploadSelf( struct NineSurface9 *This,
const struct pipe_box *damaged )
{
- struct pipe_context *pipe = This->pipe;
struct pipe_resource *res = This->base.resource;
- uint8_t *ptr;
struct pipe_box box;
DBG("This=%p damaged=%p\n", This, damaged);
box.depth = 1;
}
- ptr = NineSurface9_GetSystemMemPointer(This, box.x, box.y);
-
- pipe->texture_subdata(pipe, res, This->level, 0,
- &box, ptr, This->stride, 0);
+ nine_context_box_upload(This->base.base.device,
+ &This->pending_uploads_counter,
+ (struct NineUnknown *)This,
+ res,
+ This->level,
+ &box,
+ res->format,
+ This->data, This->stride,
+ 0, /* depth = 1 */
+ &box);
return D3D_OK;
}
+/* Currently nine_context uses the NineSurface9
+ * fields when it is render target. Any modification requires
+ * pending commands with the surface to be executed. If the bind
+ * count is 0, there is no pending commands. */
+#define PROCESS_IF_BOUND(surf) \
+ if (surf->base.base.bind) \
+ nine_csmt_process(surf->base.base.device);
+
+void
+NineSurface9_SetResource( struct NineSurface9 *This,
+ struct pipe_resource *resource, unsigned level )
+{
+ /* No need to call PROCESS_IF_BOUND, because SetResource is used only
+ * for MANAGED textures, and they are not render targets. */
+ assert(This->base.pool == D3DPOOL_MANAGED);
+ This->level = level;
+ pipe_resource_reference(&This->base.resource, resource);
+}
+
+void
+NineSurface9_SetMultiSampleType( struct NineSurface9 *This,
+ D3DMULTISAMPLE_TYPE mst )
+{
+ PROCESS_IF_BOUND(This);
+ This->desc.MultiSampleType = mst;
+}
+
void
NineSurface9_SetResourceResize( struct NineSurface9 *This,
struct pipe_resource *resource )
assert(This->desc.Pool == D3DPOOL_DEFAULT);
assert(!This->texture);
+ PROCESS_IF_BOUND(This);
pipe_resource_reference(&This->base.resource, resource);
This->desc.Width = This->base.info.width0 = resource->width0;
This->desc.Height = This->base.info.height0 = resource->height0;
This->base.info.nr_samples = resource->nr_samples;
+ This->base.info.nr_storage_samples = resource->nr_storage_samples;
This->stride = nine_format_get_stride(This->base.info.format,
This->desc.Width);
pipe_surface_reference(&This->surface[0], NULL);
pipe_surface_reference(&This->surface[1], NULL);
+ if (resource)
+ NineSurface9_CreatePipeSurfaces(This);
}