Recent

Author Topic: a bug?  (Read 6349 times)

cd

  • Jr. Member
  • **
  • Posts: 54
a bug?
« on: April 21, 2012, 02:31:41 am »
hi circular

look at screenshots

first is done with FillPolyLinearMapping(..., True)
second with FillPolyLinearMapping(..., False)

is it a bug or i do smth wrong?

circular

  • Hero Member
  • *****
  • Posts: 3049
    • Personal webpage
Re: a bug?
« Reply #1 on: April 22, 2012, 05:22:48 pm »
It seems like a bug. Maybe a SSE issue.

Texture interpolation should give the same result except with interpolation between pixels.

Try to disable SSE by changing this in BGRASSE :
Code: [Select]
FLAG_ENABLED_SSE = true;
To this :
Code: [Select]
FLAG_ENABLED_SSE = false;
I will have a look at this.
Conscience is the debugger of the mind

cd

  • Jr. Member
  • **
  • Posts: 54
Re: a bug?
« Reply #2 on: April 22, 2012, 06:39:44 pm »
yes you are right

that should be sse - with sse disabled the bug is not seen any more.

how much does sse affect speed?

circular

  • Hero Member
  • *****
  • Posts: 3049
    • Personal webpage
Re: a bug?
« Reply #3 on: April 23, 2012, 12:25:36 am »
Ok, i found the bug in SSE code. Try to replace lineartexscan2.inc by
Code: [Select]
      {$IFDEF PARAM_USESSE} {$asmmode intel}
      asm
         xorps xmm4,xmm4
         xorps xmm5,xmm5
         movlps xmm4, texPos
         movlps xmm5, texStep
         {$IFNDEF PARAM_USEINTERPOLATION}
           {$IFDEF PARAM_USESSE2}
           cvtps2dq xmm3,xmm4
           movlps intTexPos,xmm3
           {$ENDIF}
         {$ENDIF}
      end;
      {$ENDIF}

      for i := ix1 to ix2 do
      begin
        DrawPixelInlineWithAlphaCheck(pdest,
          {$IFDEF PARAM_USELIGHTING} ApplyLightnessFast( {$ENDIF}
          {$IFDEF PARAM_USEINTERPOLATION}
            scanAtFunc(texPos.x,texPos.y)
          {$ELSE}
            {$IFDEF PARAM_USESSE2}
              scanAtIntegerFunc(intTexPos.x,intTexPos.y)
            {$ELSE}
              scanAtIntegerFunc(round(texPos.x),round(texPos.y))
            {$ENDIF}
          {$ENDIF}
          {$IFDEF PARAM_USELIGHTING} ,light) {$ENDIF}
          );
        {$IFDEF PARAM_USESSE}
        asm
           addps xmm4,xmm5
           {$IFNDEF PARAM_USEINTERPOLATION}
             {$IFDEF PARAM_USESSE2}
             cvtps2dq xmm3,xmm4
             movlps intTexPos,xmm3
             {$ELSE}
             movlps texPos,xmm4
             {$ENDIF}
           {$ELSE}
             movlps texPos,xmm4
           {$ENDIF}
        end;
        {$ELSE}
          texPos += texStep;
        {$ENDIF}

        {$IFDEF PARAM_USELIGHTING}
          NextLight;
        {$ENDIF}
        inc(pdest);
      end;

Quote
how much does sse affect speed?
It depends on what you are doing. For FillPolyLinearMapping without texture interpolation, I get 10% faster with SSE. For other things, you may get the same speed, or sometimes really faster. Use EpikTimer to check this and show time with something like :
Code: [Select]
b.TextOut(0,0,inttostr(round(timer.Elapsed*1000))+' ms',CSSOrange);
Conscience is the debugger of the mind

cd

  • Jr. Member
  • **
  • Posts: 54
Re: a bug?
« Reply #4 on: April 23, 2012, 01:12:07 am »
thank you, now it works with sse lfag enabled.

will now continue hacking your library. It made a valuable progress since i first tried it on 30 March 2010! =) looking forward to using it in my next project!

circular

  • Hero Member
  • *****
  • Posts: 3049
    • Personal webpage
Re: a bug?
« Reply #5 on: April 23, 2012, 05:12:39 pm »
Ok thanks for testing.

I've updated the library with the above changes on subversion.

If you have any idea on how to improve the library, feel free to propose.
Conscience is the debugger of the mind

cd

  • Jr. Member
  • **
  • Posts: 54
Re: a bug?
« Reply #6 on: April 23, 2012, 05:45:12 pm »
a real layering as in graphics32 would be nice.

to improve fps in a full-form gui i now use a per-tile drawing mechanism (tile size is changable). only those tiles are used in drawing which are affected. of course there is an option to draw all - which is called on form invalidation. that would be nice if the library did it for me. this optimisation drastically improved gui responce -  i'm now able to create really fast and beautiful gesture gui with my 17" touchscreen (computer is rather slow, straight-forward approach gave 10-12 fps, tile-based is up to 50 "fps" when excluding stationary bitmap areas). i can send you a test application if you think this could be implemented in library.

circular

  • Hero Member
  • *****
  • Posts: 3049
    • Personal webpage
Re: a bug?
« Reply #7 on: April 23, 2012, 08:51:15 pm »
That's interesting. Of course you can send me some test application. How big is it?

Would it be like an enhancement of BGRALayers ?
Conscience is the debugger of the mind

cd

  • Jr. Member
  • **
  • Posts: 54
Re: a bug?
« Reply #8 on: April 23, 2012, 10:19:18 pm »
the code

change
draw_debug := False
to
draw_debug := true
on line 123 of unit1 to see tiles working.

this is a test project for myself so it is not very good written and there is not much comments. but if smth is unclear i can answer here.

circular

  • Hero Member
  • *****
  • Posts: 3049
    • Personal webpage
Re: a bug?
« Reply #9 on: April 24, 2012, 09:33:46 pm »
Ok. I understand what you did. That's interesting.

Note that drawing on a canvas outside an OnPaint event does not work on MacOS. Does someone know how to bypass this ?

If we need to paint everything, well, the speed will not be so high. It would still be useful if the rendering of the tile content is slow, so that it works like a buffer.

We can try to go toward implementing it in the library. First of all, it should be in a class. To do so, create a separate unit with a type definition, something like :
Code: [Select]
type TTiledSurface = class
...

And every procedure that is linked to this subject should be moved into it (MarkDrawTiles, Draw). Some variable names are not really understandable, for example b_image for BackgroundImage. Also add BackgroundColor, so that if there is no BackgroundImage, the tile is filled with this color.

CreateImages should be split into two parts. One is about freeing previous tiles and resizing the array.

Another is about what the user wants to do. In your example, you set the background image. This can be handled for example in a virtual procedure. Do you know what this is ?
Conscience is the debugger of the mind