From d99e5ffee71886be6255f13ab973b409b891db55 Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Fri, 30 Sep 2022 15:53:42 +0200 Subject: [PATCH] tu: Clamp sample locations This was missed in the initial implementation and fixes extreme sample locations like (1.0, 1.0). Part-of: --- src/freedreno/vulkan/tu_common.h | 3 +++ src/freedreno/vulkan/tu_device.c | 4 ++-- src/freedreno/vulkan/tu_pipeline.c | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/freedreno/vulkan/tu_common.h b/src/freedreno/vulkan/tu_common.h index 61b63ef7b72..6aad2c7ba16 100644 --- a/src/freedreno/vulkan/tu_common.h +++ b/src/freedreno/vulkan/tu_common.h @@ -94,6 +94,9 @@ (MAX_DYNAMIC_UNIFORM_BUFFERS + 2 * MAX_DYNAMIC_STORAGE_BUFFERS) * \ A6XX_TEX_CONST_DWORDS +#define SAMPLE_LOCATION_MIN 0.f +#define SAMPLE_LOCATION_MAX 0.9375f + #define TU_MAX_DRM_DEVICES 8 #define MAX_VIEWS 16 #define MAX_BIND_POINTS 2 /* compute + graphics */ diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index af7e4c20da3..4739b0389c7 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -1344,8 +1344,8 @@ tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT; } properties->maxSampleLocationGridSize = (VkExtent2D) { 1 , 1 }; - properties->sampleLocationCoordinateRange[0] = 0.0f; - properties->sampleLocationCoordinateRange[1] = 0.9375f; + properties->sampleLocationCoordinateRange[0] = SAMPLE_LOCATION_MIN; + properties->sampleLocationCoordinateRange[1] = SAMPLE_LOCATION_MAX; properties->sampleLocationSubPixelBits = 4; properties->variableSampleLocations = true; break; diff --git a/src/freedreno/vulkan/tu_pipeline.c b/src/freedreno/vulkan/tu_pipeline.c index 6c0311b1781..bcd0470e334 100644 --- a/src/freedreno/vulkan/tu_pipeline.c +++ b/src/freedreno/vulkan/tu_pipeline.c @@ -2161,9 +2161,21 @@ tu6_emit_sample_locations(struct tu_cs *cs, const VkSampleLocationsInfoEXT *samp A6XX_RB_SAMPLE_CONFIG_LOCATION_ENABLE; uint32_t sample_locations = 0; for (uint32_t i = 0; i < samp_loc->sampleLocationsCount; i++) { + /* From VkSampleLocationEXT: + * + * The values specified in a VkSampleLocationEXT structure are always + * clamped to the implementation-dependent sample location coordinate + * range + * [sampleLocationCoordinateRange[0],sampleLocationCoordinateRange[1]] + */ + float x = CLAMP(samp_loc->pSampleLocations[i].x, SAMPLE_LOCATION_MIN, + SAMPLE_LOCATION_MAX); + float y = CLAMP(samp_loc->pSampleLocations[i].y, SAMPLE_LOCATION_MIN, + SAMPLE_LOCATION_MAX); + sample_locations |= - (A6XX_RB_SAMPLE_LOCATION_0_SAMPLE_0_X(samp_loc->pSampleLocations[i].x) | - A6XX_RB_SAMPLE_LOCATION_0_SAMPLE_0_Y(samp_loc->pSampleLocations[i].y)) << i*8; + (A6XX_RB_SAMPLE_LOCATION_0_SAMPLE_0_X(x) | + A6XX_RB_SAMPLE_LOCATION_0_SAMPLE_0_Y(y)) << i*8; } tu_cs_emit_pkt4(cs, REG_A6XX_GRAS_SAMPLE_CONFIG, 2);