From 98570a402a87ebf4f87206c034b48cd162d8398b Mon Sep 17 00:00:00 2001 From: "specialfred453@gmail.com" Date: Thu, 9 Jan 2025 20:58:25 -0500 Subject: [PATCH 1/5] Implemented Line Width Scaling in Vulkan (not working at the moment) --- hw/xbox/nv2a/pgraph/vk/display.c | 5 +++-- hw/xbox/nv2a/pgraph/vk/draw.c | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/xbox/nv2a/pgraph/vk/display.c b/hw/xbox/nv2a/pgraph/vk/display.c index e1993d4186..1b10f5ff00 100644 --- a/hw/xbox/nv2a/pgraph/vk/display.c +++ b/hw/xbox/nv2a/pgraph/vk/display.c @@ -413,7 +413,7 @@ static void create_display_pipeline(PGRAPHState *pg) .depthClampEnable = VK_FALSE, .rasterizerDiscardEnable = VK_FALSE, .polygonMode = VK_POLYGON_MODE_FILL, - .lineWidth = 1.0f, + .lineWidth = (float)pg->surface_scale_factor, .cullMode = VK_CULL_MODE_BACK_BIT, .frontFace = VK_FRONT_FACE_CLOCKWISE, .depthBiasEnable = VK_FALSE, @@ -447,7 +447,8 @@ static void create_display_pipeline(PGRAPHState *pg) }; VkDynamicState dynamic_states[] = { VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR }; + VK_DYNAMIC_STATE_SCISSOR, + VK_DYNAMIC_STATE_LINE_WIDTH }; VkPipelineDynamicStateCreateInfo dynamic_state = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, .dynamicStateCount = 2, diff --git a/hw/xbox/nv2a/pgraph/vk/draw.c b/hw/xbox/nv2a/pgraph/vk/draw.c index 4cde028b1f..dba37eb0d1 100644 --- a/hw/xbox/nv2a/pgraph/vk/draw.c +++ b/hw/xbox/nv2a/pgraph/vk/draw.c @@ -500,7 +500,7 @@ static void create_clear_pipeline(PGRAPHState *pg) .depthClampEnable = VK_FALSE, .rasterizerDiscardEnable = VK_FALSE, .polygonMode = VK_POLYGON_MODE_FILL, - .lineWidth = 1.0f, + .lineWidth = (float)pg->surface_scale_factor, .cullMode = VK_CULL_MODE_BACK_BIT, .frontFace = VK_FRONT_FACE_CLOCKWISE, .depthBiasEnable = VK_FALSE, @@ -820,7 +820,7 @@ static void create_pipeline(PGRAPHState *pg) .rasterizerDiscardEnable = VK_FALSE, .polygonMode = pgraph_polygon_mode_vk_map[r->shader_binding->state .polygon_front_mode], - .lineWidth = 1.0f, + .lineWidth = (float)pg->surface_scale_factor, .frontFace = (pgraph_reg_r(pg, NV_PGRAPH_SETUPRASTER) & NV_PGRAPH_SETUPRASTER_FRONTFACE) ? VK_FRONT_FACE_COUNTER_CLOCKWISE : @@ -949,8 +949,9 @@ static void create_pipeline(PGRAPHState *pg) .blendConstants[3] = blend_constant[3], }; - VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR }; + VkDynamicState dynamic_states[] = { VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_SCISSOR, + VK_DYNAMIC_STATE_LINE_WIDTH }; VkPipelineDynamicStateCreateInfo dynamic_state = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, From cf40733206dba1b3a1446c98d4e15ce7ee202ba9 Mon Sep 17 00:00:00 2001 From: "specialfred453@gmail.com" Date: Wed, 15 Jan 2025 07:42:43 -0500 Subject: [PATCH 2/5] Fixed it by removing the VK_DYNAMIC_STATE_LINE_WIDTH dynamic state --- hw/xbox/nv2a/pgraph/vk/display.c | 3 +-- hw/xbox/nv2a/pgraph/vk/draw.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/xbox/nv2a/pgraph/vk/display.c b/hw/xbox/nv2a/pgraph/vk/display.c index 1b10f5ff00..0314eced67 100644 --- a/hw/xbox/nv2a/pgraph/vk/display.c +++ b/hw/xbox/nv2a/pgraph/vk/display.c @@ -447,8 +447,7 @@ static void create_display_pipeline(PGRAPHState *pg) }; VkDynamicState dynamic_states[] = { VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR, - VK_DYNAMIC_STATE_LINE_WIDTH }; + VK_DYNAMIC_STATE_SCISSOR }; VkPipelineDynamicStateCreateInfo dynamic_state = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, .dynamicStateCount = 2, diff --git a/hw/xbox/nv2a/pgraph/vk/draw.c b/hw/xbox/nv2a/pgraph/vk/draw.c index dba37eb0d1..b5d9a09881 100644 --- a/hw/xbox/nv2a/pgraph/vk/draw.c +++ b/hw/xbox/nv2a/pgraph/vk/draw.c @@ -950,8 +950,7 @@ static void create_pipeline(PGRAPHState *pg) }; VkDynamicState dynamic_states[] = { VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR, - VK_DYNAMIC_STATE_LINE_WIDTH }; + VK_DYNAMIC_STATE_SCISSOR }; VkPipelineDynamicStateCreateInfo dynamic_state = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, From c8c77230f768db826564e78546cd8e0f725195f2 Mon Sep 17 00:00:00 2001 From: "specialfred453@gmail.com" Date: Sat, 25 Jan 2025 18:49:08 -0500 Subject: [PATCH 3/5] Removed the change from display.c because it isn't required. Removed the change from create_clear_pipeline in draw.c because it isn't required. Added logic to create_pipeline in draw.c to use r->device_props.limits.lineWidthRange to constrain the line width to the supported range --- hw/xbox/nv2a/pgraph/vk/display.c | 2 +- hw/xbox/nv2a/pgraph/vk/draw.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/xbox/nv2a/pgraph/vk/display.c b/hw/xbox/nv2a/pgraph/vk/display.c index 0314eced67..e1993d4186 100644 --- a/hw/xbox/nv2a/pgraph/vk/display.c +++ b/hw/xbox/nv2a/pgraph/vk/display.c @@ -413,7 +413,7 @@ static void create_display_pipeline(PGRAPHState *pg) .depthClampEnable = VK_FALSE, .rasterizerDiscardEnable = VK_FALSE, .polygonMode = VK_POLYGON_MODE_FILL, - .lineWidth = (float)pg->surface_scale_factor, + .lineWidth = 1.0f, .cullMode = VK_CULL_MODE_BACK_BIT, .frontFace = VK_FRONT_FACE_CLOCKWISE, .depthBiasEnable = VK_FALSE, diff --git a/hw/xbox/nv2a/pgraph/vk/draw.c b/hw/xbox/nv2a/pgraph/vk/draw.c index b5d9a09881..c5fd4e0a29 100644 --- a/hw/xbox/nv2a/pgraph/vk/draw.c +++ b/hw/xbox/nv2a/pgraph/vk/draw.c @@ -500,7 +500,7 @@ static void create_clear_pipeline(PGRAPHState *pg) .depthClampEnable = VK_FALSE, .rasterizerDiscardEnable = VK_FALSE, .polygonMode = VK_POLYGON_MODE_FILL, - .lineWidth = (float)pg->surface_scale_factor, + .lineWidth = 1.0f, .cullMode = VK_CULL_MODE_BACK_BIT, .frontFace = VK_FRONT_FACE_CLOCKWISE, .depthBiasEnable = VK_FALSE, @@ -813,6 +813,10 @@ static void create_pipeline(PGRAPHState *pg) } else { // FIXME: Handle in shader? } + + float lineWidth = MIN(r->device_props.limits.lineWidthRange[1], + MAX(r->device_props.limits.lineWidthRange[0], + (float)pg->surface_scale_factor)); VkPipelineRasterizationStateCreateInfo rasterizer = { .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, @@ -820,7 +824,7 @@ static void create_pipeline(PGRAPHState *pg) .rasterizerDiscardEnable = VK_FALSE, .polygonMode = pgraph_polygon_mode_vk_map[r->shader_binding->state .polygon_front_mode], - .lineWidth = (float)pg->surface_scale_factor, + .lineWidth = lineWidth, .frontFace = (pgraph_reg_r(pg, NV_PGRAPH_SETUPRASTER) & NV_PGRAPH_SETUPRASTER_FRONTFACE) ? VK_FRONT_FACE_COUNTER_CLOCKWISE : From a07f0facf06d4ac4fc2220a11509d703ea152035 Mon Sep 17 00:00:00 2001 From: "specialfred453@gmail.com" Date: Fri, 21 Mar 2025 17:20:28 -0400 Subject: [PATCH 4/5] Added a check of available physical device features. If the wideLines feature is not supported then the lineWidth is left at 1.0f --- hw/xbox/nv2a/pgraph/vk/draw.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/xbox/nv2a/pgraph/vk/draw.c b/hw/xbox/nv2a/pgraph/vk/draw.c index e79c8d092f..446fb9e413 100644 --- a/hw/xbox/nv2a/pgraph/vk/draw.c +++ b/hw/xbox/nv2a/pgraph/vk/draw.c @@ -810,9 +810,16 @@ static void create_pipeline(PGRAPHState *pg) // FIXME: Handle in shader? } - float lineWidth = MIN(r->device_props.limits.lineWidthRange[1], - MAX(r->device_props.limits.lineWidthRange[0], - (float)pg->surface_scale_factor)); + VkPhysicalDeviceFeatures available_features; + vkGetPhysicalDeviceFeatures(r->physical_device, &available_features); + + float lineWidth = 1.0f; + if(available_features.wideLines == VK_TRUE) + { + lineWidth = MIN(r->device_props.limits.lineWidthRange[1], + MAX(r->device_props.limits.lineWidthRange[0], + (float)pg->surface_scale_factor)); + } VkPipelineRasterizationStateCreateInfo rasterizer = { .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, From 088cd8a3ff5a64201c6cef6de5a24cde7158135e Mon Sep 17 00:00:00 2001 From: "specialfred453@gmail.com" Date: Sat, 22 Mar 2025 11:57:54 -0400 Subject: [PATCH 5/5] Reverted the unrelated change on line 956 of hw/xbox/nv2a/pgraph/vk/draw.c Removed the call to vkGetPhysicalDeviceFeatures on line 814 of vk/draw.c. This was replaced by storing the result of the same call in vk/instance.c in the PGRAPHVkState struct so it can be retrieved later --- hw/xbox/nv2a/pgraph/vk/draw.c | 7 ++----- hw/xbox/nv2a/pgraph/vk/instance.c | 6 +++--- hw/xbox/nv2a/pgraph/vk/renderer.h | 1 + subprojects/cpp-httplib | 1 + 4 files changed, 7 insertions(+), 8 deletions(-) create mode 160000 subprojects/cpp-httplib diff --git a/hw/xbox/nv2a/pgraph/vk/draw.c b/hw/xbox/nv2a/pgraph/vk/draw.c index 446fb9e413..5ba452d82d 100644 --- a/hw/xbox/nv2a/pgraph/vk/draw.c +++ b/hw/xbox/nv2a/pgraph/vk/draw.c @@ -810,11 +810,8 @@ static void create_pipeline(PGRAPHState *pg) // FIXME: Handle in shader? } - VkPhysicalDeviceFeatures available_features; - vkGetPhysicalDeviceFeatures(r->physical_device, &available_features); - float lineWidth = 1.0f; - if(available_features.wideLines == VK_TRUE) + if(r->physical_device_features.wideLines == VK_TRUE) { lineWidth = MIN(r->device_props.limits.lineWidthRange[1], MAX(r->device_props.limits.lineWidthRange[0], @@ -956,7 +953,7 @@ static void create_pipeline(PGRAPHState *pg) .blendConstants[3] = blend_constant[3], }; - VkDynamicState dynamic_states[] = { VK_DYNAMIC_STATE_VIEWPORT, + VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; VkPipelineDynamicStateCreateInfo dynamic_state = { diff --git a/hw/xbox/nv2a/pgraph/vk/instance.c b/hw/xbox/nv2a/pgraph/vk/instance.c index 9df440930c..416f12dff8 100644 --- a/hw/xbox/nv2a/pgraph/vk/instance.c +++ b/hw/xbox/nv2a/pgraph/vk/instance.c @@ -523,15 +523,15 @@ static bool create_logical_device(PGRAPHState *pg, Error **errp) }; // Ensure device supports required features - VkPhysicalDeviceFeatures available_features, enabled_features; - vkGetPhysicalDeviceFeatures(r->physical_device, &available_features); + VkPhysicalDeviceFeatures enabled_features; + vkGetPhysicalDeviceFeatures(r->physical_device, &r->physical_device_features); memset(&enabled_features, 0, sizeof(enabled_features)); struct { const char *name; VkBool32 available, *enabled; } required_features[] = { - #define F(n) { #n, available_features.n, &enabled_features.n } + #define F(n) { #n, r->physical_device_features.n, &enabled_features.n } F(shaderClipDistance), F(geometryShader), F(shaderTessellationAndGeometryPointSize), diff --git a/hw/xbox/nv2a/pgraph/vk/renderer.h b/hw/xbox/nv2a/pgraph/vk/renderer.h index eb0726ac2f..5e4e31b1a8 100644 --- a/hw/xbox/nv2a/pgraph/vk/renderer.h +++ b/hw/xbox/nv2a/pgraph/vk/renderer.h @@ -331,6 +331,7 @@ typedef struct PGRAPHVkState { bool memory_budget_extension_enabled; VkPhysicalDevice physical_device; + VkPhysicalDeviceFeatures physical_device_features; VkPhysicalDeviceProperties device_props; VkDevice device; VmaAllocator allocator; diff --git a/subprojects/cpp-httplib b/subprojects/cpp-httplib new file mode 160000 index 0000000000..0f1b62c2b3 --- /dev/null +++ b/subprojects/cpp-httplib @@ -0,0 +1 @@ +Subproject commit 0f1b62c2b3d0898cbab7aa685c2593303ffdc1a2