dzn: Get rid of the render pass logic
The core provides generic render-pass -> dynamic-rendering wrappers, so let's rely on them instead of implementing our own logic. Suggested-by: Jason Ekstrand <jason.ekstrand@collabora.com> Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15913>
This commit is contained in:
@@ -2100,196 +2100,6 @@ dzn_cmd_buffer_resolve_region(struct dzn_cmd_buffer *cmdbuf,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dzn_cmd_buffer_attachment_ref_transition(struct dzn_cmd_buffer *cmdbuf,
|
||||
const struct dzn_attachment_ref *att)
|
||||
{
|
||||
const struct dzn_image_view *iview =
|
||||
cmdbuf->state.render.framebuffer->attachments[att->idx];
|
||||
const struct dzn_image *image = container_of(iview->vk.image, struct dzn_image, vk);
|
||||
|
||||
if (att->before == att->during)
|
||||
return;
|
||||
|
||||
VkImageSubresourceRange subres = {
|
||||
.aspectMask = att->aspects,
|
||||
.baseMipLevel = iview->vk.base_mip_level,
|
||||
.levelCount = iview->vk.level_count,
|
||||
.baseArrayLayer = iview->vk.base_array_layer,
|
||||
.layerCount = iview->vk.layer_count,
|
||||
};
|
||||
|
||||
dzn_foreach_aspect(aspect, att->aspects) {
|
||||
for (uint32_t lvl = 0; lvl < iview->vk.level_count; lvl++) {
|
||||
for (uint32_t layer = 0; layer < iview->vk.layer_count; layer++) {
|
||||
D3D12_RESOURCE_BARRIER barrier = {
|
||||
.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
|
||||
.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE,
|
||||
.Transition = {
|
||||
.pResource = image->res,
|
||||
.Subresource =
|
||||
dzn_image_range_get_subresource_index(image, &subres, aspect, lvl, layer),
|
||||
.StateBefore = (aspect & VK_IMAGE_ASPECT_STENCIL_BIT) ? att->stencil.before : att->before,
|
||||
.StateAfter = (aspect & VK_IMAGE_ASPECT_STENCIL_BIT) ? att->stencil.during : att->during,
|
||||
},
|
||||
};
|
||||
|
||||
if (barrier.Transition.StateBefore != barrier.Transition.StateAfter)
|
||||
ID3D12GraphicsCommandList1_ResourceBarrier(cmdbuf->cmdlist, 1, &barrier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dzn_cmd_buffer_attachment_transition(struct dzn_cmd_buffer *cmdbuf,
|
||||
const struct dzn_attachment *att)
|
||||
{
|
||||
const struct dzn_image_view *iview =
|
||||
cmdbuf->state.render.framebuffer->attachments[att->idx];
|
||||
const struct dzn_image *image = container_of(iview->vk.image, struct dzn_image, vk);
|
||||
|
||||
if (att->last == att->after)
|
||||
return;
|
||||
|
||||
VkImageSubresourceRange subres = {
|
||||
.aspectMask = att->aspects,
|
||||
.baseMipLevel = iview->vk.base_mip_level,
|
||||
.levelCount = iview->vk.level_count,
|
||||
.baseArrayLayer = iview->vk.base_array_layer,
|
||||
.layerCount = iview->vk.layer_count,
|
||||
};
|
||||
|
||||
dzn_foreach_aspect(aspect, att->aspects) {
|
||||
for (uint32_t lvl = 0; lvl < iview->vk.level_count; lvl++) {
|
||||
for (uint32_t layer = 0; layer < iview->vk.layer_count; layer++) {
|
||||
D3D12_RESOURCE_BARRIER barrier = {
|
||||
.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
|
||||
.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE,
|
||||
.Transition = {
|
||||
.pResource = image->res,
|
||||
.Subresource =
|
||||
dzn_image_range_get_subresource_index(image, &subres, aspect, lvl, layer),
|
||||
.StateBefore = (aspect & VK_IMAGE_ASPECT_STENCIL_BIT) ? att->stencil.last : att->last,
|
||||
.StateAfter = (aspect & VK_IMAGE_ASPECT_STENCIL_BIT) ? att->stencil.after : att->after,
|
||||
},
|
||||
};
|
||||
|
||||
if (barrier.Transition.StateBefore != barrier.Transition.StateAfter)
|
||||
ID3D12GraphicsCommandList1_ResourceBarrier(cmdbuf->cmdlist, 1, &barrier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dzn_cmd_buffer_resolve_attachment(struct dzn_cmd_buffer *cmdbuf, uint32_t i)
|
||||
{
|
||||
const struct dzn_subpass *subpass =
|
||||
&cmdbuf->state.render.pass->subpasses[cmdbuf->state.render.subpass];
|
||||
|
||||
if (subpass->resolve[i].idx == VK_ATTACHMENT_UNUSED)
|
||||
return;
|
||||
|
||||
const struct dzn_framebuffer *framebuffer = cmdbuf->state.render.framebuffer;
|
||||
struct dzn_image_view *src = framebuffer->attachments[subpass->colors[i].idx];
|
||||
struct dzn_image *src_img = container_of(src->vk.image, struct dzn_image, vk);
|
||||
struct dzn_image_view *dst = framebuffer->attachments[subpass->resolve[i].idx];
|
||||
struct dzn_image *dst_img = container_of(dst->vk.image, struct dzn_image, vk);
|
||||
D3D12_RESOURCE_BARRIER barriers[2];
|
||||
uint32_t barrier_count = 0;
|
||||
|
||||
/* TODO: 2DArrays/3D */
|
||||
if (subpass->colors[i].during != D3D12_RESOURCE_STATE_RESOLVE_SOURCE) {
|
||||
barriers[barrier_count++] = (D3D12_RESOURCE_BARRIER) {
|
||||
.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
|
||||
.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE,
|
||||
.Transition = {
|
||||
.pResource = src_img->res,
|
||||
.Subresource = 0,
|
||||
.StateBefore = subpass->colors[i].during,
|
||||
.StateAfter = D3D12_RESOURCE_STATE_RESOLVE_SOURCE,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (subpass->resolve[i].during != D3D12_RESOURCE_STATE_RESOLVE_DEST) {
|
||||
barriers[barrier_count++] = (D3D12_RESOURCE_BARRIER) {
|
||||
.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
|
||||
.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE,
|
||||
.Transition = {
|
||||
.pResource = dst_img->res,
|
||||
.Subresource = 0,
|
||||
.StateBefore = subpass->resolve[i].during,
|
||||
.StateAfter = D3D12_RESOURCE_STATE_RESOLVE_DEST,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (barrier_count)
|
||||
ID3D12GraphicsCommandList1_ResourceBarrier(cmdbuf->cmdlist, barrier_count, barriers);
|
||||
|
||||
ID3D12GraphicsCommandList1_ResolveSubresource(cmdbuf->cmdlist, dst_img->res, 0,
|
||||
src_img->res, 0,
|
||||
dst->srv_desc.Format);
|
||||
|
||||
for (uint32_t b = 0; b < barrier_count; b++)
|
||||
DZN_SWAP(D3D12_RESOURCE_STATES, barriers[b].Transition.StateBefore, barriers[b].Transition.StateAfter);
|
||||
|
||||
if (barrier_count)
|
||||
ID3D12GraphicsCommandList1_ResourceBarrier(cmdbuf->cmdlist, barrier_count, barriers);
|
||||
}
|
||||
|
||||
static void
|
||||
dzn_cmd_buffer_begin_subpass(struct dzn_cmd_buffer *cmdbuf)
|
||||
{
|
||||
struct dzn_framebuffer *framebuffer = cmdbuf->state.render.framebuffer;
|
||||
struct dzn_render_pass *pass = cmdbuf->state.render.pass;
|
||||
const struct dzn_subpass *subpass =
|
||||
&pass->subpasses[cmdbuf->state.render.subpass];
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rt_handles[MAX_RTS] = { 0 };
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE zs_handle = { 0 };
|
||||
|
||||
for (uint32_t i = 0; i < subpass->color_count; i++) {
|
||||
if (subpass->colors[i].idx == VK_ATTACHMENT_UNUSED) continue;
|
||||
|
||||
struct dzn_image_view *iview = framebuffer->attachments[subpass->colors[i].idx];
|
||||
struct dzn_image *img = container_of(iview->vk.image, struct dzn_image, vk);
|
||||
|
||||
rt_handles[i] = dzn_cmd_buffer_get_rtv(cmdbuf, img, &iview->rtv_desc);
|
||||
}
|
||||
|
||||
if (subpass->zs.idx != VK_ATTACHMENT_UNUSED) {
|
||||
struct dzn_image_view *iview = framebuffer->attachments[subpass->zs.idx];
|
||||
struct dzn_image *img = container_of(iview->vk.image, struct dzn_image, vk);
|
||||
|
||||
zs_handle = dzn_cmd_buffer_get_dsv(cmdbuf, img, &iview->dsv_desc);
|
||||
}
|
||||
|
||||
ID3D12GraphicsCommandList1_OMSetRenderTargets(cmdbuf->cmdlist, subpass->color_count,
|
||||
subpass->color_count ? rt_handles : NULL,
|
||||
FALSE, zs_handle.ptr ? &zs_handle : NULL);
|
||||
|
||||
for (uint32_t i = 0; i < subpass->color_count; i++)
|
||||
dzn_cmd_buffer_attachment_ref_transition(cmdbuf, &subpass->colors[i]);
|
||||
for (uint32_t i = 0; i < subpass->input_count; i++)
|
||||
dzn_cmd_buffer_attachment_ref_transition(cmdbuf, &subpass->inputs[i]);
|
||||
|
||||
if (subpass->zs.idx != VK_ATTACHMENT_UNUSED)
|
||||
dzn_cmd_buffer_attachment_ref_transition(cmdbuf, &subpass->zs);
|
||||
}
|
||||
|
||||
static void
|
||||
dzn_cmd_buffer_end_subpass(struct dzn_cmd_buffer *cmdbuf)
|
||||
{
|
||||
const struct dzn_subpass *subpass =
|
||||
&cmdbuf->state.render.pass->subpasses[cmdbuf->state.render.subpass];
|
||||
|
||||
for (uint32_t i = 0; i < subpass->color_count; i++)
|
||||
dzn_cmd_buffer_resolve_attachment(cmdbuf, i);
|
||||
}
|
||||
|
||||
static void
|
||||
dzn_cmd_buffer_update_pipeline(struct dzn_cmd_buffer *cmdbuf, uint32_t bindpoint)
|
||||
{
|
||||
@@ -3380,35 +3190,23 @@ dzn_CmdClearAttachments(VkCommandBuffer commandBuffer,
|
||||
const VkClearRect *pRects)
|
||||
{
|
||||
VK_FROM_HANDLE(dzn_cmd_buffer, cmdbuf, commandBuffer);
|
||||
struct dzn_render_pass *pass = cmdbuf->state.render.pass;
|
||||
const struct dzn_subpass *subpass =
|
||||
pass ? &pass->subpasses[cmdbuf->state.render.subpass] : NULL;
|
||||
|
||||
for (unsigned i = 0; i < attachmentCount; i++) {
|
||||
struct dzn_image_view *view = NULL;
|
||||
|
||||
if (subpass) {
|
||||
uint32_t idx =
|
||||
(pAttachments[i].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) ?
|
||||
subpass->colors[pAttachments[i].colorAttachment].idx :
|
||||
subpass->zs.idx;
|
||||
|
||||
if (idx != VK_ATTACHMENT_UNUSED)
|
||||
view = cmdbuf->state.render.framebuffer->attachments[idx];
|
||||
uint32_t idx = VK_ATTACHMENT_UNUSED;
|
||||
if (pAttachments[i].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
|
||||
assert(pAttachments[i].colorAttachment < cmdbuf->state.render.attachments.color_count);
|
||||
view = cmdbuf->state.render.attachments.colors[pAttachments[i].colorAttachment].iview;
|
||||
} else {
|
||||
if (pAttachments[i].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
|
||||
assert(pAttachments[i].colorAttachment < cmdbuf->state.render.attachments.color_count);
|
||||
view = cmdbuf->state.render.attachments.colors[pAttachments[i].colorAttachment].iview;
|
||||
} else {
|
||||
if (cmdbuf->state.render.attachments.depth.iview &&
|
||||
(pAttachments[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT))
|
||||
view = cmdbuf->state.render.attachments.depth.iview;
|
||||
if (cmdbuf->state.render.attachments.depth.iview &&
|
||||
(pAttachments[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT))
|
||||
view = cmdbuf->state.render.attachments.depth.iview;
|
||||
|
||||
if (cmdbuf->state.render.attachments.stencil.iview &&
|
||||
(pAttachments[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
|
||||
assert(!view || view == cmdbuf->state.render.attachments.depth.iview);
|
||||
view = cmdbuf->state.render.attachments.stencil.iview;
|
||||
}
|
||||
if (cmdbuf->state.render.attachments.stencil.iview &&
|
||||
(pAttachments[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
|
||||
assert(view || view == cmdbuf->state.render.attachments.depth.iview);
|
||||
view = cmdbuf->state.render.attachments.stencil.iview;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3429,82 +3227,6 @@ dzn_CmdClearAttachments(VkCommandBuffer commandBuffer,
|
||||
}
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
dzn_CmdBeginRenderPass2(VkCommandBuffer commandBuffer,
|
||||
const VkRenderPassBeginInfo *pRenderPassBeginInfo,
|
||||
const VkSubpassBeginInfo *pSubpassBeginInfo)
|
||||
{
|
||||
VK_FROM_HANDLE(dzn_cmd_buffer, cmdbuf, commandBuffer);
|
||||
VK_FROM_HANDLE(dzn_render_pass, pass, pRenderPassBeginInfo->renderPass);
|
||||
VK_FROM_HANDLE(dzn_framebuffer, framebuffer, pRenderPassBeginInfo->framebuffer);
|
||||
|
||||
assert(pass->attachment_count == framebuffer->attachment_count);
|
||||
|
||||
cmdbuf->state.render.framebuffer = framebuffer;
|
||||
cmdbuf->state.render.area = (D3D12_RECT) {
|
||||
.left = pRenderPassBeginInfo->renderArea.offset.x,
|
||||
.top = pRenderPassBeginInfo->renderArea.offset.y,
|
||||
.right = (LONG)(pRenderPassBeginInfo->renderArea.offset.x + pRenderPassBeginInfo->renderArea.extent.width),
|
||||
.bottom = (LONG)(pRenderPassBeginInfo->renderArea.offset.y + pRenderPassBeginInfo->renderArea.extent.height),
|
||||
};
|
||||
|
||||
// The render area has an impact on the scissor state.
|
||||
cmdbuf->state.dirty |= DZN_CMD_DIRTY_SCISSORS;
|
||||
cmdbuf->state.render.pass = pass;
|
||||
cmdbuf->state.render.subpass = 0;
|
||||
dzn_cmd_buffer_begin_subpass(cmdbuf);
|
||||
|
||||
uint32_t clear_count =
|
||||
MIN2(pRenderPassBeginInfo->clearValueCount, framebuffer->attachment_count);
|
||||
for (int i = 0; i < clear_count; ++i) {
|
||||
VkImageAspectFlags aspectMask = 0;
|
||||
|
||||
if (vk_format_is_depth_or_stencil(pass->attachments[i].format)) {
|
||||
if (pass->attachments[i].clear.depth)
|
||||
aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
if (pass->attachments[i].clear.stencil)
|
||||
aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
} else if (pass->attachments[i].clear.color) {
|
||||
aspectMask |= VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
}
|
||||
|
||||
struct dzn_image_view *view =
|
||||
cmdbuf->state.render.framebuffer->attachments[i];
|
||||
|
||||
dzn_cmd_buffer_clear_attachment(cmdbuf, view, &pRenderPassBeginInfo->pClearValues[i],
|
||||
aspectMask, 0, ~0, 1, &cmdbuf->state.render.area);
|
||||
}
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
dzn_CmdEndRenderPass2(VkCommandBuffer commandBuffer,
|
||||
const VkSubpassEndInfo *pSubpassEndInfo)
|
||||
{
|
||||
VK_FROM_HANDLE(dzn_cmd_buffer, cmdbuf, commandBuffer);
|
||||
|
||||
dzn_cmd_buffer_end_subpass(cmdbuf);
|
||||
|
||||
for (uint32_t i = 0; i < cmdbuf->state.render.pass->attachment_count; i++)
|
||||
dzn_cmd_buffer_attachment_transition(cmdbuf, &cmdbuf->state.render.pass->attachments[i]);
|
||||
|
||||
cmdbuf->state.render.framebuffer = NULL;
|
||||
cmdbuf->state.render.pass = NULL;
|
||||
cmdbuf->state.render.subpass = 0;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
dzn_CmdNextSubpass2(VkCommandBuffer commandBuffer,
|
||||
const VkSubpassBeginInfo *pSubpassBeginInfo,
|
||||
const VkSubpassEndInfo *pSubpassEndInfo)
|
||||
{
|
||||
VK_FROM_HANDLE(dzn_cmd_buffer, cmdbuf, commandBuffer);
|
||||
|
||||
dzn_cmd_buffer_end_subpass(cmdbuf);
|
||||
assert(cmdbuf->state.render.subpass + 1 < cmdbuf->state.render.pass->subpass_count);
|
||||
cmdbuf->state.render.subpass++;
|
||||
dzn_cmd_buffer_begin_subpass(cmdbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
dzn_cmd_buffer_resolve_rendering_attachment(struct dzn_cmd_buffer *cmdbuf,
|
||||
const struct dzn_rendering_attachment *att,
|
||||
|
@@ -2520,68 +2520,6 @@ dzn_BindBufferMemory2(VkDevice _device,
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static VkResult
|
||||
dzn_framebuffer_create(struct dzn_device *device,
|
||||
const VkFramebufferCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkFramebuffer *out)
|
||||
{
|
||||
VK_MULTIALLOC(ma);
|
||||
VK_MULTIALLOC_DECL(&ma, struct dzn_framebuffer, framebuffer, 1);
|
||||
VK_MULTIALLOC_DECL(&ma, struct dzn_image_view *, attachments, pCreateInfo->attachmentCount);
|
||||
|
||||
if (!vk_multialloc_zalloc2(&ma, &device->vk.alloc, pAllocator,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT))
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
framebuffer->width = pCreateInfo->width;
|
||||
framebuffer->height = pCreateInfo->height;
|
||||
framebuffer->layers = pCreateInfo->layers;
|
||||
|
||||
framebuffer->attachments = attachments;
|
||||
framebuffer->attachment_count = pCreateInfo->attachmentCount;
|
||||
for (uint32_t i = 0; i < framebuffer->attachment_count; i++) {
|
||||
VK_FROM_HANDLE(dzn_image_view, iview, pCreateInfo->pAttachments[i]);
|
||||
framebuffer->attachments[i] = iview;
|
||||
}
|
||||
|
||||
vk_object_base_init(&device->vk, &framebuffer->base, VK_OBJECT_TYPE_FRAMEBUFFER);
|
||||
*out = dzn_framebuffer_to_handle(framebuffer);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
dzn_framebuffer_destroy(struct dzn_framebuffer *framebuffer,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
{
|
||||
if (!framebuffer)
|
||||
return;
|
||||
|
||||
struct dzn_device *device =
|
||||
container_of(framebuffer->base.device, struct dzn_device, vk);
|
||||
|
||||
vk_object_base_finish(&framebuffer->base);
|
||||
vk_free2(&device->vk.alloc, pAllocator, framebuffer);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
dzn_CreateFramebuffer(VkDevice device,
|
||||
const VkFramebufferCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkFramebuffer *pFramebuffer)
|
||||
{
|
||||
return dzn_framebuffer_create(dzn_device_from_handle(device),
|
||||
pCreateInfo, pAllocator, pFramebuffer);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
dzn_DestroyFramebuffer(VkDevice device,
|
||||
VkFramebuffer fb,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
{
|
||||
dzn_framebuffer_destroy(dzn_framebuffer_from_handle(fb), pAllocator);
|
||||
}
|
||||
|
||||
static void
|
||||
dzn_event_destroy(struct dzn_event *event,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
|
@@ -1,223 +0,0 @@
|
||||
/*
|
||||
* Copyright © Microsoft Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "dzn_private.h"
|
||||
|
||||
#include "vk_alloc.h"
|
||||
#include "vk_format.h"
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
dzn_CreateRenderPass2(VkDevice dev,
|
||||
const VkRenderPassCreateInfo2KHR *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkRenderPass *pRenderPass)
|
||||
{
|
||||
VK_FROM_HANDLE(dzn_device, device, dev);
|
||||
|
||||
VK_MULTIALLOC(ma);
|
||||
VK_MULTIALLOC_DECL(&ma, struct dzn_render_pass, pass, 1);
|
||||
VK_MULTIALLOC_DECL(&ma, struct dzn_subpass, subpasses,
|
||||
pCreateInfo->subpassCount);
|
||||
VK_MULTIALLOC_DECL(&ma, struct dzn_attachment, attachments,
|
||||
pCreateInfo->attachmentCount);
|
||||
|
||||
if (!vk_multialloc_zalloc2(&ma, &device->vk.alloc, pAllocator,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT))
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
vk_object_base_init(&device->vk, &pass->base, VK_OBJECT_TYPE_RENDER_PASS);
|
||||
pass->subpasses = subpasses;
|
||||
pass->subpass_count = pCreateInfo->subpassCount;
|
||||
pass->attachments = attachments;
|
||||
pass->attachment_count = pCreateInfo->attachmentCount;
|
||||
|
||||
assert(!pass->attachment_count || pass->attachments);
|
||||
for (uint32_t i = 0; i < pass->attachment_count; i++) {
|
||||
const VkAttachmentDescription2 *attachment = &pCreateInfo->pAttachments[i];
|
||||
|
||||
attachments[i].idx = i;
|
||||
attachments[i].format = attachment->format;
|
||||
assert(attachments[i].format);
|
||||
if (vk_format_is_depth_or_stencil(attachment->format)) {
|
||||
attachments[i].clear.depth =
|
||||
attachment->loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
attachments[i].clear.stencil =
|
||||
attachment->stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
} else {
|
||||
attachments[i].clear.color =
|
||||
attachment->loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
}
|
||||
attachments[i].samples = attachment->samples;
|
||||
if (vk_format_has_stencil(attachment->format)) {
|
||||
attachments[i].stencil.before =
|
||||
dzn_image_layout_to_state(attachment->initialLayout, VK_IMAGE_ASPECT_STENCIL_BIT);
|
||||
attachments[i].stencil.after =
|
||||
dzn_image_layout_to_state(attachment->finalLayout, VK_IMAGE_ASPECT_STENCIL_BIT);
|
||||
attachments[i].stencil.last = attachments[i].stencil.before;
|
||||
}
|
||||
|
||||
if (vk_format_has_depth(attachment->format)) {
|
||||
attachments[i].before =
|
||||
dzn_image_layout_to_state(attachment->initialLayout, VK_IMAGE_ASPECT_STENCIL_BIT);
|
||||
attachments[i].after =
|
||||
dzn_image_layout_to_state(attachment->finalLayout, VK_IMAGE_ASPECT_STENCIL_BIT);
|
||||
attachments[i].last = attachments[i].before;
|
||||
} else {
|
||||
assert(vk_format_is_color(attachment->format));
|
||||
attachments[i].before =
|
||||
dzn_image_layout_to_state(attachment->initialLayout, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
attachments[i].after =
|
||||
dzn_image_layout_to_state(attachment->finalLayout, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
attachments[i].last = attachments[i].before;
|
||||
}
|
||||
}
|
||||
|
||||
assert(subpasses);
|
||||
for (uint32_t i = 0; i < pass->subpass_count; i++) {
|
||||
const VkSubpassDescription2 *subpass = &pCreateInfo->pSubpasses[i];
|
||||
const VkSubpassDescription2 *subpass_after = NULL;
|
||||
|
||||
if (i + 1 < pass->subpass_count)
|
||||
subpass_after = &pCreateInfo->pSubpasses[i + 1];
|
||||
|
||||
for (uint32_t j = 0; j < subpass->colorAttachmentCount; j++) {
|
||||
uint32_t idx = subpass->pColorAttachments[j].attachment;
|
||||
subpasses[i].colors[j].idx = idx;
|
||||
if (idx != VK_ATTACHMENT_UNUSED) {
|
||||
subpasses[i].colors[j].aspects = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
subpasses[i].colors[j].before = attachments[idx].last;
|
||||
subpasses[i].colors[j].during =
|
||||
dzn_image_layout_to_state(subpass->pColorAttachments[j].layout,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
attachments[idx].last = subpasses[i].colors[j].during;
|
||||
attachments[idx].aspects |= VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
subpasses[i].color_count = j + 1;
|
||||
}
|
||||
|
||||
idx = subpass->pResolveAttachments ?
|
||||
subpass->pResolveAttachments[j].attachment :
|
||||
VK_ATTACHMENT_UNUSED;
|
||||
subpasses[i].resolve[j].idx = idx;
|
||||
if (idx != VK_ATTACHMENT_UNUSED) {
|
||||
subpasses[i].resolve[j].aspects = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
subpasses[i].resolve[j].before = attachments[idx].last;
|
||||
subpasses[i].resolve[j].during =
|
||||
dzn_image_layout_to_state(subpass->pResolveAttachments[j].layout,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
attachments[idx].last = subpasses[i].resolve[j].during;
|
||||
attachments[idx].aspects |= VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
subpasses[i].zs.idx = VK_ATTACHMENT_UNUSED;
|
||||
if (subpass->pDepthStencilAttachment) {
|
||||
uint32_t idx = subpass->pDepthStencilAttachment->attachment;
|
||||
subpasses[i].zs.idx = idx;
|
||||
if (idx != VK_ATTACHMENT_UNUSED) {
|
||||
subpasses[i].zs.aspects = vk_format_aspects(attachments[idx].format);
|
||||
subpasses[i].zs.before = attachments[idx].last;
|
||||
subpasses[i].zs.during = attachments[idx].last;
|
||||
subpasses[i].zs.stencil.before = attachments[idx].stencil.last;
|
||||
subpasses[i].zs.stencil.during = attachments[idx].stencil.last;
|
||||
|
||||
if (subpasses[i].zs.aspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
|
||||
subpasses[i].zs.stencil.during =
|
||||
dzn_image_layout_to_state(subpass->pDepthStencilAttachment->layout,
|
||||
VK_IMAGE_ASPECT_STENCIL_BIT);
|
||||
}
|
||||
|
||||
if (subpasses[i].zs.aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {
|
||||
subpasses[i].zs.during =
|
||||
dzn_image_layout_to_state(subpass->pDepthStencilAttachment->layout,
|
||||
VK_IMAGE_ASPECT_DEPTH_BIT);
|
||||
}
|
||||
|
||||
attachments[idx].last = subpasses[i].zs.during;
|
||||
attachments[idx].stencil.last = subpasses[i].zs.stencil.during;
|
||||
attachments[idx].aspects |= subpasses[i].zs.aspects;
|
||||
}
|
||||
}
|
||||
|
||||
subpasses[i].input_count = subpass->inputAttachmentCount;
|
||||
for (uint32_t j = 0; j < subpasses[i].input_count; j++) {
|
||||
uint32_t idx = subpass->pInputAttachments[j].attachment;
|
||||
subpasses[i].inputs[j].idx = idx;
|
||||
if (idx != VK_ATTACHMENT_UNUSED) {
|
||||
subpasses[i].inputs[j].aspects = subpass->pInputAttachments[j].aspectMask;
|
||||
subpasses[i].inputs[j].before = attachments[idx].last;
|
||||
subpasses[i].inputs[j].during = attachments[idx].last;
|
||||
subpasses[i].inputs[j].stencil.before = attachments[idx].stencil.last;
|
||||
subpasses[i].inputs[j].stencil.during = attachments[idx].stencil.last;
|
||||
|
||||
if (subpasses[i].inputs[j].aspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
|
||||
subpasses[i].inputs[j].stencil.during =
|
||||
dzn_image_layout_to_state(subpass->pInputAttachments[j].layout,
|
||||
VK_IMAGE_ASPECT_STENCIL_BIT);
|
||||
}
|
||||
|
||||
if (subpasses[i].inputs[j].aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {
|
||||
subpasses[i].inputs[j].during =
|
||||
dzn_image_layout_to_state(subpass->pInputAttachments[j].layout,
|
||||
VK_IMAGE_ASPECT_DEPTH_BIT);
|
||||
attachments[idx].last = subpasses[i].inputs[j].during;
|
||||
} else if (subpasses[i].inputs[j].aspects == VK_IMAGE_ASPECT_COLOR_BIT) {
|
||||
subpasses[i].inputs[j].during =
|
||||
dzn_image_layout_to_state(subpass->pInputAttachments[j].layout,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
}
|
||||
|
||||
attachments[idx].last = subpasses[i].inputs[j].during;
|
||||
attachments[idx].stencil.last = subpasses[i].inputs[j].stencil.during;
|
||||
attachments[idx].aspects |= subpass->pInputAttachments[j].aspectMask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*pRenderPass = dzn_render_pass_to_handle(pass);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
dzn_DestroyRenderPass(VkDevice dev,
|
||||
VkRenderPass p,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
{
|
||||
VK_FROM_HANDLE(dzn_device, device, dev);
|
||||
VK_FROM_HANDLE(dzn_render_pass, pass, p);
|
||||
|
||||
if (!pass)
|
||||
return;
|
||||
|
||||
vk_object_base_finish(&pass->base);
|
||||
vk_free2(&device->vk.alloc, pAllocator, pass);
|
||||
}
|
||||
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
dzn_GetRenderAreaGranularity(VkDevice device,
|
||||
VkRenderPass pass,
|
||||
VkExtent2D *pGranularity)
|
||||
{
|
||||
// FIXME: query the actual optimal granularity
|
||||
pGranularity->width = pGranularity->height = 1;
|
||||
}
|
@@ -780,7 +780,7 @@ dzn_graphics_pipeline_create(struct dzn_device *device,
|
||||
{
|
||||
const VkPipelineRenderingCreateInfo *ri = (const VkPipelineRenderingCreateInfo *)
|
||||
vk_find_struct_const(pCreateInfo, PIPELINE_RENDERING_CREATE_INFO);
|
||||
VK_FROM_HANDLE(dzn_render_pass, pass, pCreateInfo->renderPass);
|
||||
VK_FROM_HANDLE(vk_render_pass, pass, pCreateInfo->renderPass);
|
||||
VK_FROM_HANDLE(dzn_pipeline_layout, layout, pCreateInfo->layout);
|
||||
uint32_t color_count = 0;
|
||||
VkFormat color_fmts[MAX_RTS] = { 0 };
|
||||
@@ -846,21 +846,23 @@ dzn_graphics_pipeline_create(struct dzn_device *device,
|
||||
dzn_graphics_pipeline_translate_blend(pipeline, &desc, pCreateInfo);
|
||||
|
||||
if (pass) {
|
||||
const struct dzn_subpass *subpass = &pass->subpasses[pCreateInfo->subpass];
|
||||
const struct vk_subpass *subpass = &pass->subpasses[pCreateInfo->subpass];
|
||||
color_count = subpass->color_count;
|
||||
for (uint32_t i = 0; i < subpass->color_count; i++) {
|
||||
uint32_t idx = subpass->colors[i].idx;
|
||||
uint32_t idx = subpass->color_attachments[i].attachment;
|
||||
|
||||
if (idx == VK_ATTACHMENT_UNUSED) continue;
|
||||
|
||||
const struct dzn_attachment *attachment = &pass->attachments[idx];
|
||||
const struct vk_render_pass_attachment *attachment =
|
||||
&pass->attachments[idx];
|
||||
|
||||
color_fmts[i] = attachment->format;
|
||||
}
|
||||
|
||||
if (subpass->zs.idx != VK_ATTACHMENT_UNUSED) {
|
||||
const struct dzn_attachment *attachment =
|
||||
&pass->attachments[subpass->zs.idx];
|
||||
if (subpass->depth_stencil_attachment &&
|
||||
subpass->depth_stencil_attachment->attachment != VK_ATTACHMENT_UNUSED) {
|
||||
const struct vk_render_pass_attachment *attachment =
|
||||
&pass->attachments[subpass->depth_stencil_attachment->attachment];
|
||||
|
||||
zs_fmt = attachment->format;
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include "vk_image.h"
|
||||
#include "vk_log.h"
|
||||
#include "vk_physical_device.h"
|
||||
#include "vk_render_pass.h"
|
||||
#include "vk_sync.h"
|
||||
#include "vk_queue.h"
|
||||
#include "vk_shader_module.h"
|
||||
@@ -316,33 +317,6 @@ struct dzn_cmd_event_signal {
|
||||
|
||||
struct dzn_cmd_buffer;
|
||||
|
||||
struct dzn_attachment {
|
||||
uint32_t idx;
|
||||
VkFormat format;
|
||||
uint32_t samples;
|
||||
union {
|
||||
bool color;
|
||||
struct {
|
||||
bool depth;
|
||||
bool stencil;
|
||||
};
|
||||
} clear;
|
||||
VkImageAspectFlags aspects;
|
||||
D3D12_RESOURCE_STATES before, last, after;
|
||||
struct {
|
||||
D3D12_RESOURCE_STATES before, last, after;
|
||||
} stencil;
|
||||
};
|
||||
|
||||
struct dzn_attachment_ref {
|
||||
uint32_t idx;
|
||||
D3D12_RESOURCE_STATES before, during;
|
||||
struct {
|
||||
D3D12_RESOURCE_STATES before, during;
|
||||
} stencil;
|
||||
VkImageAspectFlags aspects;
|
||||
};
|
||||
|
||||
struct dzn_descriptor_state {
|
||||
struct {
|
||||
const struct dzn_descriptor_set *set;
|
||||
@@ -484,9 +458,6 @@ struct dzn_cmd_buffer_state {
|
||||
struct dzn_rendering_attachment colors[MAX_RTS];
|
||||
struct dzn_rendering_attachment depth, stencil;
|
||||
} attachments;
|
||||
struct dzn_render_pass *pass;
|
||||
uint32_t subpass;
|
||||
struct dzn_framebuffer *framebuffer;
|
||||
} render;
|
||||
struct {
|
||||
BITSET_DECLARE(dirty, MAX_VBS);
|
||||
@@ -685,25 +656,6 @@ struct dzn_descriptor_update_template {
|
||||
const struct dzn_descriptor_update_template_entry *entries;
|
||||
};
|
||||
|
||||
#define MAX_INPUT_ATTACHMENTS 4
|
||||
|
||||
struct dzn_subpass {
|
||||
uint32_t color_count;
|
||||
struct dzn_attachment_ref colors[MAX_RTS];
|
||||
struct dzn_attachment_ref resolve[MAX_RTS];
|
||||
struct dzn_attachment_ref zs;
|
||||
uint32_t input_count;
|
||||
struct dzn_attachment_ref inputs[MAX_INPUT_ATTACHMENTS];
|
||||
};
|
||||
|
||||
struct dzn_render_pass {
|
||||
struct vk_object_base base;
|
||||
uint32_t attachment_count;
|
||||
struct dzn_attachment *attachments;
|
||||
uint32_t subpass_count;
|
||||
struct dzn_subpass *subpasses;
|
||||
};
|
||||
|
||||
struct dzn_pipeline_cache {
|
||||
struct vk_object_base base;
|
||||
};
|
||||
@@ -918,15 +870,6 @@ struct dzn_buffer_view {
|
||||
D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc;
|
||||
};
|
||||
|
||||
struct dzn_framebuffer {
|
||||
struct vk_object_base base;
|
||||
|
||||
uint32_t width, height, layers;
|
||||
|
||||
uint32_t attachment_count;
|
||||
struct dzn_image_view **attachments;
|
||||
};
|
||||
|
||||
struct dzn_sampler {
|
||||
struct vk_object_base base;
|
||||
D3D12_SAMPLER_DESC desc;
|
||||
@@ -1050,7 +993,6 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_descriptor_set, base, VkDescriptorSet, VK_OBJ
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_descriptor_set_layout, base, VkDescriptorSetLayout, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_descriptor_update_template, base, VkDescriptorUpdateTemplate, VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_event, base, VkEvent, VK_OBJECT_TYPE_EVENT)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_framebuffer, base, VkFramebuffer, VK_OBJECT_TYPE_FRAMEBUFFER)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_image_view, vk.base, VkImageView, VK_OBJECT_TYPE_IMAGE_VIEW)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_pipeline, base, VkPipeline, VK_OBJECT_TYPE_PIPELINE)
|
||||
@@ -1059,7 +1001,6 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_compute_pipeline, base.base, VkPipeline, VK_O
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_pipeline_cache, base, VkPipelineCache, VK_OBJECT_TYPE_PIPELINE_CACHE)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_pipeline_layout, base, VkPipelineLayout, VK_OBJECT_TYPE_PIPELINE_LAYOUT)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_query_pool, base, VkQueryPool, VK_OBJECT_TYPE_QUERY_POOL)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_render_pass, base, VkRenderPass, VK_OBJECT_TYPE_RENDER_PASS)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(dzn_sampler, base, VkSampler, VK_OBJECT_TYPE_SAMPLER)
|
||||
|
||||
#endif /* DZN_PRIVATE_H */
|
||||
|
@@ -37,7 +37,6 @@ libdzn_files = files(
|
||||
'dzn_image.c',
|
||||
'dzn_meta.c',
|
||||
'dzn_nir.c',
|
||||
'dzn_pass.c',
|
||||
'dzn_pipeline_cache.c',
|
||||
'dzn_pipeline.c',
|
||||
'dzn_query.c',
|
||||
|
Reference in New Issue
Block a user