Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 20 additions & 32 deletions src/d3d11/d3d11_context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ template <typename ContextInternalState> class MTLD3D11DeviceContextImplBase : p
EmitOP([=, texture = pUAV->texture(), viewId = pUAV->viewId(),
value = std::array<uint32_t, 4>({Values[0], Values[1], Values[2], Values[3]}),
dimension = desc.ViewDimension](ArgumentEncodingContext &enc) mutable {
auto view_format = texture->view(viewId).pixelFormat();
auto view_format = texture->pixelFormat(viewId);
auto uint_format = MTLGetUnsignedIntegerFormat((WMTPixelFormat)view_format);
/* RG11B10Float is a special case */
if (view_format == WMTPixelFormatRG11B10Float) {
Expand Down Expand Up @@ -937,7 +937,7 @@ template <typename ContextInternalState> class MTLD3D11DeviceContextImplBase : p
if (tex->pixelFormat(viewId) == WMTPixelFormatA8Unorm) {
fixedViewId = tex->checkViewUseFormat(viewId, WMTPixelFormatR8Unorm);
}
WMT::Texture texture = enc.access(tex, fixedViewId, DXMT_ENCODER_RESOURCE_ACESS_READ | DXMT_ENCODER_RESOURCE_ACESS_WRITE).texture;
WMT::Texture texture = enc.access(tex, fixedViewId, DXMT_ENCODER_RESOURCE_ACESS_READWRITE).texture;
if (texture.mipmapLevelCount() > 1) {
auto &cmd = enc.encodeBlitCommand<wmtcmd_blit_generate_mipmaps>();
cmd.type = WMTBlitCommandGenerateMipmaps;
Expand Down Expand Up @@ -3908,7 +3908,7 @@ template <typename ContextInternalState> class MTLD3D11DeviceContextImplBase : p

SwitchToBlitEncoder(CommandBufferState::UpdateBlitEncoderActive);
EmitOP([=, src = std::move(src), dst = std::move(dst), cmd = std::move(cmd)](ArgumentEncodingContext &enc) {
auto [src_buffer, src_offset] = enc.access(src, DXMT_ENCODER_RESOURCE_ACESS_READ);
auto [src_buffer, src_offset] = enc.access(src, 0, src->length(), DXMT_ENCODER_RESOURCE_ACESS_READ);
auto texture = enc.access(dst, cmd.Dst.MipLevel, cmd.Dst.ArraySlice, DXMT_ENCODER_RESOURCE_ACESS_WRITE);
auto &cmd_cptex = enc.encodeBlitCommand<wmtcmd_blit_copy_from_buffer_to_texture>();
cmd_cptex.type = WMTBlitCommandCopyFromBufferToTexture;
Expand Down Expand Up @@ -4156,34 +4156,36 @@ template <typename ContextInternalState> class MTLD3D11DeviceContextImplBase : p
render_target_array, encoder_argbuf_size = std::move(allocated_encoder_argbuf_size)](ArgumentEncodingContext &ctx) {
auto pool = WMT::MakeAutoreleasePool();
uint32_t dsv_planar_flags = DepthStencilPlanarFlags(dsv.PixelFormat);
auto& info = ctx.startRenderPass(dsv_planar_flags, dsv.ReadOnlyFlags, rtvs.size(), *encoder_argbuf_size.get())->info;
auto& info = *ctx.startRenderPass(dsv_planar_flags, dsv.ReadOnlyFlags, rtvs.size(), *encoder_argbuf_size.get());

for (auto &rtv : rtvs.span()) {
if (rtv.PixelFormat == WMTPixelFormatInvalid) {
continue;
}
auto& colorAttachment = info.colors[rtv.RenderTargetIndex];
colorAttachment.texture = rtv.Texture->view(rtv.viewId);
colorAttachment.depth_plane = rtv.DepthPlane;
colorAttachment.load_action = rtv.LoadAction;
colorAttachment.store_action = WMTStoreActionStore;
auto &color = info.colors[rtv.RenderTargetIndex];
color.attachment = ctx.access(rtv.Texture, rtv.viewId, DXMT_ENCODER_RESOURCE_ACESS_READWRITE);
color.depth_plane = rtv.DepthPlane;
color.load_action = rtv.LoadAction;
color.store_action = WMTStoreActionStore;
};

if (dsv.Texture.ptr()) {
WMT::Texture texture = dsv.Texture->view(dsv.viewId);
auto access_flag = ((dsv.ReadOnlyFlags & dsv_planar_flags) == dsv_planar_flags)
? DXMT_ENCODER_RESOURCE_ACESS_READ
: DXMT_ENCODER_RESOURCE_ACESS_READWRITE;
// TODO: ...should know more about store behavior (e.g. DiscardView)
if (dsv_planar_flags & 1) {
auto& depthAttachment = info.depth;
depthAttachment.texture = texture;
depthAttachment.load_action = dsv.DepthLoadAction;
depthAttachment.store_action = WMTStoreActionStore;
auto &depth = info.depth;
depth.attachment = ctx.access(dsv.Texture, dsv.viewId, access_flag);
depth.load_action = dsv.DepthLoadAction;
depth.store_action = WMTStoreActionStore;
}

if (dsv_planar_flags & 2) {
auto& stencilAttachment = info.stencil;
stencilAttachment.texture = texture;
stencilAttachment.load_action = dsv.StencilLoadAction;
stencilAttachment.store_action = WMTStoreActionStore;
auto &stencil = info.stencil;
stencil.attachment = ctx.access(dsv.Texture, dsv.viewId, access_flag);
stencil.load_action = dsv.StencilLoadAction;
stencil.store_action = WMTStoreActionStore;
}
}
if (effective_render_target == 0) {
Expand All @@ -4195,20 +4197,6 @@ template <typename ContextInternalState> class MTLD3D11DeviceContextImplBase : p
info.render_target_height = render_target_height;
info.render_target_width = render_target_width;
info.render_target_array_length = render_target_array;

for (auto &rtv : rtvs.span()) {
if (rtv.PixelFormat == WMTPixelFormatInvalid) {
continue;
}
ctx.access(rtv.Texture, rtv.viewId, DXMT_ENCODER_RESOURCE_ACESS_READ | DXMT_ENCODER_RESOURCE_ACESS_WRITE);
};

if (dsv.Texture.ptr()) {
if ((dsv.ReadOnlyFlags & dsv_planar_flags) == dsv_planar_flags)
ctx.access(dsv.Texture, dsv.viewId, DXMT_ENCODER_RESOURCE_ACESS_READ);
else
ctx.access(dsv.Texture, dsv.viewId, DXMT_ENCODER_RESOURCE_ACESS_READ | DXMT_ENCODER_RESOURCE_ACESS_WRITE);
}
});
}

Expand Down
16 changes: 8 additions & 8 deletions src/dxmt/dxmt_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,17 @@ ClearRenderTargetContext::begin(Rc<Texture> texture, TextureViewKey view) {
auto width = texture->width(view);
auto height = texture->height(view);
auto array_length = texture->arrayLength(view);
auto &pass_info = ctx_.startRenderPass(dsv_flag, 0, 1, 0)->info;
auto &pass_info = *ctx_.startRenderPass(dsv_flag, 0, 1, 0);

if (dsv_flag) {
auto &depth = pass_info.depth;
depth.texture = ctx_.access(texture, view, DXMT_ENCODER_RESOURCE_ACESS_WRITE).texture;
depth.attachment = ctx_.access(texture, view, DXMT_ENCODER_RESOURCE_ACESS_WRITE);
depth.depth_plane = 0;
depth.load_action = WMTLoadActionLoad;
depth.store_action = WMTStoreActionStore;
} else {
auto &color = pass_info.colors[0];
color.texture = ctx_.access(texture, view, DXMT_ENCODER_RESOURCE_ACESS_WRITE).texture;
color.attachment = ctx_.access(texture, view, DXMT_ENCODER_RESOURCE_ACESS_WRITE);
color.depth_plane = 0;
color.load_action = WMTLoadActionLoad;
color.store_action = WMTStoreActionStore;
Expand Down Expand Up @@ -242,7 +242,7 @@ ClearRenderTargetContext::clear(
draw.vertex_start = 0;
draw.vertex_count = 3;
draw.base_instance = 0;
draw.instance_count = ctx_.currentRenderEncoder()->info.render_target_array_length;
draw.instance_count = ctx_.currentRenderEncoder()->render_target_array_length;
}

void
Expand Down Expand Up @@ -343,15 +343,15 @@ DepthStencilBlitContext::copyFromBuffer(

auto width = depth_stencil->width(view);
auto height = depth_stencil->height(view);
auto &pass_info = ctx_.startRenderPass(0b11, 0, 0, 0)->info;
auto &pass_info = *ctx_.startRenderPass(0b11, 0, 0, 0);
auto &depth = pass_info.depth;
depth.texture = ctx_.access(depth_stencil, view, DXMT_ENCODER_RESOURCE_ACESS_WRITE).texture;
depth.attachment = ctx_.access(depth_stencil, view, DXMT_ENCODER_RESOURCE_ACESS_WRITE);
depth.depth_plane = 0;
depth.load_action = WMTLoadActionLoad;
depth.store_action = WMTStoreActionStore;

auto &stencil = pass_info.stencil;
stencil.texture = depth.texture;
stencil.attachment = ctx_.access(depth_stencil, view, DXMT_ENCODER_RESOURCE_ACESS_WRITE);
stencil.depth_plane = 0;
stencil.load_action = WMTLoadActionLoad;
stencil.store_action = WMTStoreActionStore;
Expand Down Expand Up @@ -583,7 +583,7 @@ ClearResourceKernelContext::clear(uint32_t offset_x, uint32_t offset_y, uint32_t
meta_temp_.size[1] = height;

if (clearing_texture_) {
auto dst_ = ctx_.access(clearing_texture_, clearing_view_, DXMT_ENCODER_RESOURCE_ACESS_WRITE);
auto &dst_ = ctx_.access(clearing_texture_, clearing_view_, DXMT_ENCODER_RESOURCE_ACESS_WRITE);
auto &settex = ctx_.encodeComputeCommand<wmtcmd_compute_settexture>();
settex.type = WMTComputeCommandSetTexture;
settex.texture = dst_.texture;
Expand Down
Loading