directx - warning X4000: use of potentially uninitialized variable
问题描述
HLSL compiler emit the error message "warning X4000: use of potentially uninitialized variable" with the following code:
float4 GetPixelColorFromRawImage(
in ByteAddressBuffer Source,
in uint2 SourceSize,
in uint2 XY)
{
// Check if within range
if (any(XY >= SourceSize))
return float4(0.5, 0.0, 0.0, 1.0); // <<<==== WARNING HERE
if (BytesPerPixel == 3) {
// 24 bits RGB color image
uint4 RGBA = GetPixelRGBAFromRawImage(Source, SourceSize, XY);
return float4(RGBA.r / 256.0,
RGBA.g / 256.0,
RGBA.b / 256.0,
RGBA.a / 256.0);
}
else if (BytesPerPixel == 2) {
// 16 bit grayscale image
uint Gray1 = GetPixel16BitGrayFromRawImage(Source, SourceSize, XY);
uint Gray2 = GetByteFromUInt(LUT16.Load(Gray1 & (~3)), Gray1 & 3);
float Gray3 = (float)Gray2 / 256.0;
return float4(Gray3, Gray3, Gray3, 1.0);
}
else {
return float4(0.0, 0.0, 0.0, 1.0);
}
}
I don't understand that warning. There is no variable at all used in the offending line!
Any help appreciated.
解决方案
The compiler sometimes goes crazy with intermediate return
calls, and gives errors where there should be none.
You can try a little workaround.
In the beginning of your method, define and instantiate a variable, then update it in the ifs and the return it.
float4 GetPixelColorFromRawImage(
in ByteAddressBuffer Source,
in uint2 SourceSize,
in uint2 XY)
{
float4 returnVar = float4(0.0, 0.0, 0.0, 0.0);
// Check if within range
if (any(XY >= SourceSize))
returnVar = float4(0.5, 0.0, 0.0, 1.0);
if (BytesPerPixel == 3) {
// 24 bits RGB color image
uint4 RGBA = GetPixelRGBAFromRawImage(Source, SourceSize, XY);
returnVar = float4(RGBA.r / 256.0,
RGBA.g / 256.0,
RGBA.b / 256.0,
RGBA.a / 256.0);
}
else if (BytesPerPixel == 2) {
// 16 bit grayscale image
uint Gray1 = GetPixel16BitGrayFromRawImage(Source, SourceSize, XY);
uint Gray2 = GetByteFromUInt(LUT16.Load(Gray1 & (~3)), Gray1 & 3);
float Gray3 = (float)Gray2 / 256.0;
returnVar = float4(Gray3, Gray3, Gray3, 1.0);
}
else {
returnVar = float4(0.0, 0.0, 0.0, 1.0);
}
return returnVar;
}
推荐阅读
- c# - 可替换/可交换数据层的通用接口
- javascript - 脚本化使用
我尝试使用 JavaScript 在 html 中动态创建 svg 路径元素。
我想在<defs>
稍后可以在<use>
xlink:href 元素中重用的元素中设置路径。
创建后(在- r - r - 为什么 rlm(MASS 包)返回一个没有截距的模型?
- c# - Web API 2 Json 输出被截断
- javascript - Promise 完成后调用类的方法
- java - Softlayer - 已开机的服务器列表
- asp.net-core - 如何使用 .NET Core 在 Web API 中使用 FluentValidation 执行异步 ModelState 验证
- search - 示例 33078:如何在库中的任何 SAS® 数据集中的任何变量中查找特定值
- python-3.x - 子类化消息以添加其他行为
- html - 是否可以将 Internet Explorer 滚动条箭头居中?