Skip to content

Commit f3efc6b

Browse files
committed
Fix some bugs with foveation textures;
- OpenXR only adds foveation texture when foveation is enabled. - Render passes created for graphics pipelines include foveation info.
1 parent 1572d69 commit f3efc6b

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/core/gpu.h

+1
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ typedef struct {
503503
gpu_color_state color[4];
504504
uint32_t attachmentCount;
505505
uint32_t viewCount;
506+
bool foveated;
506507
const char* label;
507508
} gpu_pipeline_info;
508509

src/core/gpu_vk.c

+24-3
Original file line numberDiff line numberDiff line change
@@ -1638,8 +1638,8 @@ bool gpu_pipeline_init_graphics(gpu_pipeline* pipeline, gpu_pipeline_info* info,
16381638
} else {
16391639
bool depth = info->depth.format;
16401640
uint32_t colorCount = info->attachmentCount;
1641-
VkAttachmentDescription2 attachments[5];
1642-
VkAttachmentReference2 references[5];
1641+
VkAttachmentDescription2 attachments[6];
1642+
VkAttachmentReference2 references[6];
16431643

16441644
for (uint32_t i = 0; i < colorCount; i++) {
16451645
references[i] = (VkAttachmentReference2) {
@@ -1679,6 +1679,20 @@ bool gpu_pipeline_init_graphics(gpu_pipeline* pipeline, gpu_pipeline_info* info,
16791679
};
16801680
}
16811681

1682+
if (info->foveated) {
1683+
uint32_t index = colorCount + depth;
1684+
1685+
attachments[index] = (VkAttachmentDescription2) {
1686+
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2,
1687+
.format = VK_FORMAT_R8G8_UNORM,
1688+
.samples = VK_SAMPLE_COUNT_1_BIT,
1689+
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
1690+
.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
1691+
.initialLayout = VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT,
1692+
.finalLayout = VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT
1693+
};
1694+
}
1695+
16821696
VkSubpassDescription2 subpass = {
16831697
.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2,
16841698
.viewMask = (1 << info->viewCount) - 1,
@@ -1689,7 +1703,14 @@ bool gpu_pipeline_init_graphics(gpu_pipeline* pipeline, gpu_pipeline_info* info,
16891703

16901704
VkRenderPassCreateInfo2 passInfo = {
16911705
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2,
1692-
.attachmentCount = colorCount + depth,
1706+
.pNext = info->foveated ? &(VkRenderPassFragmentDensityMapCreateInfoEXT) {
1707+
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_FRAGMENT_DENSITY_MAP_CREATE_INFO_EXT,
1708+
.fragmentDensityMapAttachment = {
1709+
.attachment = colorCount + depth,
1710+
.layout = VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT
1711+
}
1712+
} : NULL,
1713+
.attachmentCount = colorCount + depth + info->foveated,
16931714
.pAttachments = attachments,
16941715
.subpassCount = 1,
16951716
.pSubpasses = &subpass

src/modules/graphics/graphics.c

+1
Original file line numberDiff line numberDiff line change
@@ -5964,6 +5964,7 @@ void lovrPassReset(Pass* pass) {
59645964
pass->pipeline->info.depth.format = (gpu_texture_format) (canvas->depth.texture ? canvas->depth.texture->info.format : canvas->depthFormat);
59655965
pass->pipeline->info.multisample.count = canvas->samples;
59665966
pass->pipeline->info.viewCount = pass->views;
5967+
pass->pipeline->info.foveated = canvas->foveation;
59675968

59685969
pass->cameraCount = 0;
59695970
pass->viewportCount = 0;

src/modules/headset/headset_openxr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3442,7 +3442,7 @@ static bool openxr_getPass(Pass** pass) {
34423442
return true;
34433443
}
34443444

3445-
canvas.foveation = state.swapchains[SWAPCHAIN_COLOR].foveationTextures[state.swapchains[SWAPCHAIN_COLOR].textureIndex];
3445+
canvas.foveation = state.foveationLevel ? state.swapchains[SWAPCHAIN_COLOR].foveationTextures[state.swapchains[SWAPCHAIN_COLOR].textureIndex] : NULL;
34463446

34473447
if (!lovrPassSetCanvas(state.pass, &canvas)) {
34483448
return false;

0 commit comments

Comments
 (0)