gallium/swr: Fix compilation warnings
authorjzielins <jan.zielinski@intel.com>
Mon, 6 Jul 2020 15:38:02 +0000 (17:38 +0200)
committerJan Zielinski <jan.zielinski@intel.com>
Tue, 7 Jul 2020 09:24:47 +0000 (09:24 +0000)
In some places in SWR cod objects are initialized using
memset/memcpy. This is usually done to enable
allocating those objects in aligned memory.
It generates compilation warnings though,
which are worked around by casting the pointers to void*
before calling memset/memcpy.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5777>

src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.cpp
src/gallium/drivers/swr/rasterizer/core/api.cpp
src/gallium/drivers/swr/rasterizer/core/frontend.cpp
src/gallium/drivers/swr/rasterizer/core/ringbuffer.h
src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp
src/gallium/drivers/swr/rasterizer/memory/StoreTile.h
src/gallium/drivers/swr/swr_context.cpp
src/gallium/drivers/swr/swr_shader.cpp
src/gallium/drivers/swr/swr_state.cpp

index 2404ae7590d1ab82b733c6a0b2c4b81672e85f9d..e2076e8fc4439d8c9291cf1fec58b13a040854d3 100644 (file)
@@ -106,7 +106,7 @@ void BucketManager::PrintBucket(
     std::string str = arrows[level];
     str += desc.name;
     char hier[80];
-    strcpy_s(hier, sizeof(hier), str.c_str());
+    strcpy_s(hier, sizeof(hier)-1, str.c_str());
 
     // print out
     fprintf(f,
index 04f03c78f423ecc57109039a32147c7178c43354..31f9fe2c2bbf3867b399802c89ccca80ac4e2206 100644 (file)
@@ -142,8 +142,8 @@ HANDLE SwrCreateContext(SWR_CREATECONTEXT_INFO* pCreateInfo)
         pContext->workerPrivateState = *pCreateInfo->pWorkerPrivateState;
     }
 
-    memset(&pContext->WaitLock, 0, sizeof(pContext->WaitLock));
-    memset(&pContext->FifosNotEmpty, 0, sizeof(pContext->FifosNotEmpty));
+    memset((void*)&pContext->WaitLock, 0, sizeof(pContext->WaitLock));
+    memset((void*)&pContext->FifosNotEmpty, 0, sizeof(pContext->FifosNotEmpty));
     new (&pContext->WaitLock) std::mutex();
     new (&pContext->FifosNotEmpty) std::condition_variable();
 
@@ -230,7 +230,7 @@ HANDLE SwrCreateContext(SWR_CREATECONTEXT_INFO* pCreateInfo)
 
 void CopyState(DRAW_STATE& dst, const DRAW_STATE& src)
 {
-    memcpy(&dst.state, &src.state, sizeof(API_STATE));
+    memcpy((void*)&dst.state, (void*)&src.state, sizeof(API_STATE));
 }
 
 template <bool IsDraw>
@@ -489,7 +489,7 @@ void SWR_API SwrRestoreState(HANDLE hContext, const void* pStateBlock, size_t me
     auto         pDst     = GetDrawState(pContext);
     assert(pStateBlock && memSize >= sizeof(*pDst));
 
-    memcpy(pDst, pStateBlock, sizeof(*pDst));
+    memcpy((void*)pDst, (void*)pStateBlock, sizeof(*pDst));
 }
 
 void SetupDefaultState(SWR_CONTEXT* pContext)
@@ -748,7 +748,7 @@ void SwrSetRastState(HANDLE hContext, const SWR_RASTSTATE* pRastState)
     SWR_CONTEXT* pContext = GetContext(hContext);
     API_STATE*   pState   = GetDrawState(pContext);
 
-    memcpy(&pState->rastState, pRastState, sizeof(SWR_RASTSTATE));
+    memcpy((void*)&pState->rastState, (void*)pRastState, sizeof(SWR_RASTSTATE));
 }
 
 void SwrSetViewports(HANDLE                       hContext,
index 63beac180d9fe62a548d6292a5ca8c9069ebca8d..13aa89ed5ddc385485f149e8e7fa2df29898fab6 100644 (file)
@@ -1243,7 +1243,7 @@ static void AllocateTessellationData(SWR_CONTEXT* pContext)
     {
         gt_pTessellationThreadData =
             (TessellationThreadLocalData*)AlignedMalloc(sizeof(TessellationThreadLocalData), 64);
-        memset(gt_pTessellationThreadData, 0, sizeof(*gt_pTessellationThreadData));
+        memset((void*)gt_pTessellationThreadData, 0, sizeof(*gt_pTessellationThreadData));
     }
 }
 
