Quake II RTX doxygen  1.0 dev
mgpu.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 2019, NVIDIA CORPORATION. All rights reserved.
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 
19 #include "vkpt.h"
20 
21 #ifdef VKPT_DEVICE_GROUPS
22 
23 // performs a global memory barrier across all GPUs in the DG
24 void
25 vkpt_mgpu_global_barrier(VkCommandBuffer cmd_buf)
26 {
27  if (qvk.device_count == 1) {
28  return;
29  }
30 
31  VkMemoryBarrier mem_barrier = {
32  .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
33  .pNext = NULL,
34  .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
35  .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT
36  };
37 
38  vkCmdPipelineBarrier(cmd_buf,
39  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
40  VK_DEPENDENCY_DEVICE_GROUP_BIT,
41  1, &mem_barrier,
42  0, NULL,
43  0, NULL);
44 }
45 
46 void
47 vkpt_mgpu_image_copy(VkCommandBuffer cmd_buf,
48  int src_image_index,
49  int dst_image_index,
50  int src_gpu_index,
51  int dst_gpu_index,
52  VkOffset2D src_offset,
53  VkOffset2D dst_offset,
54  VkExtent2D size)
55 {
56  VkImageSubresourceRange subresource_range = {
57  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
58  .baseMipLevel = 0,
59  .levelCount = 1,
60  .baseArrayLayer = 0,
61  .layerCount = 1
62  };
63 
64  VkImageSubresourceLayers subresource_layers = {
65  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
66  .mipLevel = 0,
67  .baseArrayLayer = 0,
68  .layerCount = 1
69  };
70 
71  VkImageCopy copy_region = {
72  .srcSubresource = subresource_layers,
73  .srcOffset.x = src_offset.x,
74  .srcOffset.y = src_offset.y,
75  .srcOffset.z = 0,
76  .dstSubresource = subresource_layers,
77  .dstOffset.x = dst_offset.x,
78  .dstOffset.y = dst_offset.y,
79  .dstOffset.z = 0,
80  .extent.width = size.width,
81  .extent.height = size.height,
82  .extent.depth = 1
83  };
84 
85  set_current_gpu(cmd_buf, src_gpu_index);
86 
87  VkMemoryBarrier mem_barrier = {
88  .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
89  .pNext = NULL,
90  .srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
91  .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
92  };
93 
94  vkCmdPipelineBarrier(cmd_buf,
95  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
96  0,
97  1, &mem_barrier,
98  0, NULL,
99  0, NULL);
100 
101  vkCmdCopyImage(cmd_buf,
102  qvk.images_local[src_gpu_index][src_image_index], VK_IMAGE_LAYOUT_GENERAL,
103  qvk.images_local[dst_gpu_index][dst_image_index], VK_IMAGE_LAYOUT_GENERAL,
104  1, &copy_region);
105 
106  set_current_gpu(cmd_buf, ALL_GPUS);
107 }
108 #endif
109 
110 void
111 vkpt_image_copy(VkCommandBuffer cmd_buf,
112  int src_image_index,
113  int dst_image_index,
114  VkOffset2D src_offset,
115  VkOffset2D dst_offset,
116  VkExtent2D size)
117 {
118  VkImageSubresourceRange subresource_range = {
119  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
120  .baseMipLevel = 0,
121  .levelCount = 1,
122  .baseArrayLayer = 0,
123  .layerCount = 1
124  };
125 
126  VkImageSubresourceLayers subresource_layers = {
127  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
128  .mipLevel = 0,
129  .baseArrayLayer = 0,
130  .layerCount = 1
131  };
132 
133  VkImageCopy copy_region = {
134  .srcSubresource = subresource_layers,
135  .srcOffset.x = src_offset.x,
136  .srcOffset.y = src_offset.y,
137  .srcOffset.z = 0,
138  .dstSubresource = subresource_layers,
139  .dstOffset.x = dst_offset.x,
140  .dstOffset.y = dst_offset.y,
141  .dstOffset.z = 0,
142  .extent.width = size.width,
143  .extent.height = size.height,
144  .extent.depth = 1
145  };
146 
147  VkMemoryBarrier mem_barrier = {
148  .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
149  .pNext = NULL,
150  .srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
151  .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
152  };
153 
154  vkCmdPipelineBarrier(cmd_buf,
155  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
156  0,
157  1, &mem_barrier,
158  0, NULL,
159  0, NULL);
160 
161  vkCmdCopyImage(cmd_buf,
162  qvk.images[src_image_index], VK_IMAGE_LAYOUT_GENERAL,
163  qvk.images[dst_image_index], VK_IMAGE_LAYOUT_GENERAL,
164  1, &copy_region);
165 }
vkpt.h
QVK_s::images
VkImage images[NUM_VKPT_IMAGES]
Definition: vkpt.h:231
set_current_gpu
void set_current_gpu(VkCommandBuffer cmd_buf, int gpu_index)
Definition: vk_util.c:426
qvk
QVK_t qvk
Definition: main.c:377
ALL_GPUS
#define ALL_GPUS
Definition: vkpt.h:535
vkpt_image_copy
void vkpt_image_copy(VkCommandBuffer cmd_buf, int src_image_index, int dst_image_index, VkOffset2D src_offset, VkOffset2D dst_offset, VkExtent2D size)
Definition: mgpu.c:111
QVK_s::device_count
int device_count
Definition: vkpt.h:167