Mesa (main): d3d12: Resources inherit from threaded_resource
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Nov 9 01:32:00 UTC 2021
Module: Mesa
Branch: main
Commit: e9a1e1c21ee11c5a85759e88871aba1fe459ff30
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e9a1e1c21ee11c5a85759e88871aba1fe459ff30
Author: Jesse Natalie <jenatali at microsoft.com>
Date: Wed Nov 3 10:23:14 2021 -0700
d3d12: Resources inherit from threaded_resource
Reviewed By: Bill Kristiansen <billkris at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13670>
---
src/gallium/drivers/d3d12/d3d12_blit.cpp | 80 ++++++++++-----------
src/gallium/drivers/d3d12/d3d12_context.cpp | 4 +-
src/gallium/drivers/d3d12/d3d12_context.h | 1 +
src/gallium/drivers/d3d12/d3d12_draw.cpp | 4 +-
src/gallium/drivers/d3d12/d3d12_query.cpp | 2 +-
src/gallium/drivers/d3d12/d3d12_resource.cpp | 101 ++++++++++++++-------------
src/gallium/drivers/d3d12/d3d12_resource.h | 3 +-
src/gallium/drivers/d3d12/d3d12_surface.cpp | 2 +-
8 files changed, 101 insertions(+), 96 deletions(-)
diff --git a/src/gallium/drivers/d3d12/d3d12_blit.cpp b/src/gallium/drivers/d3d12/d3d12_blit.cpp
index 2310d79c67f..ad54e340b47 100644
--- a/src/gallium/drivers/d3d12/d3d12_blit.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_blit.cpp
@@ -85,7 +85,7 @@ resolve_supported(const struct pipe_blit_info *info)
if (src->dxgi_format != dst->dxgi_format)
return false;
- if (util_format_is_pure_integer(src->base.format))
+ if (util_format_is_pure_integer(src->base.b.format))
return false;
// sizes needs to match
@@ -126,7 +126,7 @@ blit_resolve(struct d3d12_context *ctx, const struct pipe_blit_info *info)
d3d12_batch_reference_resource(batch, src);
d3d12_batch_reference_resource(batch, dst);
- DXGI_FORMAT dxgi_format = d3d12_get_resource_srv_format(src->base.format, src->base.target);
+ DXGI_FORMAT dxgi_format = d3d12_get_resource_srv_format(src->base.b.format, src->base.b.target);
assert(src->dxgi_format == dst->dxgi_format);
ctx->cmdlist->ResolveSubresource(
@@ -273,16 +273,16 @@ copy_subregion_no_barriers(struct d3d12_context *ctx,
D3D12_TEXTURE_COPY_LOCATION src_loc, dst_loc;
unsigned src_z = psrc_box->z;
- int src_subres_stride = src->base.last_level + 1;
- int dst_subres_stride = dst->base.last_level + 1;
+ int src_subres_stride = src->base.b.last_level + 1;
+ int dst_subres_stride = dst->base.b.last_level + 1;
- int src_array_size = src->base.array_size;
- int dst_array_size = dst->base.array_size;
+ int src_array_size = src->base.b.array_size;
+ int dst_array_size = dst->base.b.array_size;
- if (dst->base.target == PIPE_TEXTURE_CUBE)
+ if (dst->base.b.target == PIPE_TEXTURE_CUBE)
dst_array_size *= 6;
- if (src->base.target == PIPE_TEXTURE_CUBE)
+ if (src->base.b.target == PIPE_TEXTURE_CUBE)
src_array_size *= 6;
int stencil_src_res_offset = 1;
@@ -291,16 +291,16 @@ copy_subregion_no_barriers(struct d3d12_context *ctx,
int src_nres = 1;
int dst_nres = 1;
- if (dst->base.format == PIPE_FORMAT_Z24_UNORM_S8_UINT ||
- dst->base.format == PIPE_FORMAT_S8_UINT_Z24_UNORM ||
- dst->base.format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
+ if (dst->base.b.format == PIPE_FORMAT_Z24_UNORM_S8_UINT ||
+ dst->base.b.format == PIPE_FORMAT_S8_UINT_Z24_UNORM ||
+ dst->base.b.format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
stencil_dst_res_offset = dst_subres_stride * dst_array_size;
src_nres = 2;
}
- if (src->base.format == PIPE_FORMAT_Z24_UNORM_S8_UINT ||
- src->base.format == PIPE_FORMAT_S8_UINT_Z24_UNORM ||
- dst->base.format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
+ if (src->base.b.format == PIPE_FORMAT_Z24_UNORM_S8_UINT ||
+ src->base.b.format == PIPE_FORMAT_S8_UINT_Z24_UNORM ||
+ dst->base.b.format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
stencil_src_res_offset = src_subres_stride * src_array_size;
dst_nres = 2;
}
@@ -315,27 +315,27 @@ copy_subregion_no_barriers(struct d3d12_context *ctx,
continue;
src_loc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
- src_loc.SubresourceIndex = get_subresource_id(src->base.target, src_level, src_subres_stride, src_z, &src_z) +
+ src_loc.SubresourceIndex = get_subresource_id(src->base.b.target, src_level, src_subres_stride, src_z, &src_z) +
subres * stencil_src_res_offset;
src_loc.pResource = d3d12_resource_resource(src);
dst_loc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
- dst_loc.SubresourceIndex = get_subresource_id(dst->base.target, dst_level, dst_subres_stride, dstz, &dstz) +
+ dst_loc.SubresourceIndex = get_subresource_id(dst->base.b.target, dst_level, dst_subres_stride, dstz, &dstz) +
subres * stencil_dst_res_offset;
dst_loc.pResource = d3d12_resource_resource(dst);
if (psrc_box->x == 0 && psrc_box->y == 0 && psrc_box->z == 0 &&
- psrc_box->width == (int)u_minify(src->base.width0, src_level) &&
- psrc_box->height == (int)u_minify(src->base.height0, src_level) &&
- psrc_box->depth == (int)u_minify(src->base.depth0, src_level)) {
+ psrc_box->width == (int)u_minify(src->base.b.width0, src_level) &&
+ psrc_box->height == (int)u_minify(src->base.b.height0, src_level) &&
+ psrc_box->depth == (int)u_minify(src->base.b.depth0, src_level)) {
assert((dstx == 0 && dsty == 0 && dstz == 0) ||
screen->opts2.ProgrammableSamplePositionsTier !=
D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER_NOT_SUPPORTED ||
- (!util_format_is_depth_or_stencil(dst->base.format) &&
- !util_format_is_depth_or_stencil(src->base.format) &&
- dst->base.nr_samples <= 1 &&
- src->base.nr_samples <= 1));
+ (!util_format_is_depth_or_stencil(dst->base.b.format) &&
+ !util_format_is_depth_or_stencil(src->base.b.format) &&
+ dst->base.b.nr_samples <= 1 &&
+ src->base.b.nr_samples <= 1));
ctx->cmdlist->CopyTextureRegion(&dst_loc, dstx, dsty, dstz,
&src_loc, NULL);
@@ -343,18 +343,18 @@ copy_subregion_no_barriers(struct d3d12_context *ctx,
} else {
D3D12_BOX src_box;
src_box.left = psrc_box->x;
- src_box.right = MIN2(psrc_box->x + psrc_box->width, (int)u_minify(src->base.width0, src_level));
+ src_box.right = MIN2(psrc_box->x + psrc_box->width, (int)u_minify(src->base.b.width0, src_level));
src_box.top = psrc_box->y;
- src_box.bottom = MIN2(psrc_box->y + psrc_box->height, (int)u_minify(src->base.height0, src_level));
+ src_box.bottom = MIN2(psrc_box->y + psrc_box->height, (int)u_minify(src->base.b.height0, src_level));
src_box.front = src_z;
src_box.back = src_z + psrc_box->depth;
assert((screen->opts2.ProgrammableSamplePositionsTier !=
D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER_NOT_SUPPORTED ||
- (!util_format_is_depth_or_stencil(dst->base.format) &&
- !util_format_is_depth_or_stencil(src->base.format))) &&
- dst->base.nr_samples <= 1 &&
- src->base.nr_samples <= 1);
+ (!util_format_is_depth_or_stencil(dst->base.b.format) &&
+ !util_format_is_depth_or_stencil(src->base.b.format))) &&
+ dst->base.b.nr_samples <= 1 &&
+ src->base.b.nr_samples <= 1);
ctx->cmdlist->CopyTextureRegion(&dst_loc, dstx, dsty, dstz,
&src_loc, &src_box);
@@ -374,11 +374,11 @@ copy_resource_y_flipped_no_barriers(struct d3d12_context *ctx,
{
if (D3D12_DEBUG_BLIT & d3d12_debug) {
debug_printf("D3D12 BLIT as COPY: from %s@%d %dx%dx%d + %dx%dx%d\n",
- util_format_name(src->base.format), src_level,
+ util_format_name(src->base.b.format), src_level,
psrc_box->x, psrc_box->y, psrc_box->z,
psrc_box->width, psrc_box->height, psrc_box->depth);
debug_printf(" to %s@%d %dx%dx%d\n",
- util_format_name(dst->base.format), dst_level,
+ util_format_name(dst->base.b.format), dst_level,
pdst_box->x, pdst_box->y, pdst_box->z);
}
@@ -411,9 +411,9 @@ d3d12_direct_copy(struct d3d12_context *ctx,
{
struct d3d12_batch *batch = d3d12_current_batch(ctx);
- unsigned src_subres = get_subresource_id(src->base.target, src_level, src->base.last_level + 1,
+ unsigned src_subres = get_subresource_id(src->base.b.target, src_level, src->base.b.last_level + 1,
psrc_box->z, nullptr);
- unsigned dst_subres = get_subresource_id(dst->base.target, dst_level, dst->base.last_level + 1,
+ unsigned dst_subres = get_subresource_id(dst->base.b.target, dst_level, dst->base.b.last_level + 1,
pdst_box->z, nullptr);
if (D3D12_DEBUG_BLIT & d3d12_debug)
@@ -421,14 +421,14 @@ d3d12_direct_copy(struct d3d12_context *ctx,
src_subres, dst_subres);
d3d12_transition_subresources_state(ctx, src, src_subres, 1, 0, 1,
- d3d12_get_format_start_plane(src->base.format),
- d3d12_get_format_num_planes(src->base.format),
+ d3d12_get_format_start_plane(src->base.b.format),
+ d3d12_get_format_num_planes(src->base.b.format),
D3D12_RESOURCE_STATE_COPY_SOURCE,
D3D12_BIND_INVALIDATE_FULL);
d3d12_transition_subresources_state(ctx, dst, dst_subres, 1, 0, 1,
- d3d12_get_format_start_plane(dst->base.format),
- d3d12_get_format_num_planes(dst->base.format),
+ d3d12_get_format_start_plane(dst->base.b.format),
+ d3d12_get_format_num_planes(dst->base.b.format),
D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_BIND_INVALIDATE_FULL);
@@ -437,7 +437,7 @@ d3d12_direct_copy(struct d3d12_context *ctx,
d3d12_batch_reference_resource(batch, src);
d3d12_batch_reference_resource(batch, dst);
- if (src->base.target == PIPE_BUFFER) {
+ if (src->base.b.target == PIPE_BUFFER) {
copy_buffer_region_no_barriers(ctx, dst, pdst_box->x,
src, psrc_box->x, psrc_box->width);
} else if (psrc_box->height == pdst_box->height) {
@@ -479,7 +479,7 @@ create_staging_resource(struct d3d12_context *ctx,
abs(src_box->width), abs(src_box->height), abs(src_box->depth),
©_src);
- templ.format = src->base.format;
+ templ.format = src->base.b.format;
templ.width0 = copy_src.width;
templ.height0 = copy_src.height;
templ.depth0 = copy_src.depth;
@@ -488,7 +488,7 @@ create_staging_resource(struct d3d12_context *ctx,
templ.nr_storage_samples = 1;
templ.usage = PIPE_USAGE_STAGING;
templ.bind = util_format_is_depth_or_stencil(templ.format) ? PIPE_BIND_DEPTH_STENCIL : PIPE_BIND_RENDER_TARGET;
- templ.target = src->base.target;
+ templ.target = src->base.b.target;
staging_res = ctx->base.screen->resource_create(ctx->base.screen, &templ);
diff --git a/src/gallium/drivers/d3d12/d3d12_context.cpp b/src/gallium/drivers/d3d12/d3d12_context.cpp
index 73fa7b125c6..0d38fbb6cf8 100644
--- a/src/gallium/drivers/d3d12/d3d12_context.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_context.cpp
@@ -1176,7 +1176,7 @@ d3d12_set_vertex_buffers(struct pipe_context *pctx,
struct d3d12_resource *res = d3d12_resource(buf->buffer.resource);
ctx->vbvs[i].BufferLocation = d3d12_resource_gpu_virtual_address(res) + buf->buffer_offset;
ctx->vbvs[i].StrideInBytes = buf->stride;
- ctx->vbvs[i].SizeInBytes = res->base.width0 - buf->buffer_offset;
+ ctx->vbvs[i].SizeInBytes = res->base.b.width0 - buf->buffer_offset;
}
ctx->state_dirty |= D3D12_DIRTY_VERTEX_BUFFERS;
}
@@ -1634,7 +1634,7 @@ d3d12_transition_subresources_state(struct d3d12_context *ctx,
const uint32_t layer = start_layer + a;
for( uint32_t p = 0; p < num_planes; p++) {
const uint32_t plane = start_plane + p;
- uint32_t subres_id = level + (layer * res->mip_levels) + plane * (res->mip_levels * res->base.array_size);
+ uint32_t subres_id = level + (layer * res->mip_levels) + plane * (res->mip_levels * res->base.b.array_size);
assert(subres_id < xres->NumSubresources());
ctx->resource_state_manager->TransitionSubresource(xres, subres_id, state);
}
diff --git a/src/gallium/drivers/d3d12/d3d12_context.h b/src/gallium/drivers/d3d12/d3d12_context.h
index 362b8022278..859336b7dfd 100644
--- a/src/gallium/drivers/d3d12/d3d12_context.h
+++ b/src/gallium/drivers/d3d12/d3d12_context.h
@@ -36,6 +36,7 @@
#include "util/list.h"
#include "util/slab.h"
#include "util/u_suballoc.h"
+#include "util/u_threaded_context.h"
#include <directx/d3d12.h>
diff --git a/src/gallium/drivers/d3d12/d3d12_draw.cpp b/src/gallium/drivers/d3d12/d3d12_draw.cpp
index 0dcb0c51dd4..c48c57c5c64 100644
--- a/src/gallium/drivers/d3d12/d3d12_draw.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_draw.cpp
@@ -393,7 +393,7 @@ transition_surface_subresources_state(struct d3d12_context *ctx,
{
struct d3d12_resource *res = d3d12_resource(pres);
unsigned start_layer, num_layers;
- if (!d3d12_subresource_id_uses_layer(res->base.target)) {
+ if (!d3d12_subresource_id_uses_layer(res->base.b.target)) {
start_layer = 0;
num_layers = 1;
} else {
@@ -657,7 +657,7 @@ d3d12_draw_vbo(struct pipe_context *pctx,
D3D12_INDEX_BUFFER_VIEW ibv;
struct d3d12_resource *res = d3d12_resource(index_buffer);
ibv.BufferLocation = d3d12_resource_gpu_virtual_address(res) + index_offset;
- ibv.SizeInBytes = res->base.width0 - index_offset;
+ ibv.SizeInBytes = res->base.b.width0 - index_offset;
ibv.Format = ib_format(dinfo->index_size);
d3d12_transition_resource_state(ctx, res, D3D12_RESOURCE_STATE_INDEX_BUFFER, D3D12_BIND_INVALIDATE_NONE);
if (ctx->cmdlist_dirty & D3D12_DIRTY_INDEX_BUFFER ||
diff --git a/src/gallium/drivers/d3d12/d3d12_query.cpp b/src/gallium/drivers/d3d12/d3d12_query.cpp
index 9f86e956e0d..29d66bde8e5 100644
--- a/src/gallium/drivers/d3d12/d3d12_query.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_query.cpp
@@ -161,7 +161,7 @@ d3d12_destroy_query(struct pipe_context *pctx,
struct pipe_query *q)
{
struct d3d12_query *query = (struct d3d12_query *)q;
- pipe_resource *predicate = &query->predicate->base;
+ pipe_resource *predicate = &query->predicate->base.b;
if (query->subquery)
d3d12_destroy_query(pctx, (struct pipe_query *)query->subquery);
pipe_resource_reference(&predicate, NULL);
diff --git a/src/gallium/drivers/d3d12/d3d12_resource.cpp b/src/gallium/drivers/d3d12/d3d12_resource.cpp
index f8ebd4e1ccf..3df178fc20f 100644
--- a/src/gallium/drivers/d3d12/d3d12_resource.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_resource.cpp
@@ -53,7 +53,7 @@ can_map_directly(struct pipe_resource *pres)
static void
init_valid_range(struct d3d12_resource *res)
{
- if (can_map_directly(&res->base))
+ if (can_map_directly(&res->base.b))
util_range_init(&res->valid_buffer_range);
}
@@ -62,6 +62,7 @@ d3d12_resource_destroy(struct pipe_screen *pscreen,
struct pipe_resource *presource)
{
struct d3d12_resource *resource = d3d12_resource(presource);
+ threaded_resource_deinit(presource);
if (can_map_directly(presource))
util_range_destroy(&resource->valid_buffer_range);
if (resource->bo)
@@ -230,8 +231,8 @@ init_texture(struct d3d12_screen *screen,
if (screen->winsys && (templ->bind & PIPE_BIND_DISPLAY_TARGET)) {
struct sw_winsys *winsys = screen->winsys;
res->dt = winsys->displaytarget_create(screen->winsys,
- res->base.bind,
- res->base.format,
+ res->base.b.bind,
+ res->base.b.format,
templ->width0,
templ->height0,
64, NULL,
@@ -251,7 +252,7 @@ d3d12_resource_create(struct pipe_screen *pscreen,
struct d3d12_resource *res = CALLOC_STRUCT(d3d12_resource);
bool ret;
- res->base = *templ;
+ res->base.b = *templ;
if (D3D12_DEBUG_RESOURCE & d3d12_debug) {
debug_printf("D3D12: Create %sresource %s@%d %dx%dx%d as:%d mip:%d\n",
@@ -261,8 +262,8 @@ d3d12_resource_create(struct pipe_screen *pscreen,
templ->array_size, templ->last_level);
}
- pipe_reference_init(&res->base.reference, 1);
- res->base.screen = pscreen;
+ pipe_reference_init(&res->base.b.reference, 1);
+ res->base.b.screen = pscreen;
if (templ->target == PIPE_BUFFER) {
ret = init_buffer(screen, res, templ);
@@ -276,10 +277,11 @@ d3d12_resource_create(struct pipe_screen *pscreen,
}
init_valid_range(res);
+ threaded_resource_init(&res->base.b, false, 0);
memset(&res->bind_counts, 0, sizeof(d3d12_resource::bind_counts));
- return &res->base;
+ return &res->base.b;
}
static struct pipe_resource *
@@ -294,14 +296,15 @@ d3d12_resource_from_handle(struct pipe_screen *pscreen,
if (!res)
return NULL;
- res->base = *templ;
- pipe_reference_init(&res->base.reference, 1);
- res->base.screen = pscreen;
+ res->base.b = *templ;
+ pipe_reference_init(&res->base.b.reference, 1);
+ res->base.b.screen = pscreen;
res->dxgi_format = templ->target == PIPE_BUFFER ? DXGI_FORMAT_UNKNOWN :
d3d12_get_format(templ->format);
res->bo = d3d12_bo_wrap_res((ID3D12Resource *)handle->com_obj, templ->format);
init_valid_range(res);
- return &res->base;
+ threaded_resource_init(&res->base.b, false, 0);
+ return &res->base.b;
}
static bool
@@ -333,18 +336,18 @@ unsigned int
get_subresource_id(struct d3d12_resource *res, unsigned resid,
unsigned z, unsigned base_level)
{
- unsigned resource_stride = res->base.last_level + 1;
- if (res->base.target == PIPE_TEXTURE_1D_ARRAY ||
- res->base.target == PIPE_TEXTURE_2D_ARRAY)
- resource_stride *= res->base.array_size;
+ unsigned resource_stride = res->base.b.last_level + 1;
+ if (res->base.b.target == PIPE_TEXTURE_1D_ARRAY ||
+ res->base.b.target == PIPE_TEXTURE_2D_ARRAY)
+ resource_stride *= res->base.b.array_size;
- if (res->base.target == PIPE_TEXTURE_CUBE)
+ if (res->base.b.target == PIPE_TEXTURE_CUBE)
resource_stride *= 6;
- if (res->base.target == PIPE_TEXTURE_CUBE_ARRAY)
- resource_stride *= 6 * res->base.array_size;
+ if (res->base.b.target == PIPE_TEXTURE_CUBE_ARRAY)
+ resource_stride *= 6 * res->base.b.array_size;
- unsigned layer_stride = res->base.last_level + 1;
+ unsigned layer_stride = res->base.b.last_level + 1;
return resid * resource_stride + z * layer_stride +
base_level;
@@ -386,11 +389,11 @@ fill_buffer_location(struct d3d12_context *ctx,
buf_loc.PlacedFootprint.Offset += offset;
buf_loc.PlacedFootprint.Footprint.Width = ALIGN(trans->base.box.width,
- util_format_get_blockwidth(res->base.format));
+ util_format_get_blockwidth(res->base.b.format));
buf_loc.PlacedFootprint.Footprint.Height = ALIGN(trans->base.box.height,
- util_format_get_blockheight(res->base.format));
+ util_format_get_blockheight(res->base.b.format));
buf_loc.PlacedFootprint.Footprint.Depth = ALIGN(depth,
- util_format_get_blockdepth(res->base.format));
+ util_format_get_blockdepth(res->base.b.format));
buf_loc.PlacedFootprint.Footprint.RowPitch = trans->base.stride;
@@ -434,8 +437,8 @@ transfer_buf_to_image_part(struct d3d12_context *ctx,
debug_printf("D3D12: Copy %dx%dx%d + %dx%dx%d from buffer %s to image %s\n",
trans->base.box.x, trans->base.box.y, trans->base.box.z,
trans->base.box.width, trans->base.box.height, trans->base.box.depth,
- util_format_name(staging_res->base.format),
- util_format_name(res->base.format));
+ util_format_name(staging_res->base.b.format),
+ util_format_name(res->base.b.format));
}
struct copy_info copy_info;
@@ -447,7 +450,7 @@ transfer_buf_to_image_part(struct d3d12_context *ctx,
copy_info.dst_loc = fill_texture_location(res, trans, resid, z);
copy_info.dst_x = trans->base.box.x;
copy_info.dst_y = trans->base.box.y;
- copy_info.dst_z = res->base.target == PIPE_TEXTURE_CUBE ? 0 : dest_z;
+ copy_info.dst_z = res->base.b.target == PIPE_TEXTURE_CUBE ? 0 : dest_z;
copy_info.src_box = nullptr;
copy_texture_region(ctx, copy_info);
@@ -459,7 +462,7 @@ transfer_buf_to_image(struct d3d12_context *ctx,
struct d3d12_resource *staging_res,
struct d3d12_transfer *trans, int resid)
{
- if (res->base.target == PIPE_TEXTURE_3D) {
+ if (res->base.b.target == PIPE_TEXTURE_3D) {
assert(resid == 0);
transfer_buf_to_image_part(ctx, res, staging_res, trans,
0, trans->base.box.depth, 0,
@@ -497,7 +500,7 @@ transfer_image_part_to_buf(struct d3d12_context *ctx,
copy_info.dst_loc.PlacedFootprint.Offset = (z - start_layer) * trans->base.layer_stride;
copy_info.dst_x = copy_info.dst_y = copy_info.dst_z = 0;
- if (!util_texrange_covers_whole_level(&res->base, trans->base.level,
+ if (!util_texrange_covers_whole_level(&res->base.b, trans->base.level,
box->x, box->y, start_box_z,
box->width, box->height, depth)) {
src_box.left = box->x;
@@ -529,23 +532,23 @@ transfer_image_to_buf(struct d3d12_context *ctx,
debug_printf("D3D12: Copy %dx%dx%d + %dx%dx%d from %s@%d to %s\n",
trans->base.box.x, trans->base.box.y, trans->base.box.z,
trans->base.box.width, trans->base.box.height, trans->base.box.depth,
- util_format_name(res->base.format), resid,
- util_format_name(staging_res->base.format));
+ util_format_name(res->base.b.format), resid,
+ util_format_name(staging_res->base.b.format));
}
struct pipe_resource *resolved_resource = nullptr;
- if (res->base.nr_samples > 1) {
- struct pipe_resource tmpl = res->base;
+ if (res->base.b.nr_samples > 1) {
+ struct pipe_resource tmpl = res->base.b;
tmpl.nr_samples = 0;
resolved_resource = d3d12_resource_create(ctx->base.screen, &tmpl);
struct pipe_blit_info resolve_info = {};
- struct pipe_box box = {0,0,0, (int)res->base.width0, (int16_t)res->base.height0, (int16_t)res->base.depth0};
+ struct pipe_box box = {0,0,0, (int)res->base.b.width0, (int16_t)res->base.b.height0, (int16_t)res->base.b.depth0};
resolve_info.dst.resource = resolved_resource;
resolve_info.dst.box = box;
- resolve_info.dst.format = res->base.format;
- resolve_info.src.resource = &res->base;
+ resolve_info.dst.format = res->base.b.format;
+ resolve_info.src.resource = &res->base.b;
resolve_info.src.box = box;
- resolve_info.src.format = res->base.format;
+ resolve_info.src.format = res->base.b.format;
resolve_info.filter = PIPE_TEX_FILTER_NEAREST;
resolve_info.mask = util_format_get_mask(tmpl.format);
@@ -556,7 +559,7 @@ transfer_image_to_buf(struct d3d12_context *ctx,
}
- if (res->base.target == PIPE_TEXTURE_3D) {
+ if (res->base.b.target == PIPE_TEXTURE_3D) {
transfer_image_part_to_buf(ctx, res, staging_res, trans, resid,
0, 0, trans->base.box.z, trans->base.box.depth);
} else {
@@ -631,7 +634,7 @@ synchronize(struct d3d12_context *ctx,
unsigned usage,
D3D12_RANGE *range)
{
- assert(can_map_directly(&res->base));
+ assert(can_map_directly(&res->base.b));
/* Check whether that range contains valid data; if not, we might not need to sync */
if (!(usage & PIPE_MAP_UNSYNCHRONIZED) &&
@@ -648,7 +651,7 @@ synchronize(struct d3d12_context *ctx,
}
if (usage & PIPE_MAP_WRITE)
- util_range_add(&res->base, &res->valid_buffer_range,
+ util_range_add(&res->base.b, &res->valid_buffer_range,
range->Begin, range->End);
return true;
@@ -709,9 +712,9 @@ prepare_zs_layer_strides(struct d3d12_resource *res,
const struct pipe_box *box,
struct d3d12_transfer *trans)
{
- trans->base.stride = align(util_format_get_stride(res->base.format, box->width),
+ trans->base.stride = align(util_format_get_stride(res->base.b.format, box->width),
D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
- trans->base.layer_stride = util_format_get_2d_size(res->base.format,
+ trans->base.layer_stride = util_format_get_2d_size(res->base.b.format,
trans->base.stride,
box->height);
}
@@ -777,7 +780,7 @@ read_zs_surface(struct d3d12_context *ctx, struct d3d12_resource *res,
trans->data = buf;
- switch (res->base.format) {
+ switch (res->base.b.format) {
case PIPE_FORMAT_Z24_UNORM_S8_UINT:
util_format_z24_unorm_s8_uint_pack_separate(buf, trans->base.stride,
(uint32_t *)depth_ptr, trans->base.stride,
@@ -853,7 +856,7 @@ write_zs_surface(struct pipe_context *pctx, struct d3d12_resource *res,
return;
}
- switch (res->base.format) {
+ switch (res->base.b.format) {
case PIPE_FORMAT_Z24_UNORM_S8_UINT:
util_format_z32_unorm_unpack_z_32unorm((uint32_t *)depth_ptr, trans->base.stride, (uint8_t*)trans->data,
trans->base.stride, trans->base.box.width,
@@ -914,7 +917,7 @@ d3d12_transfer_map(struct pipe_context *pctx,
range.Begin = 0;
void *ptr;
- if (can_map_directly(&res->base)) {
+ if (can_map_directly(&res->base.b)) {
if (pres->target == PIPE_BUFFER) {
ptrans->stride = 0;
ptrans->layer_stride = 0;
@@ -945,12 +948,12 @@ d3d12_transfer_map(struct pipe_context *pctx,
ptrans->stride,
box->height);
- if (res->base.target != PIPE_TEXTURE_3D)
+ if (res->base.b.target != PIPE_TEXTURE_3D)
ptrans->layer_stride = align(ptrans->layer_stride,
D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT);
unsigned staging_res_size = ptrans->layer_stride * box->depth;
- if (res->base.target == PIPE_BUFFER) {
+ if (res->base.b.target == PIPE_BUFFER) {
/* To properly support ARB_map_buffer_alignment, we need to return a pointer
* that's appropriately offset from a 64-byte-aligned base address.
*/
@@ -1011,15 +1014,15 @@ d3d12_transfer_unmap(struct pipe_context *pctx,
if (trans->base.usage & PIPE_MAP_WRITE) {
assert(ptrans->box.x >= 0);
- range.Begin = res->base.target == PIPE_BUFFER ?
+ range.Begin = res->base.b.target == PIPE_BUFFER ?
(unsigned)ptrans->box.x % BUFFER_MAP_ALIGNMENT : 0;
- range.End = staging_res->base.width0 - range.Begin;
+ range.End = staging_res->base.b.width0 - range.Begin;
}
d3d12_bo_unmap(staging_res->bo, &range);
if (trans->base.usage & PIPE_MAP_WRITE) {
struct d3d12_context *ctx = d3d12_context(pctx);
- if (res->base.target == PIPE_BUFFER) {
+ if (res->base.b.target == PIPE_BUFFER) {
uint64_t dst_offset = trans->base.box.x;
uint64_t src_offset = dst_offset % BUFFER_MAP_ALIGNMENT;
transfer_buf_to_buf(ctx, staging_res, res, src_offset, dst_offset, ptrans->box.width);
@@ -1074,7 +1077,7 @@ d3d12_resource_make_writeable(struct pipe_context *pctx,
res->bo = dup_res->bo;
d3d12_bo_reference(res->bo);
- d3d12_resource_destroy(dup_res->base.screen, &dup_res->base);
+ d3d12_resource_destroy(dup_res->base.b.screen, &dup_res->base.b);
}
void
diff --git a/src/gallium/drivers/d3d12/d3d12_resource.h b/src/gallium/drivers/d3d12/d3d12_resource.h
index a71c8206f44..d2c176c9dbd 100644
--- a/src/gallium/drivers/d3d12/d3d12_resource.h
+++ b/src/gallium/drivers/d3d12/d3d12_resource.h
@@ -28,6 +28,7 @@ struct pipe_screen;
#include "d3d12_bufmgr.h"
#include "util/u_range.h"
#include "util/u_transfer.h"
+#include "util/u_threaded_context.h"
#include <directx/d3d12.h>
@@ -38,7 +39,7 @@ enum d3d12_resource_binding_type {
};
struct d3d12_resource {
- struct pipe_resource base;
+ struct threaded_resource base;
struct d3d12_bo *bo;
DXGI_FORMAT dxgi_format;
unsigned mip_levels;
diff --git a/src/gallium/drivers/d3d12/d3d12_surface.cpp b/src/gallium/drivers/d3d12/d3d12_surface.cpp
index 610c87631f2..ab74e5a342b 100644
--- a/src/gallium/drivers/d3d12/d3d12_surface.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_surface.cpp
@@ -342,7 +342,7 @@ d3d12_surface_update_pre_draw(struct d3d12_surface *surface,
}
if (!d3d12_descriptor_handle_is_allocated(&surface->uint_rtv_handle)) {
- initialize_rtv(surface->base.context, &res->base, &surface->base,
+ initialize_rtv(surface->base.context, &res->base.b, &surface->base,
&surface->uint_rtv_handle, DXGI_FORMAT_R8G8B8A8_UINT);
}
More information about the mesa-commit
mailing list