index 133420e6f3d65efaa8f0d88b005551474cc76a72..2e758f43753f9ab012aa869b74b14492c66ae0ba 100644 (file)
@@ -46,7 +46,7 @@ public:
         mNumEntries  = numEntries;
         mpRingBuffer = (T*)AlignedMalloc(sizeof(T) * numEntries, 64);
         SWR_ASSERT(mpRingBuffer != nullptr);
-        memset(mpRingBuffer, 0, sizeof(T) * numEntries);
+        memset((void*)mpRingBuffer, 0, sizeof(T) * numEntries);
     }
 
     void Destroy()
index 3ac11a8f11e27a3a3c9c0f10cc3759b592f18616..0ee727cc8d8a5f6d959649fa7a8c3b625d8c5c99 100644 (file)
@@ -108,45 +108,6 @@ namespace SwrJit
         return (uint16_t)tmpVal;
     }
 
-    //////////////////////////////////////////////////////////////////////////
-    /// @brief Convert an IEEE 754 16-bit float to an 32-bit single precision
-    ///        float
-    /// @param val - 16-bit float
-    /// @todo Maybe move this outside of this file into a header?
-    static float ConvertFloat16ToFloat32(uint32_t val)
-    {
-        uint32_t result;
-        if ((val & 0x7fff) == 0)
-        {
-            result = ((uint32_t)(val & 0x8000)) << 16;
-        }
-        else if ((val & 0x7c00) == 0x7c00)
-        {
-            result = ((val & 0x3ff) == 0) ? 0x7f800000 : 0x7fc00000;
-            result |= ((uint32_t)val & 0x8000) << 16;
-        }
-        else
-        {
-            uint32_t sign = (val & 0x8000) << 16;
-            uint32_t mant = (val & 0x3ff) << 13;
-            uint32_t exp  = (val >> 10) & 0x1f;
-            if ((exp == 0) && (mant != 0)) // Adjust exponent and mantissa for denormals
-            {
-                mant <<= 1;
-                while (mant < (0x400 << 13))
-                {
-                    exp--;
-                    mant <<= 1;
-                }
-                mant &= (0x3ff << 13);
-            }
-            exp    = ((exp - 15 + 127) & 0xff) << 23;
-            result = sign | exp | mant;
-        }
-
-        return *(float*)&result;
-    }
-
     Constant* Builder::C(bool i) { return ConstantInt::get(IRB()->getInt1Ty(), (i ? 1 : 0)); }
 
     Constant* Builder::C(char i) { return ConstantInt::get(IRB()->getInt8Ty(), i); }
index 2d32e90330e75eeeacd9c6594106e239c4481395..1b7698cc5b89f110e5ebd7460d8bec1712b610cd 100644 (file)
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
-* 
+*
 * @file StoreTile.h
-* 
+*
 * @brief Functionality for Store.
-* 
+*
 ******************************************************************************/
 #pragma once
 
@@ -347,8 +347,8 @@ struct ConvertPixelsSOAtoAOS
     {
         static const uint32_t MAX_RASTER_TILE_BYTES = 16 * 16; // 16 pixels * 16 bytes per pixel
 
-        OSALIGNSIMD16(uint8_t) soaTile[MAX_RASTER_TILE_BYTES];
-        OSALIGNSIMD16(uint8_t) aosTile[MAX_RASTER_TILE_BYTES];
+        OSALIGNSIMD16(uint8_t) soaTile[MAX_RASTER_TILE_BYTES] = {0};
+        OSALIGNSIMD16(uint8_t) aosTile[MAX_RASTER_TILE_BYTES] = {0};
 
         // Convert from SrcFormat --> DstFormat
         simd16vector src;
@@ -580,10 +580,10 @@ INLINE static void FlatConvert(const uint8_t* pSrc, uint8_t* pDst, uint8_t* pDst
     static const uint32_t offset = sizeof(simdscalar);
 
     // swizzle rgba -> bgra while we load
-    simdscalar vComp0 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(0))*offset)); // float32 rrrrrrrr 
+    simdscalar vComp0 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(0))*offset)); // float32 rrrrrrrr
     simdscalar vComp1 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(1))*offset)); // float32 gggggggg
-    simdscalar vComp2 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(2))*offset)); // float32 bbbbbbbb 
-    simdscalar vComp3 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(3))*offset)); // float32 aaaaaaaa 
+    simdscalar vComp2 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(2))*offset)); // float32 bbbbbbbb
+    simdscalar vComp3 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(3))*offset)); // float32 aaaaaaaa
 
     // clamp
     vComp0 = _simd_max_ps(vComp0, _simd_setzero_ps());
@@ -607,15 +607,15 @@ INLINE static void FlatConvert(const uint8_t* pSrc, uint8_t* pDst, uint8_t* pDst
     }
 
     // convert float components from 0.0f .. 1.0f to correct scale for 0 .. 255 dest format
