Skip to content
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
7 changes: 4 additions & 3 deletions src/dxmt/dxmt_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ Buffer::prepareAllocationViews(BufferAllocation *allocation) {
info.sample_count = 1;
info.pixel_format = format;
info.options = allocation->info_.options;
info.usage = WMTTextureUsageShaderRead;
auto usage = WMTTextureUsageShaderRead;
if (!allocation->flags().test(BufferAllocationFlag::GpuReadonly) &&
( allocation->flags().test(BufferAllocationFlag::GpuManaged) || allocation->flags().test(BufferAllocationFlag::GpuPrivate))) {
info.usage |= WMTTextureUsageShaderWrite;
usage |= WMTTextureUsageShaderWrite;
if (format == WMTPixelFormatR32Uint || format == WMTPixelFormatR32Sint ||
(format == WMTPixelFormatRG32Uint && device_.supportsFamily(WMTGPUFamilyApple8))) {
info.usage |= WMTTextureUsageShaderAtomic;
usage |= WMTTextureUsageShaderAtomic;
}
}
info.usage = usage;

auto view = allocation->obj_.newTexture(info, 0, total_length);

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