From b26f27d9e3fd44ec5775accdc3666a339684be4c Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Mon, 1 Aug 2022 20:03:12 -0400 Subject: large changes to bitmap structure --- bitmap_calls.cpp | 107 +++++++++++++++++++++++++------------------------------ 1 file changed, 49 insertions(+), 58 deletions(-) (limited to 'bitmap_calls.cpp') diff --git a/bitmap_calls.cpp b/bitmap_calls.cpp index 132aec5..09d1cb1 100644 --- a/bitmap_calls.cpp +++ b/bitmap_calls.cpp @@ -6,28 +6,29 @@ // 0 - store in 4x4 chunks // 1 - unpack to 1xwidth -internal void -Convert4x4Chunk(pixel_buffer *Buffer, uint8 Which) +void Bitmap_ConvertPacking(void *Buffer, void *DestBuffer, uint16 Width, uint16 Height, uint16 BytesPerPixel, uint16 Which) { - uint8 *Src = (uint8 *)Buffer->OriginalBuffer; - uint8 *Temp = (uint8 *)Buffer->EffectBuffer; - uint32 RemainderPixels = Buffer->Width % 4; - for (uint32 Y = 0; Y < Buffer->Height; Y++) { + uint8 *Src = (uint8 *)Buffer; + uint8 *Temp = (uint8 *)DestBuffer; + uint32 RemainderPixels = Width % 4; + for (uint32 Y = 0; Y < Height; Y++) { uint32 X = 0; - while (X < Buffer->Width - RemainderPixels) { + while (X < Width - RemainderPixels) { + uint16 WidthP, HeightP; + Bitmap_CalcPackedDimensions(Width, Height, &WidthP, &HeightP); uint32 XLookup = (X >> 2)*16 + (X % 4); - uint32 YLookup = (Y >> 2)*(Buffer->FullWidth*4) + (Y % 4)*4; + uint32 YLookup = (Y >> 2)*(WidthP*4) + (Y % 4)*4; uint32 PixelToSeek = XLookup + YLookup; uint8 *DPixel, *Pixel; if (Which == 0) { - DPixel = Temp + PixelToSeek*Buffer->BytesPerPixel; - Pixel = Src + Y*Buffer->Width*4 + X*Buffer->BytesPerPixel; + DPixel = Temp + PixelToSeek*BytesPerPixel; + Pixel = Src + Y*Width*4 + X*BytesPerPixel; } else { - Pixel = Src + PixelToSeek*Buffer->BytesPerPixel; - DPixel = Temp + Y*Buffer->Width*4 + X*Buffer->BytesPerPixel; + Pixel = Src + PixelToSeek*BytesPerPixel; + DPixel = Temp + Y*Width*4 + X*BytesPerPixel; } - if (InstructionMode == sse_enabled || InstructionMode == avx_enabled) { + if (InstructionMode == instruction_mode_sse || InstructionMode == instruction_mode_avx) { __m128i Row = _mm_loadu_si128((__m128i *)Pixel); _mm_storeu_si128((__m128i *)DPixel, Row); X+=4; @@ -36,17 +37,19 @@ Convert4x4Chunk(pixel_buffer *Buffer, uint8 Which) X++; } } - while (X < Buffer->Width) { + while (X < Width) { + uint16 WidthP, HeightP; + Bitmap_CalcPackedDimensions(Width, Height, &WidthP, &HeightP); uint32 XLookup = (X >> 2)*16 + (X % 4); - uint32 YLookup = (Y >> 2)*(Buffer->FullWidth*4) + (Y % 4)*4; + uint32 YLookup = (Y >> 2)*(WidthP*4) + (Y % 4)*4; uint32 PixelToSeek = XLookup + YLookup; uint8 *DPixel, *Pixel; if (Which == 0) { - DPixel = Temp + PixelToSeek*Buffer->BytesPerPixel; - Pixel = Src + Y*Buffer->Width*4 + X*Buffer->BytesPerPixel; + DPixel = Temp + PixelToSeek*BytesPerPixel; + Pixel = Src + Y*Width*4 + X*BytesPerPixel; } else { - Pixel = Src + PixelToSeek*Buffer->BytesPerPixel; - DPixel = Temp + Y*Buffer->Width*4 + X*Buffer->BytesPerPixel; + Pixel = Src + PixelToSeek*BytesPerPixel; + DPixel = Temp + Y*Width*4 + X*BytesPerPixel; } *(uint32 *)DPixel = *(uint32 *)Pixel; @@ -56,27 +59,23 @@ Convert4x4Chunk(pixel_buffer *Buffer, uint8 Which) } // TODO(fox): Replace this in the future. -internal void * +#if 0 +static void * MoveImportToBitmap(memory *Memory, pixel_buffer *Raster, void *Input) { uint8 *Row = ((uint8 *)Input); - void *Output = AllocateMemory(Memory, Raster->FullWidth * Raster->FullHeight * Raster->BytesPerPixel, B_Scratch); + // void *Output = AllocateMemory(Memory, Bitmap_CalcTotalBytes(Raster->Width, Raster->Height, Raster->BytesPerPixel), B_Layers); uint8 *Row2 = ((uint8 *)Output); uint64 bytes = 0; - uint16 ByteOffset = Raster->BytesPerPixel; - if (InstructionMode == avx_enabled) - ByteOffset = 8*Raster->BytesPerPixel; - else if (InstructionMode == avx_enabled) - ByteOffset = 4*Raster->BytesPerPixel; - - uint64 TotalBytes = Raster->Height*Raster->Width*Raster->BytesPerPixel; + uint16 ByteOffset = Bitmap_CalculateByteOffset(BytesPerPixel); + uint64 TotalBytes = Bitmap_CalculateTotalBytes(Width, Height, BytesPerPixel); uint64 RemainderBytes = TotalBytes % ByteOffset; while (bytes <= TotalBytes - RemainderBytes) { uint8 *Pixel = (uint8 *)Row + bytes; uint8 *Pixel2 = (uint8 *)Row2 + bytes; - if (InstructionMode == sse_enabled || InstructionMode == avx_enabled) { + if (InstructionMode == instruction_mode_sse || InstructionMode == instruction_mode_avx) { __m128i OutputPixel = _mm_loadu_si128((__m128i *)Pixel); _mm_storeu_si128((__m128i *)Pixel2, OutputPixel); bytes += 4*Raster->BytesPerPixel; @@ -93,28 +92,24 @@ MoveImportToBitmap(memory *Memory, pixel_buffer *Raster, void *Input) } return Output; } +#endif -internal void -ClearBuffer(pixel_buffer *Raster, void *Buffer) +static void +Bitmap_Clear(void *Buffer, uint16 Width, uint16 Height, uint16 BytesPerPixel) { uint8 *Row = (uint8 *)Buffer; __m256i Zero8 = _mm256_setzero_si256(); __m128i Zero = _mm_setzero_si128(); - uint64 bytes = 0; - uint16 ByteOffset = Raster->BytesPerPixel; - if (InstructionMode == avx_enabled) - ByteOffset = 8*Raster->BytesPerPixel; - else if (InstructionMode == avx_enabled) - ByteOffset = 4*Raster->BytesPerPixel; - uint64 TotalBytes = Raster->FullHeight*Raster->FullWidth*Raster->BytesPerPixel; + uint16 ByteOffset = Bitmap_CalcByteOffset(BytesPerPixel); + uint64 TotalBytes = Bitmap_CalcTotalBytes(Width, Height, BytesPerPixel); while (bytes < TotalBytes) { uint8 *Pixel = Row + bytes; - if (InstructionMode == avx_enabled) { + if (InstructionMode == instruction_mode_avx) { _mm256_storeu_si256((__m256i *)Pixel, Zero8); - } else if (InstructionMode == sse_enabled) { + } else if (InstructionMode == instruction_mode_sse) { _mm_storeu_si128((__m128i *)Pixel, Zero); } else { *(uint32 *)Pixel = 0x00000000; @@ -122,10 +117,10 @@ ClearBuffer(pixel_buffer *Raster, void *Buffer) bytes += ByteOffset; } } - +#if 0 // 0 - original -> effect // 1 - effect -> original -internal void +static void CopyToBuffer(pixel_buffer *Raster, uint16 Which) { uint8 *Row, *Row2; @@ -138,19 +133,14 @@ CopyToBuffer(pixel_buffer *Raster, uint16 Which) } uint64 bytes = 0; - uint16 ByteOffset = Raster->BytesPerPixel; - if (InstructionMode == avx_enabled) - ByteOffset = 8*Raster->BytesPerPixel; - else if (InstructionMode == avx_enabled) - ByteOffset = 4*Raster->BytesPerPixel; - - uint64 TotalBytes = Raster->FullHeight*Raster->FullWidth*Raster->BytesPerPixel; + uint16 ByteOffset = Bitmap_CalculateByteOffset(BytesPerPixel); + uint64 TotalBytes = Bitmap_CalculateTotalBytes(Width, Height, BytesPerPixel); uint64 RemainderBytes = TotalBytes % ByteOffset; while (bytes <= TotalBytes - RemainderBytes) { uint8 *Pixel = (uint8 *)Row + bytes; uint8 *Pixel2 = (uint8 *)Row2 + bytes; - if (InstructionMode == sse_enabled || InstructionMode == avx_enabled) { + if (InstructionMode == instruction_mode_sse || InstructionMode == instruction_mode_avx) { __m128i OutputPixel = _mm_loadu_si128((__m128i *)Pixel); _mm_storeu_si128((__m128i *)Pixel2, OutputPixel); bytes += 4*Raster->BytesPerPixel; @@ -167,7 +157,7 @@ CopyToBuffer(pixel_buffer *Raster, uint16 Which) } } -internal void +static void BitmapPackRGB(pixel_buffer *Buffer) { Assert(Buffer->Pitch); Convert4x4Chunk(Buffer, 0); @@ -175,7 +165,7 @@ BitmapPackRGB(pixel_buffer *Buffer) { ClearBuffer(Buffer, Buffer->EffectBuffer); } -internal void +static void OutputToViewport(pixel_buffer *CompBuffer, project_state *State, GLuint textureID) { Convert4x4Chunk(CompBuffer, 1); EndRenderState(State); @@ -184,7 +174,7 @@ OutputToViewport(pixel_buffer *CompBuffer, project_state *State, GLuint textureI CompBuffer->EffectBuffer); } -internal void +static void DebugFillSolid(pixel_buffer *Raster, v4 Color) { uint32 ColS = ColToUint32(Color); @@ -194,18 +184,18 @@ DebugFillSolid(pixel_buffer *Raster, v4 Color) uint64 bytes = 0; uint16 ByteOffset = Raster->BytesPerPixel; - if (InstructionMode == avx_enabled) + if (InstructionMode == instruction_mode_avx) ByteOffset = 8*Raster->BytesPerPixel; - else if (InstructionMode == avx_enabled) + else if (InstructionMode == instruction_mode_sse) ByteOffset = 4*Raster->BytesPerPixel; uint64 TotalBytes = Raster->FullHeight*Raster->FullWidth*Raster->BytesPerPixel; while (bytes < TotalBytes) { uint8 *Pixel = Row + bytes; - if (InstructionMode == avx_enabled) { + if (InstructionMode == instruction_mode_avx) { _mm256_storeu_si256((__m256i *)Pixel, Col8); - } else if (InstructionMode == sse_enabled) { + } else if (InstructionMode == instruction_mode_sse) { _mm_storeu_si128((__m128i *)Pixel, Col); } else { *(uint32 *)Pixel = ColS; @@ -214,7 +204,7 @@ DebugFillSolid(pixel_buffer *Raster, v4 Color) } } -internal void +static void DebugBitmap(pixel_buffer *Raster) { uint8 asda = 0x0; @@ -233,3 +223,4 @@ DebugBitmap(pixel_buffer *Raster) } } } +#endif -- cgit v1.2.3