-    vComp0 = _simd_mul_ps(vComp0, _simd_set1_ps(FormatTraits<DstFormat>::fromFloat(0))); 
+    vComp0 = _simd_mul_ps(vComp0, _simd_set1_ps(FormatTraits<DstFormat>::fromFloat(0)));
     vComp1 = _simd_mul_ps(vComp1, _simd_set1_ps(FormatTraits<DstFormat>::fromFloat(1)));
     vComp2 = _simd_mul_ps(vComp2, _simd_set1_ps(FormatTraits<DstFormat>::fromFloat(2)));
     vComp3 = _simd_mul_ps(vComp3, _simd_set1_ps(FormatTraits<DstFormat>::fromFloat(3)));
 
     // moving to 8 wide integer vector types
     simdscalari src0 = _simd_cvtps_epi32(vComp0); // padded byte rrrrrrrr
-    simdscalari src1 = _simd_cvtps_epi32(vComp1); // padded byte gggggggg 
-    simdscalari src2 = _simd_cvtps_epi32(vComp2); // padded byte bbbbbbbb 
+    simdscalari src1 = _simd_cvtps_epi32(vComp1); // padded byte gggggggg
+    simdscalari src2 = _simd_cvtps_epi32(vComp2); // padded byte bbbbbbbb
     simdscalari src3 = _simd_cvtps_epi32(vComp3); // padded byte aaaaaaaa
 
 #if KNOB_ARCH <= KNOB_ARCH_AVX
@@ -743,9 +743,9 @@ INLINE static void FlatConvertNoAlpha(const uint8_t* pSrc, uint8_t* pDst, uint8_
     static const uint32_t offset = sizeof(simdscalar);
 
     // swizzle rgba -> bgra while we load
-    simdscalar vComp0 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(0))*offset)); // float32 rrrrrrrr 
+    simdscalar vComp0 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(0))*offset)); // float32 rrrrrrrr
     simdscalar vComp1 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(1))*offset)); // float32 gggggggg
-    simdscalar vComp2 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(2))*offset)); // float32 bbbbbbbb 
+    simdscalar vComp2 = _simd_load_ps((const float*)(pSrc + (FormatTraits<DstFormat>::swizzle(2))*offset)); // float32 bbbbbbbb
                                                                                                             // clamp
     vComp0 = _simd_max_ps(vComp0, _simd_setzero_ps());
     vComp0 = _simd_min_ps(vComp0, _simd_set1_ps(1.0f));
@@ -771,8 +771,8 @@ INLINE static void FlatConvertNoAlpha(const uint8_t* pSrc, uint8_t* pDst, uint8_
 
     // moving to 8 wide integer vector types
     simdscalari src0 = _simd_cvtps_epi32(vComp0); // padded byte rrrrrrrr
-    simdscalari src1 = _simd_cvtps_epi32(vComp1); // padded byte gggggggg 
-    simdscalari src2 = _simd_cvtps_epi32(vComp2); // padded byte bbbbbbbb 
+    simdscalari src1 = _simd_cvtps_epi32(vComp1); // padded byte gggggggg
+    simdscalari src2 = _simd_cvtps_epi32(vComp2); // padded byte bbbbbbbb
 
 #if KNOB_ARCH <= KNOB_ARCH_AVX
 
@@ -1062,13 +1062,13 @@ struct OptStoreRasterTile< TilingTraits<SWR_TILE_NONE, 8>, SrcFormat, DstFormat>
             return GenericStoreTile::Store(pSrc, pDstSurface, x, y, sampleNum, renderTargetArrayIndex);
         }
 
