While finishing the optimisations on EvoGUI , getting ready for v1.0 in a few days, I've found one strange thing in my tests and careful measurements.
It seems that creating a render surface at the beginning of my app takes less time than after it is left running for a while. The conclusion is that the command
Surface = Scene.CreateRenderSurface gets slower after each previous such command (followed correctly by
Surface.Destroy) In other words, if you create and destroy the same surface many times, creating it again becomes slower.
I've made a little benchmarking app in VB, and you can test it for yourself. The code is included below.
I have originaly noticed the slowdown using the CreateAlphaRenderSurface command, but it's the same with CreateRenderSurface. On my test machine, core2duo 6750 @ 2.8 ghz , gforce 8800gt, the 3000 iterations in the test code below generate a 900% increase (9 times as slow) in the needed time to create and destroy a surface. 1000 iterations create a 250% slowdown.
Note however that I did perform more accurate tests separately and that Surface.Destroy() does not get slower, only Scene.CreateRenderSurface does.
So my question is: is this a TV thing or a DX thing? It could be TV if the surfaces get accumulating pointers/indexes and the new ones take increasingly longer to create because of the system needing to iterate through previously created ones if they are not removed when Surface.Destroy is used? I can imagine such an error being done by accident, happened to me. I didn't test surface creation in DirectX itself, but I may do that too.
If it's a TV thing, I'll post it as a bug. Thanks!
Imports MTV3D65
Public Class frmMain
Inherits System.Windows.Forms.Form
Public TV As TVEngine
Public Scene As TVScene
Public Inp As TVInputEngine
Public bDoLoop As Boolean
Public timer As System.Diagnostics.Stopwatch
Public TempSurface As TVRenderSurface
Declare Function GetFocus Lib "user32" () As Integer
#Region " Windows Form Designer generated code "
...
#End Region
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim Time1, Time2 As Long
TV = New TVEngine
TV.SetDebugMode(True, True)
TV.SetDebugFile(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\debugfile.txt")
TV.Init3DWindowed(Me.Handle, True)
TV.GetViewport.SetAutoResize(True)
Scene = New TVScene
Inp = New TVInputEngine
Inp.Initialize(True, True)
timer = New System.Diagnostics.Stopwatch
bDoLoop = True
Me.Show()
Me.Focus()
' Starts of test ----------------
timer.Reset()
timer.Start()
For i = 0 To 10
TempSurface = Scene.CreateRenderSurface(256, 256)
TempSurface.Destroy()
Next
timer.Stop()
Time1 = timer.ElapsedTicks
For i = 0 To 3000
TempSurface = Scene.CreateRenderSurface(256, 256)
TempSurface.Destroy()
Next
timer.Reset()
timer.Start()
For i = 0 To 10
TempSurface = Scene.CreateRenderSurface(256, 256)
TempSurface.Destroy()
Next
timer.Stop()
Time2 = timer.ElapsedTicks
If Time2 > Time1 Then
MsgBox("Time 2 is " + CStr(Time2 - Time1) + "ticks longer than Time1. This is a " + CStr(CInt((Time2 / Time1) * 100)) + " % increase!")
Else
MsgBox("On your machine, the increase does not seem to occur. Please tell this to the rest of the TV3D community!")
End If
' End of test ----------------
Do While bDoLoop
If GetFocus = Me.Handle.ToInt32 Then
TV.Clear(False)
Scene.RenderAll(True)
TV.RenderToScreen()
If Inp.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_ESCAPE) Then bDoLoop = False
Else
System.Threading.Thread.Sleep(100)
End If
Application.DoEvents()
Loop
TV = Nothing
End
End Sub
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
bDoLoop = False
End Sub
End Class