Mesa (main): dzn: Clamp depthBiasConstantFactor when doing the float -> int conversion
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jun 24 17:11:34 UTC 2022
Module: Mesa
Branch: main
Commit: 02002c8f12eba89abcbf0a71e5ee01b2a5ae7635
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=02002c8f12eba89abcbf0a71e5ee01b2a5ae7635
Author: Boris Brezillon <boris.brezillon at collabora.com>
Date: Fri Jun 24 08:12:16 2022 -0700
dzn: Clamp depthBiasConstantFactor when doing the float -> int conversion
If we don't do that, we might end up with an integer overflow/underflow.
Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17236>
---
src/microsoft/vulkan/dzn_pipeline.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/microsoft/vulkan/dzn_pipeline.c b/src/microsoft/vulkan/dzn_pipeline.c
index b3a5997009c..8d863e54a25 100644
--- a/src/microsoft/vulkan/dzn_pipeline.c
+++ b/src/microsoft/vulkan/dzn_pipeline.c
@@ -647,6 +647,17 @@ translate_cull_mode(VkCullModeFlags in)
}
}
+static int32_t
+translate_depth_bias(double depth_bias)
+{
+ if (depth_bias > INT32_MAX)
+ return INT32_MAX;
+ else if (depth_bias < INT32_MIN)
+ return INT32_MIN;
+
+ return depth_bias;
+}
+
static void
dzn_graphics_pipeline_translate_rast(struct dzn_graphics_pipeline *pipeline,
D3D12_PIPELINE_STATE_STREAM_DESC *out,
@@ -680,7 +691,7 @@ dzn_graphics_pipeline_translate_rast(struct dzn_graphics_pipeline *pipeline,
desc->FrontCounterClockwise =
in_rast->frontFace == VK_FRONT_FACE_COUNTER_CLOCKWISE;
if (in_rast->depthBiasEnable) {
- desc->DepthBias = in_rast->depthBiasConstantFactor;
+ desc->DepthBias = translate_depth_bias(in_rast->depthBiasConstantFactor);
desc->SlopeScaledDepthBias = in_rast->depthBiasSlopeFactor;
desc->DepthBiasClamp = in_rast->depthBiasClamp;
}
@@ -1339,7 +1350,7 @@ dzn_graphics_pipeline_get_state(struct dzn_graphics_pipeline *pipeline,
D3D12_RASTERIZER_DESC *rast =
dzn_graphics_pipeline_get_desc(pipeline, stream_buf, rast);
if (rast && pipeline->zsa.dynamic_depth_bias) {
- rast->DepthBias = masked_key.depth_bias.constant_factor;
+ rast->DepthBias = translate_depth_bias(masked_key.depth_bias.constant_factor);
rast->DepthBiasClamp = masked_key.depth_bias.clamp;
rast->SlopeScaledDepthBias = masked_key.depth_bias.slope_factor;
}
More information about the mesa-commit
mailing list