-        uint8_t *pDst = (uint8_t*)ComputeSurfaceAddress<false, false>(x, y, pDstSurface->arrayIndex + renderTargetArrayIndex, 
+        uint8_t *pDst = (uint8_t*)ComputeSurfaceAddress<false, false>(x, y, pDstSurface->arrayIndex + renderTargetArrayIndex,
             pDstSurface->arrayIndex + renderTargetArrayIndex, sampleNum, pDstSurface->lod, pDstSurface);
 
         const uint32_t dx = SIMD16_TILE_X_DIM * DST_BYTES_PER_PIXEL;
         const uint32_t dy = SIMD16_TILE_Y_DIM * pDstSurface->pitch - KNOB_TILE_X_DIM * DST_BYTES_PER_PIXEL;
 
-        uint8_t* ppDsts[] = 
+        uint8_t* ppDsts[] =
         {
             pDst,                                           // row 0, col 0
             pDst + pDstSurface->pitch,                      // row 1, col 0
@@ -1127,7 +1127,7 @@ struct OptStoreRasterTile< TilingTraits<SWR_TILE_NONE, 16>, SrcFormat, DstFormat
             return GenericStoreTile::Store(pSrc, pDstSurface, x, y, sampleNum, renderTargetArrayIndex);
         }
 
-        uint8_t *pDst = (uint8_t*)ComputeSurfaceAddress<false, false>(x, y, pDstSurface->arrayIndex + renderTargetArrayIndex, 
+        uint8_t *pDst = (uint8_t*)ComputeSurfaceAddress<false, false>(x, y, pDstSurface->arrayIndex + renderTargetArrayIndex,
             pDstSurface->arrayIndex + renderTargetArrayIndex, sampleNum, pDstSurface->lod, pDstSurface);
 
         const uint32_t dx = SIMD16_TILE_X_DIM * DST_BYTES_PER_PIXEL;
index 83ea856ecd703b4387907d0c6c850d79204ccc7c..e552bc6bd0e7b1d71cfc863a29e55af538a7926c 100644 (file)
@@ -491,7 +491,7 @@ swr_create_context(struct pipe_screen *p_screen, void *priv, unsigned flags)
 {
    struct swr_context *ctx = (struct swr_context *)
       AlignedMalloc(sizeof(struct swr_context), KNOB_SIMD_BYTES);
-   memset(ctx, 0, sizeof(struct swr_context));
+   memset((void*)ctx, 0, sizeof(struct swr_context));
 
    swr_screen(p_screen)->pfnSwrGetInterface(ctx->api);
    swr_screen(p_screen)->pfnSwrGetTileInterface(ctx->tileApi);
index 5f4ba348629f3ecad71fcc46cd1dec44999c6dba..ab8b00a5d96dc6389e4469e410bf2415b9634d43 100644 (file)
@@ -189,7 +189,7 @@ swr_generate_fs_key(struct swr_jit_fs_key &key,
                     struct swr_context *ctx,
                     swr_fragment_shader *swr_fs)
 {
-   memset(&key, 0, sizeof(key));
+   memset((void*)&key, 0, sizeof(key));
 
    key.nr_cbufs = ctx->framebuffer.nr_cbufs;
    key.light_twoside = ctx->rasterizer->light_twoside;
@@ -221,7 +221,7 @@ swr_generate_vs_key(struct swr_jit_vs_key &key,
                     struct swr_context *ctx,
                     swr_vertex_shader *swr_vs)
 {
-   memset(&key, 0, sizeof(key));
+   memset((void*)&key, 0, sizeof(key));
 
    key.clip_plane_mask =
       swr_vs->info.base.clipdist_writemask ?
@@ -235,7 +235,7 @@ void
 swr_generate_fetch_key(struct swr_jit_fetch_key &key,
                        struct swr_vertex_element_state *velems)
 {
-   memset(&key, 0, sizeof(key));
+   memset((void*)&key, 0, sizeof(key));
 
    key.fsState = velems->fsState;
 }
@@ -245,7 +245,7 @@ swr_generate_gs_key(struct swr_jit_gs_key &key,
                     struct swr_context *ctx,
                     swr_geometry_shader *swr_gs)
 {
-   memset(&key, 0, sizeof(key));
+   memset((void*)&key, 0, sizeof(key));
 
    struct tgsi_shader_info *pPrevShader = nullptr;
 
@@ -270,7 +270,7 @@ swr_generate_tcs_key(struct swr_jit_tcs_key &key,
                     struct swr_context *ctx,
                     swr_tess_control_shader *swr_tcs)
 {
-   memset(&key, 0, sizeof(key));
+   memset((void*)&key, 0, sizeof(key));
 
    struct tgsi_shader_info *pPrevShader = &ctx->vs->info.base;
 
@@ -294,7 +294,7 @@ swr_generate_tes_key(struct swr_jit_tes_key &key,
                     struct swr_context *ctx,
                     swr_tess_evaluation_shader *swr_tes)
 {
-   memset(&key, 0, sizeof(key));
+   memset((void*)&key, 0, sizeof(key));
 
    struct tgsi_shader_info *pPrevShader = nullptr;
 
index 4e9a25345a39d4fd04fe3d088e704705ad64bb4d..01758f5f9101a069bfa6273fc8083a47553d69e5 100644 (file)
@@ -584,7 +584,7 @@ swr_create_vertex_elements_state(struct pipe_context *pipe,
    assert(num_elements <= PIPE_MAX_ATTRIBS);
    velems = new swr_vertex_element_state;
    if (velems) {
-      memset(&velems->fsState, 0, sizeof(velems->fsState));
+      memset((void*)&velems->fsState, 0, sizeof(velems->fsState));
       velems->fsState.bVertexIDOffsetEnable = true;
       velems->fsState.numAttribs = num_elements;
       for (unsigned i = 0; i < num_elements; i++) {