mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 11:48:06 +02:00
anv/grl: Use union for reinterpreting integer as float
Fixes strict aliasing violations flagged by GCC 12:
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h: In function ‘float as_float(uint32_t)’:
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h:182:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
182 | return *reinterpret_cast<float*>(&i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h: In function ‘float3 as_float3(int3)’:
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h:187:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
187 | return *reinterpret_cast<float3*>(&i3);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h:187:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h: In function ‘float4 as_float4(int4)’:
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h:192:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
192 | return *reinterpret_cast<float4*>(&i4);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h:192:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
Fixes: 5f948503e4 ("anv: Import GRL")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21236>
(cherry picked from commit 53ce756eeb)
This commit is contained in:
parent
ba02305bfd
commit
fbad155585
2 changed files with 9 additions and 4 deletions
|
|
@ -868,7 +868,7 @@
|
|||
"description": "anv/grl: Use union for reinterpreting integer as float",
|
||||
"nominated": true,
|
||||
"nomination_type": 1,
|
||||
"resolution": 0,
|
||||
"resolution": 1,
|
||||
"main_sha": null,
|
||||
"because_sha": "5f948503e40c6c9ccf8497a55b23219d797f9729"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -179,17 +179,22 @@ inline float dot(const float3& a, const float3& b) {
|
|||
|
||||
inline float as_float(uint32_t i)
|
||||
{
|
||||
return *reinterpret_cast<float*>(&i);
|
||||
union { float f; uint32_t i; } fi;
|
||||
|
||||
fi.i = i;
|
||||
return fi.f;
|
||||
}
|
||||
|
||||
inline float3 as_float3(int3 i3)
|
||||
{
|
||||
return *reinterpret_cast<float3*>(&i3);
|
||||
float3 o = { as_float(i3.x), as_float(i3.y), as_float(i3.z) };
|
||||
return o;
|
||||
}
|
||||
|
||||
inline float4 as_float4(int4 i4)
|
||||
{
|
||||
return *reinterpret_cast<float4*>(&i4);
|
||||
float4 o = { as_float(i4.x), as_float(i4.y), as_float(i4.z), as_float(i4.w) };
|
||||
return o;
|
||||
}
|
||||
|
||||
inline float4 convert_float4_rtn(int4 i4)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue