|
@@ -167,6 +167,7 @@ VkImageCreateInfo GenerateImageCreateInfo(const VKDevice& device, const SurfaceP
|
|
|
ci.extent = {params.width, params.height, 1};
|
|
ci.extent = {params.width, params.height, 1};
|
|
|
break;
|
|
break;
|
|
|
case SurfaceTarget::Texture3D:
|
|
case SurfaceTarget::Texture3D:
|
|
|
|
|
+ ci.flags |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT;
|
|
|
ci.extent = {params.width, params.height, params.depth};
|
|
ci.extent = {params.width, params.height, params.depth};
|
|
|
break;
|
|
break;
|
|
|
case SurfaceTarget::TextureBuffer:
|
|
case SurfaceTarget::TextureBuffer:
|
|
@@ -176,6 +177,12 @@ VkImageCreateInfo GenerateImageCreateInfo(const VKDevice& device, const SurfaceP
|
|
|
return ci;
|
|
return ci;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+u32 EncodeSwizzle(Tegra::Texture::SwizzleSource x_source, Tegra::Texture::SwizzleSource y_source,
|
|
|
|
|
+ Tegra::Texture::SwizzleSource z_source, Tegra::Texture::SwizzleSource w_source) {
|
|
|
|
|
+ return (static_cast<u32>(x_source) << 24) | (static_cast<u32>(y_source) << 16) |
|
|
|
|
|
+ (static_cast<u32>(z_source) << 8) | static_cast<u32>(w_source);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
} // Anonymous namespace
|
|
} // Anonymous namespace
|
|
|
|
|
|
|
|
CachedSurface::CachedSurface(Core::System& system, const VKDevice& device,
|
|
CachedSurface::CachedSurface(Core::System& system, const VKDevice& device,
|
|
@@ -203,9 +210,11 @@ CachedSurface::CachedSurface(Core::System& system, const VKDevice& device,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// TODO(Rodrigo): Move this to a virtual function.
|
|
// TODO(Rodrigo): Move this to a virtual function.
|
|
|
- main_view = CreateViewInner(
|
|
|
|
|
- ViewParams(params.target, 0, static_cast<u32>(params.GetNumLayers()), 0, params.num_levels),
|
|
|
|
|
- true);
|
|
|
|
|
|
|
+ u32 num_layers = 1;
|
|
|
|
|
+ if (params.is_layered || params.target == SurfaceTarget::Texture3D) {
|
|
|
|
|
+ num_layers = params.depth;
|
|
|
|
|
+ }
|
|
|
|
|
+ main_view = CreateView(ViewParams(params.target, 0, num_layers, 0, params.num_levels));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
CachedSurface::~CachedSurface() = default;
|
|
CachedSurface::~CachedSurface() = default;
|
|
@@ -253,12 +262,8 @@ void CachedSurface::DecorateSurfaceName() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
View CachedSurface::CreateView(const ViewParams& params) {
|
|
View CachedSurface::CreateView(const ViewParams& params) {
|
|
|
- return CreateViewInner(params, false);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-View CachedSurface::CreateViewInner(const ViewParams& params, bool is_proxy) {
|
|
|
|
|
// TODO(Rodrigo): Add name decorations
|
|
// TODO(Rodrigo): Add name decorations
|
|
|
- return views[params] = std::make_shared<CachedSurfaceView>(device, *this, params, is_proxy);
|
|
|
|
|
|
|
+ return views[params] = std::make_shared<CachedSurfaceView>(device, *this, params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void CachedSurface::UploadBuffer(const std::vector<u8>& staging_buffer) {
|
|
void CachedSurface::UploadBuffer(const std::vector<u8>& staging_buffer) {
|
|
@@ -342,18 +347,27 @@ VkImageSubresourceRange CachedSurface::GetImageSubresourceRange() const {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
CachedSurfaceView::CachedSurfaceView(const VKDevice& device, CachedSurface& surface,
|
|
CachedSurfaceView::CachedSurfaceView(const VKDevice& device, CachedSurface& surface,
|
|
|
- const ViewParams& params, bool is_proxy)
|
|
|
|
|
|
|
+ const ViewParams& params)
|
|
|
: VideoCommon::ViewBase{params}, params{surface.GetSurfaceParams()},
|
|
: VideoCommon::ViewBase{params}, params{surface.GetSurfaceParams()},
|
|
|
image{surface.GetImageHandle()}, buffer_view{surface.GetBufferViewHandle()},
|
|
image{surface.GetImageHandle()}, buffer_view{surface.GetBufferViewHandle()},
|
|
|
aspect_mask{surface.GetAspectMask()}, device{device}, surface{surface},
|
|
aspect_mask{surface.GetAspectMask()}, device{device}, surface{surface},
|
|
|
- base_layer{params.base_layer}, num_layers{params.num_layers}, base_level{params.base_level},
|
|
|
|
|
- num_levels{params.num_levels}, image_view_type{image ? GetImageViewType(params.target)
|
|
|
|
|
- : VK_IMAGE_VIEW_TYPE_1D} {}
|
|
|
|
|
|
|
+ base_level{params.base_level}, num_levels{params.num_levels},
|
|
|
|
|
+ image_view_type{image ? GetImageViewType(params.target) : VK_IMAGE_VIEW_TYPE_1D} {
|
|
|
|
|
+ if (image_view_type == VK_IMAGE_VIEW_TYPE_3D) {
|
|
|
|
|
+ base_layer = 0;
|
|
|
|
|
+ num_layers = 1;
|
|
|
|
|
+ base_slice = params.base_layer;
|
|
|
|
|
+ num_slices = params.num_layers;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ base_layer = params.base_layer;
|
|
|
|
|
+ num_layers = params.num_layers;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
CachedSurfaceView::~CachedSurfaceView() = default;
|
|
CachedSurfaceView::~CachedSurfaceView() = default;
|
|
|
|
|
|
|
|
-VkImageView CachedSurfaceView::GetHandle(SwizzleSource x_source, SwizzleSource y_source,
|
|
|
|
|
- SwizzleSource z_source, SwizzleSource w_source) {
|
|
|
|
|
|
|
+VkImageView CachedSurfaceView::GetImageView(SwizzleSource x_source, SwizzleSource y_source,
|
|
|
|
|
+ SwizzleSource z_source, SwizzleSource w_source) {
|
|
|
const u32 new_swizzle = EncodeSwizzle(x_source, y_source, z_source, w_source);
|
|
const u32 new_swizzle = EncodeSwizzle(x_source, y_source, z_source, w_source);
|
|
|
if (last_image_view && last_swizzle == new_swizzle) {
|
|
if (last_image_view && last_swizzle == new_swizzle) {
|
|
|
return last_image_view;
|
|
return last_image_view;
|
|
@@ -399,6 +413,11 @@ VkImageView CachedSurfaceView::GetHandle(SwizzleSource x_source, SwizzleSource y
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (image_view_type == VK_IMAGE_VIEW_TYPE_3D) {
|
|
|
|
|
+ ASSERT(base_slice == 0);
|
|
|
|
|
+ ASSERT(num_slices == params.depth);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
VkImageViewCreateInfo ci;
|
|
VkImageViewCreateInfo ci;
|
|
|
ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
|
ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
|
|
ci.pNext = nullptr;
|
|
ci.pNext = nullptr;
|
|
@@ -417,6 +436,35 @@ VkImageView CachedSurfaceView::GetHandle(SwizzleSource x_source, SwizzleSource y
|
|
|
return last_image_view = *image_view;
|
|
return last_image_view = *image_view;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+VkImageView CachedSurfaceView::GetAttachment() {
|
|
|
|
|
+ if (render_target) {
|
|
|
|
|
+ return *render_target;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ VkImageViewCreateInfo ci;
|
|
|
|
|
+ ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
|
|
|
|
+ ci.pNext = nullptr;
|
|
|
|
|
+ ci.flags = 0;
|
|
|
|
|
+ ci.image = surface.GetImageHandle();
|
|
|
|
|
+ ci.format = surface.GetImage().GetFormat();
|
|
|
|
|
+ ci.components = {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
|
|
|
+ VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY};
|
|
|
|
|
+ ci.subresourceRange.aspectMask = aspect_mask;
|
|
|
|
|
+ ci.subresourceRange.baseMipLevel = base_level;
|
|
|
|
|
+ ci.subresourceRange.levelCount = num_levels;
|
|
|
|
|
+ if (image_view_type == VK_IMAGE_VIEW_TYPE_3D) {
|
|
|
|
|
+ ci.viewType = num_slices > 1 ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
|
+ ci.subresourceRange.baseArrayLayer = base_slice;
|
|
|
|
|
+ ci.subresourceRange.layerCount = num_slices;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ci.viewType = image_view_type;
|
|
|
|
|
+ ci.subresourceRange.baseArrayLayer = base_layer;
|
|
|
|
|
+ ci.subresourceRange.layerCount = num_layers;
|
|
|
|
|
+ }
|
|
|
|
|
+ render_target = device.GetLogical().CreateImageView(ci);
|
|
|
|
|
+ return *render_target;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
VKTextureCache::VKTextureCache(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
|
|
VKTextureCache::VKTextureCache(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
|
|
|
const VKDevice& device, VKResourceManager& resource_manager,
|
|
const VKDevice& device, VKResourceManager& resource_manager,
|
|
|
VKMemoryManager& memory_manager, VKScheduler& scheduler,
|
|
VKMemoryManager& memory_manager, VKScheduler& scheduler,
|