From 4e991c3e6f016b133295005654782d12426efb31 Mon Sep 17 00:00:00 2001 From: Kieron Morris Date: Sun, 30 Jan 2022 00:17:50 +0000 Subject: [PATCH] Double Buffer with SSE 128 copy working --- src/driver/video/doublebuffer.pas | 15 +++++++-------- src/include/util.pas | 6 +++--- src/kernel.pas | 29 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/driver/video/doublebuffer.pas b/src/driver/video/doublebuffer.pas index dfff1206..36f1ecd7 100644 --- a/src/driver/video/doublebuffer.pas +++ b/src/driver/video/doublebuffer.pas @@ -55,25 +55,24 @@ end; procedure Flush(FrontBuffer : PVideoBuffer; BackBuffer : PVideoBuffer); var idx : uint32; - Back,Front : PuInt64; + Back,Front : uint32; BufferSize : uint32; const - COPY_WIDTH = 64; + //COPY_WIDTH = 64; //Use this for 64bit copies + COPY_WIDTH = 128; //Use this for SSE copies begin //tracer.push_trace('doublebuffer.Flush.enter'); if not(BackBuffer^.Initialized) then exit; if ((FrontBuffer^.Width > BackBuffer^.Width) or (FrontBuffer^.Height > BackBuffer^.Height)) then exit; - Back:= PUint64(BackBuffer^.Location); - Front:= PuInt64(FrontBuffer^.Location); + Back:= BackBuffer^.Location; + Front:= FrontBuffer^.Location; BufferSize:= ( ( BackBuffer^.Width * BackBuffer^.Height * BackBuffer^.BitsPerPixel) div COPY_WIDTH ) - 1; for idx:=0 to BufferSize do begin - Front[idx]:= Back[idx]; + //Front[idx]:= Back[idx]; // -- TODO: Get SSE working here for 128bit copies -- - // __SSE_128_memcpy(uint32(Front), uint32(Back)); - // Front:= PUint64(uint32(Front) + 16); - // Back:= PUint64(uint32(Back) + 16); + __SSE_128_memcpy(Back + (idx * 16), Front + (idx * 16)); end; //tracer.push_trace('doublebuffer.Flush.exit'); end; diff --git a/src/include/util.pas b/src/include/util.pas index ac648a11..77069499 100644 --- a/src/include/util.pas +++ b/src/include/util.pas @@ -131,9 +131,9 @@ end; procedure __SSE_128_memcpy(source : uint32; dest : uint32); assembler; asm MOV EAX, Source - MOV ECX, Dest - MOVUPS XMM0, [EAX] - MOVUPS [ECX], XMM0 + MOVAPS XMM1, [EAX] + MOV EAX, Dest + MOVAPS [EAX], XMM1 end; function switchendian16(b : uint16) : uint16; diff --git a/src/kernel.pas b/src/kernel.pas index eb0c7ea8..d36f5e4d 100644 --- a/src/kernel.pas +++ b/src/kernel.pas @@ -126,6 +126,9 @@ var HM : PHashMap; colour : TRGB32; + + array1 : Array[0..255] of char; + array2 : Array[0..255] of char; begin { Init the base system unit } @@ -213,6 +216,32 @@ begin video.enable('BASIC_DOUBLE_BUFFER'); colour:= color.white; + // serial.sendHex(uint32(@array1[8])); + // serial.sendHex(uint32(@array2[8])); + // for i:=8 to 23 do begin + // array2[i]:= '?'; + // end; + // array2[24]:= #0; + + // array1[8]:= 'H'; + // array1[9]:= 'e'; + // array1[10]:= 'l'; + // array1[11]:= 'l'; + // array1[12]:= 'o'; + // array1[13]:= 'w'; + // array1[14]:= 'o'; + // array1[15]:= 'r'; + // array1[16]:= 'l'; + // array1[17]:= 'd'; + // array1[18]:= '1'; + // array1[19]:= '2'; + // array1[20]:= '3'; + // array1[21]:= '4'; + // array1[22]:= '5'; + // array1[23]:= '!'; + // __SSE_128_memcpy(uint32(@array1[8]), uint32(@array2[8])); + // serial.sendString(pchar(@array2[8])); + for i:=0 to video.frontBufferWidth-1 do begin for z:=0 to video.frontBufferHeight-1 do begin video.DrawPixel(i, z, colour);