mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 04:58:05 +02:00
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@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17236>
This commit is contained in:
parent
9527fbe596
commit
02002c8f12
1 changed files with 13 additions and 2 deletions
|
|
@ -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
|
static void
|
||||||
dzn_graphics_pipeline_translate_rast(struct dzn_graphics_pipeline *pipeline,
|
dzn_graphics_pipeline_translate_rast(struct dzn_graphics_pipeline *pipeline,
|
||||||
D3D12_PIPELINE_STATE_STREAM_DESC *out,
|
D3D12_PIPELINE_STATE_STREAM_DESC *out,
|
||||||
|
|
@ -680,7 +691,7 @@ dzn_graphics_pipeline_translate_rast(struct dzn_graphics_pipeline *pipeline,
|
||||||
desc->FrontCounterClockwise =
|
desc->FrontCounterClockwise =
|
||||||
in_rast->frontFace == VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
in_rast->frontFace == VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||||
if (in_rast->depthBiasEnable) {
|
if (in_rast->depthBiasEnable) {
|
||||||
desc->DepthBias = in_rast->depthBiasConstantFactor;
|
desc->DepthBias = translate_depth_bias(in_rast->depthBiasConstantFactor);
|
||||||
desc->SlopeScaledDepthBias = in_rast->depthBiasSlopeFactor;
|
desc->SlopeScaledDepthBias = in_rast->depthBiasSlopeFactor;
|
||||||
desc->DepthBiasClamp = in_rast->depthBiasClamp;
|
desc->DepthBiasClamp = in_rast->depthBiasClamp;
|
||||||
}
|
}
|
||||||
|
|
@ -1339,7 +1350,7 @@ dzn_graphics_pipeline_get_state(struct dzn_graphics_pipeline *pipeline,
|
||||||
D3D12_RASTERIZER_DESC *rast =
|
D3D12_RASTERIZER_DESC *rast =
|
||||||
dzn_graphics_pipeline_get_desc(pipeline, stream_buf, rast);
|
dzn_graphics_pipeline_get_desc(pipeline, stream_buf, rast);
|
||||||
if (rast && pipeline->zsa.dynamic_depth_bias) {
|
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->DepthBiasClamp = masked_key.depth_bias.clamp;
|
||||||
rast->SlopeScaledDepthBias = masked_key.depth_bias.slope_factor;
|
rast->SlopeScaledDepthBias = masked_key.depth_bias.slope_factor;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue