summaryrefslogtreecommitdiff
path: root/src/video_core/renderer_vulkan
diff options
context:
space:
mode:
authorGravatar Feng Chen2023-01-05 12:28:48 +0800
committerGravatar Feng Chen2023-01-05 12:41:33 +0800
commit013b6891531b37e0f882b8b88d404feb63370617 (patch)
treecbfeebc7a015f15004028056c8932c000201e1fc /src/video_core/renderer_vulkan
parentvideo_core: Implement maxwell3d draw texture method (diff)
downloadyuzu-013b6891531b37e0f882b8b88d404feb63370617.tar.gz
yuzu-013b6891531b37e0f882b8b88d404feb63370617.tar.xz
yuzu-013b6891531b37e0f882b8b88d404feb63370617.zip
video_core: Implement opengl/vulkan draw_texture
Diffstat (limited to 'src/video_core/renderer_vulkan')
-rw-r--r--src/video_core/renderer_vulkan/blit_image.cpp41
-rw-r--r--src/video_core/renderer_vulkan/blit_image.h6
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.cpp28
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.h1
4 files changed, 69 insertions, 7 deletions
diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp
index 3f2b139e0..d728e5c6c 100644
--- a/src/video_core/renderer_vulkan/blit_image.cpp
+++ b/src/video_core/renderer_vulkan/blit_image.cpp
@@ -4,13 +4,13 @@
4#include <algorithm> 4#include <algorithm>
5 5
6#include "common/settings.h" 6#include "common/settings.h"
7#include "video_core/host_shaders/blit_color_float_frag_spv.h"
7#include "video_core/host_shaders/convert_abgr8_to_d24s8_frag_spv.h" 8#include "video_core/host_shaders/convert_abgr8_to_d24s8_frag_spv.h"
8#include "video_core/host_shaders/convert_d24s8_to_abgr8_frag_spv.h" 9#include "video_core/host_shaders/convert_d24s8_to_abgr8_frag_spv.h"
9#include "video_core/host_shaders/convert_depth_to_float_frag_spv.h" 10#include "video_core/host_shaders/convert_depth_to_float_frag_spv.h"
10#include "video_core/host_shaders/convert_float_to_depth_frag_spv.h" 11#include "video_core/host_shaders/convert_float_to_depth_frag_spv.h"
11#include "video_core/host_shaders/convert_s8d24_to_abgr8_frag_spv.h" 12#include "video_core/host_shaders/convert_s8d24_to_abgr8_frag_spv.h"
12#include "video_core/host_shaders/full_screen_triangle_vert_spv.h" 13#include "video_core/host_shaders/full_screen_triangle_vert_spv.h"
13#include "video_core/host_shaders/vulkan_blit_color_float_frag_spv.h"
14#include "video_core/host_shaders/vulkan_blit_depth_stencil_frag_spv.h" 14#include "video_core/host_shaders/vulkan_blit_depth_stencil_frag_spv.h"
15#include "video_core/renderer_vulkan/blit_image.h" 15#include "video_core/renderer_vulkan/blit_image.h"
16#include "video_core/renderer_vulkan/maxwell_to_vk.h" 16#include "video_core/renderer_vulkan/maxwell_to_vk.h"
@@ -303,7 +303,7 @@ void UpdateTwoTexturesDescriptorSet(const Device& device, VkDescriptorSet descri
303} 303}
304 304
305void BindBlitState(vk::CommandBuffer cmdbuf, VkPipelineLayout layout, const Region2D& dst_region, 305void BindBlitState(vk::CommandBuffer cmdbuf, VkPipelineLayout layout, const Region2D& dst_region,
306 const Region2D& src_region) { 306 const Region2D& src_region, const Extent3D& src_size = {1, 1, 1}) {
307 const VkOffset2D offset{ 307 const VkOffset2D offset{
308 .x = std::min(dst_region.start.x, dst_region.end.x), 308 .x = std::min(dst_region.start.x, dst_region.end.x),
309 .y = std::min(dst_region.start.y, dst_region.end.y), 309 .y = std::min(dst_region.start.y, dst_region.end.y),
@@ -325,12 +325,15 @@ void BindBlitState(vk::CommandBuffer cmdbuf, VkPipelineLayout layout, const Regi
325 .offset = offset, 325 .offset = offset,
326 .extent = extent, 326 .extent = extent,
327 }; 327 };
328 const float scale_x = static_cast<float>(src_region.end.x - src_region.start.x); 328 const float scale_x = static_cast<float>(src_region.end.x - src_region.start.x) /
329 const float scale_y = static_cast<float>(src_region.end.y - src_region.start.y); 329 static_cast<float>(src_size.width);
330 const float scale_y = static_cast<float>(src_region.end.y - src_region.start.y) /
331 static_cast<float>(src_size.height);
330 const PushConstants push_constants{ 332 const PushConstants push_constants{
331 .tex_scale = {scale_x, scale_y}, 333 .tex_scale = {scale_x, scale_y},
332 .tex_offset = {static_cast<float>(src_region.start.x), 334 .tex_offset = {static_cast<float>(src_region.start.x) / static_cast<float>(src_size.width),
333 static_cast<float>(src_region.start.y)}, 335 static_cast<float>(src_region.start.y) /
336 static_cast<float>(src_size.height)},
334 }; 337 };
335 cmdbuf.SetViewport(0, viewport); 338 cmdbuf.SetViewport(0, viewport);
336 cmdbuf.SetScissor(0, scissor); 339 cmdbuf.SetScissor(0, scissor);
@@ -365,7 +368,7 @@ BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,
365 two_textures_pipeline_layout(device.GetLogical().CreatePipelineLayout( 368 two_textures_pipeline_layout(device.GetLogical().CreatePipelineLayout(
366 PipelineLayoutCreateInfo(two_textures_set_layout.address()))), 369 PipelineLayoutCreateInfo(two_textures_set_layout.address()))),
367 full_screen_vert(BuildShader(device, FULL_SCREEN_TRIANGLE_VERT_SPV)), 370 full_screen_vert(BuildShader(device, FULL_SCREEN_TRIANGLE_VERT_SPV)),
368 blit_color_to_color_frag(BuildShader(device, VULKAN_BLIT_COLOR_FLOAT_FRAG_SPV)), 371 blit_color_to_color_frag(BuildShader(device, BLIT_COLOR_FLOAT_FRAG_SPV)),
369 blit_depth_stencil_frag(BuildShader(device, VULKAN_BLIT_DEPTH_STENCIL_FRAG_SPV)), 372 blit_depth_stencil_frag(BuildShader(device, VULKAN_BLIT_DEPTH_STENCIL_FRAG_SPV)),
370 convert_depth_to_float_frag(BuildShader(device, CONVERT_DEPTH_TO_FLOAT_FRAG_SPV)), 373 convert_depth_to_float_frag(BuildShader(device, CONVERT_DEPTH_TO_FLOAT_FRAG_SPV)),
371 convert_float_to_depth_frag(BuildShader(device, CONVERT_FLOAT_TO_DEPTH_FRAG_SPV)), 374 convert_float_to_depth_frag(BuildShader(device, CONVERT_FLOAT_TO_DEPTH_FRAG_SPV)),
@@ -404,6 +407,30 @@ void BlitImageHelper::BlitColor(const Framebuffer* dst_framebuffer, VkImageView
404 scheduler.InvalidateState(); 407 scheduler.InvalidateState();
405} 408}
406 409
410void BlitImageHelper::BlitColor(const Framebuffer* dst_framebuffer, VkImageView src_image_view,
411 VkSampler src_sampler, const Region2D& dst_region,
412 const Region2D& src_region, const Extent3D& src_size) {
413 const BlitImagePipelineKey key{
414 .renderpass = dst_framebuffer->RenderPass(),
415 .operation = Tegra::Engines::Fermi2D::Operation::SrcCopy,
416 };
417 const VkPipelineLayout layout = *one_texture_pipeline_layout;
418 const VkPipeline pipeline = FindOrEmplaceColorPipeline(key);
419 scheduler.RequestRenderpass(dst_framebuffer);
420 scheduler.Record([this, dst_region, src_region, src_size, pipeline, layout, src_sampler,
421 src_image_view](vk::CommandBuffer cmdbuf) {
422 // TODO: Barriers
423 const VkDescriptorSet descriptor_set = one_texture_descriptor_allocator.Commit();
424 UpdateOneTextureDescriptorSet(device, descriptor_set, src_sampler, src_image_view);
425 cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
426 cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set,
427 nullptr);
428 BindBlitState(cmdbuf, layout, dst_region, src_region, src_size);
429 cmdbuf.Draw(3, 1, 0, 0);
430 });
431 scheduler.InvalidateState();
432}
433
407void BlitImageHelper::BlitDepthStencil(const Framebuffer* dst_framebuffer, 434void BlitImageHelper::BlitDepthStencil(const Framebuffer* dst_framebuffer,
408 VkImageView src_depth_view, VkImageView src_stencil_view, 435 VkImageView src_depth_view, VkImageView src_stencil_view,
409 const Region2D& dst_region, const Region2D& src_region, 436 const Region2D& dst_region, const Region2D& src_region,
diff --git a/src/video_core/renderer_vulkan/blit_image.h b/src/video_core/renderer_vulkan/blit_image.h
index 5df679fb4..e2db33f56 100644
--- a/src/video_core/renderer_vulkan/blit_image.h
+++ b/src/video_core/renderer_vulkan/blit_image.h
@@ -10,6 +10,8 @@
10 10
11namespace Vulkan { 11namespace Vulkan {
12 12
13using VideoCommon::Extent3D;
14using VideoCommon::Offset2D;
13using VideoCommon::Region2D; 15using VideoCommon::Region2D;
14 16
15class Device; 17class Device;
@@ -36,6 +38,10 @@ public:
36 Tegra::Engines::Fermi2D::Filter filter, 38 Tegra::Engines::Fermi2D::Filter filter,
37 Tegra::Engines::Fermi2D::Operation operation); 39 Tegra::Engines::Fermi2D::Operation operation);
38 40
41 void BlitColor(const Framebuffer* dst_framebuffer, VkImageView src_image_view,
42 VkSampler src_sampler, const Region2D& dst_region, const Region2D& src_region,
43 const Extent3D& src_size);
44
39 void BlitDepthStencil(const Framebuffer* dst_framebuffer, VkImageView src_depth_view, 45 void BlitDepthStencil(const Framebuffer* dst_framebuffer, VkImageView src_depth_view,
40 VkImageView src_stencil_view, const Region2D& dst_region, 46 VkImageView src_stencil_view, const Region2D& dst_region,
41 const Region2D& src_region, Tegra::Engines::Fermi2D::Filter filter, 47 const Region2D& src_region, Tegra::Engines::Fermi2D::Filter filter,
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
index 242bf9602..153096fa4 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
@@ -265,6 +265,34 @@ void RasterizerVulkan::DrawIndirect() {
265 buffer_cache.SetDrawIndirect(nullptr); 265 buffer_cache.SetDrawIndirect(nullptr);
266} 266}
267 267
268void RasterizerVulkan::DrawTexture() {
269 MICROPROFILE_SCOPE(Vulkan_Drawing);
270
271 SCOPE_EXIT({ gpu.TickWork(); });
272 FlushWork();
273
274 query_cache.UpdateCounters();
275
276 texture_cache.SynchronizeGraphicsDescriptors();
277 texture_cache.UpdateRenderTargets(false);
278
279 UpdateDynamicStates();
280
281 const auto& draw_texture_state = maxwell3d->draw_manager->GetDrawTextureState();
282 const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler);
283 const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture);
284 Region2D dst_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x0),
285 .y = static_cast<s32>(draw_texture_state.dst_y0)},
286 Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x1),
287 .y = static_cast<s32>(draw_texture_state.dst_y1)}};
288 Region2D src_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.src_x0),
289 .y = static_cast<s32>(draw_texture_state.src_y0)},
290 Offset2D{.x = static_cast<s32>(draw_texture_state.src_x1),
291 .y = static_cast<s32>(draw_texture_state.src_y1)}};
292 blit_image.BlitColor(texture_cache.GetFramebuffer(), texture.RenderTarget(), sampler->Handle(),
293 dst_region, src_region, texture.size);
294}
295
268void RasterizerVulkan::Clear(u32 layer_count) { 296void RasterizerVulkan::Clear(u32 layer_count) {
269 MICROPROFILE_SCOPE(Vulkan_Clearing); 297 MICROPROFILE_SCOPE(Vulkan_Clearing);
270 298
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h
index c661e5b19..deb44dcaa 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.h
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.h
@@ -66,6 +66,7 @@ public:
66 66
67 void Draw(bool is_indexed, u32 instance_count) override; 67 void Draw(bool is_indexed, u32 instance_count) override;
68 void DrawIndirect() override; 68 void DrawIndirect() override;
69 void DrawTexture() override;
69 void Clear(u32 layer_count) override; 70 void Clear(u32 layer_count) override;
70 void DispatchCompute() override; 71 void DispatchCompute() override;
71 void ResetCounter(VideoCore::QueryType type) override; 72 void ResetCounter(VideoCore::QueryType type) override;