Why "Warning X4000: use of potentially uninitialized variable" shows for more than one usage of common method?
Asked Answered
D

1

8

I have a common method in hlsli

/// RendererShaderTypes.hlsli
///
static inline float4 OverlayColor(float2 texOverlay, float4 videoColor)
{

      float4 texColor = float4(imageMixTexture[4].Sample(imageMixSampler[4], texOverlay));
      if (texColor.r == keyColor.r &&
          texColor.g == keyColor.g &&
          texColor.b == keyColor.b)
      {
          return videoColor;
      }
      return lerp(texColor, videoColor, transparency);
}

It's called from more than one hlsl pixel shaders.

#include "RendererShaderTypes.hlsli"
float4 main(PSPosTexOverlay input) : SV_TARGET
{
    return OverlayColor(input.texOverlay, backColor);
}

also called to another pixel shader

#include "RendererShaderTypes.hlsli"
float4 main(PSPosVideoTexture input) : SV_TARGET
{
     // lookup color of video
     float4 mixColor = mul(colorMatrix[0], VideoColor(imageMixSampler[0], imageMixTexture[0], input.texImage));
     mixColor.rgb *= mixColor.a;
     mixColor.a = 1.0f;
     return OverlayColor(input.texOverlay, mixColor);
}

when compiled shows following warning. Any idea why it's showing?

warning X4000: use of potentially uninitialized variable (OverlayColor)

Decuple answered 20/2, 2019 at 7:33 Comment(5)
What is in the elided code block?Samothrace
Please post a minimal reproducible exampleManikin
@ChuckWalbourn I have not showed the code block because I though it's something related to prototype declaring issues. Any idea why it shows?Decuple
@TajuddinKhandaker No reason that I can see that the above code would cause that error. At the risk of repetition what we need is a complete program that shows the compilation error. Take the code above, add a couple of calls to the function and add the declarations of the globals. Compile it to check that you are still getting the warning and then post that minimal, complete and verifiable program here.Chlorenchyma
Ok. Thank you @Chlorenchyma for letting me understand. I have tried to visualize how the common method in hlsli is called. If once compiled the warning never shows, but when something changed in hlsli or to the individual shader where the common method called the warning shows for each shader. I have 4 shaders called the same method for mixing video color. Let me know if the explanation serves my query properly.Decuple
D
13

I don't know yet any satisfactory reason but I have solved the issue. Any function that calls a mid-function return statement will show the warning during compilation. I have re-writed one of above like this and the warning went away.

static inline float4 OverlayColor(int texIndex, float2 texOverlay, float4 videoColor)
{
    float4 texColor = float4(imageMixTexture[4].Sample(imageMixSampler[4], texOverlay));
    float4 overlayColor;
    if (texColor.r == keyColor.r &&
        texColor.g == keyColor.g &&
        texColor.b == keyColor.b)
    {
        overlayColor = videoColor;
    }
    else
        overlayColor = lerp(texColor, videoColor, transparency);
    return overlayColor;
}
Decuple answered 29/6, 2019 at 5:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.