Author Topic: The Ascended ASM game creation thread  (Read 1901 times)

Ascended

  • Member
  • ***
  • Posts: 331
Re: Lonewolff's ASM game creation thread
« Reply #15 on: April 12, 2018, 07:00:53 PM »
So the benchmarks are in

Presently get an erratic frame rate in C++ of 6000 to 7500 FPS.

Frame rate is currently slower in ASM but is a very solid ~6000 FPS.

Ascended

  • Member
  • ***
  • Posts: 331
Re: Lonewolff's ASM game creation thread
« Reply #16 on: April 13, 2018, 09:30:36 AM »
Probably premature. But would be interesting to see how (and if) this runs for other people.

The DX initialisation still needs a little more work to make it robust, but should do the job.

I have attached the current build below.  :t

(Bear in mind it will only work on Windows 7 and above, as this is the minimum platform required for DirectX 11  :idea:)

Siekmanski

  • Member
  • *****
  • Posts: 1600
Re: Lonewolff's ASM game creation thread
« Reply #17 on: April 13, 2018, 10:27:52 AM »
 8) 5500 FPS ( NVIDIA GeForce GTX 770 )
Creative coders use backward thinking techniques as their strategy.

jj2007

  • Member
  • *****
  • Posts: 8608
  • Assembler is fun ;-)
    • MasmBasic
Re: Lonewolff's ASM game creation thread
« Reply #18 on: April 13, 2018, 10:35:25 AM »
Probably premature. But would be interesting to see how (and if) this runs for other people.

On Win7-64, I see just a white rectangle. One core is at 50%.

Ascended

  • Member
  • ***
  • Posts: 331
Re: Lonewolff's ASM game creation thread
« Reply #19 on: April 13, 2018, 11:37:40 AM »
Nice!  :t

Thanks guys. Hopefully something nicer and more interactive on the next test  :biggrin:

Ascended

  • Member
  • ***
  • Posts: 331
Re: Lonewolff's ASM game creation thread
« Reply #20 on: April 15, 2018, 04:49:50 PM »
Going great with this project. Everything is getting laid out nicely.  8)

Spent time refactoring the code in to nice re-usable proto's.

Now on to the nasty 3D mathematics - Ugghh! Not my strong point. Gotta be done though, as a personal rite of passage. On to that right now.  :t

LordAdef

  • Member
  • ****
  • Posts: 588
Re: Lonewolff's ASM game creation thread
« Reply #21 on: April 15, 2018, 04:54:37 PM »
I'm curious to see your original c++ project in action. The avatar picture from the game is great.

By the way, once in a while, put some code here for us to check out

Ascended

  • Member
  • ***
  • Posts: 331
Re: Lonewolff's ASM game creation thread
« Reply #22 on: April 15, 2018, 05:47:46 PM »
At this stage this is what the main application and loop looks like

Code: [Select]
.code
WinMain proc
local windowWidth:dword
local windowHeight:dword
mov windowWidth, 1280
mov windowHeight, 720

; Create window
invoke SystemWindowCreate, windowWidth, windowHeight
mov hWnd, eax

; Create device and swap chain
invoke SystemDeviceCreate, windowWidth, windowHeight, hWnd

; Create vertex shader
mov ecx, SIZEOFvertexShaderData
invoke ShaderVertexCreate, addr d3dVertexShader, addr vertexShaderData, ecx

; Create pixel shader
mov ecx, SIZEOFpixelShaderData
invoke ShaderPixelCreate, addr d3dPixelShader, addr pixelShaderData, ecx


; Create input layout XY
mov ecx, SIZEOFvertexShaderData
coinvoke d3dDevice, ID3D11Device, CreateInputLayout, addr inputDescP, 1, addr vertexShaderData, ecx, addr d3dInputLayout
invoke SystemError, TEXT_("Failed to create input layout.")

; Create vetex buffer
coinvoke d3dDevice, ID3D11Device, CreateBuffer, addr vertexDesc, addr resourceData, addr d3dVertexBuffer
invoke SystemError, TEXT_("Failed to create vertex buffer.")

; Reset performance counters
invoke QueryPerformanceFrequency, addr TimeFrequency
invoke QueryPerformanceCounter, addr TimeStart

; Constant buffer creation (for the WVP matrices)
mov ebx, offset constDesc
cd equ [ebx.D3D11_BUFFER_DESC]
mov cd.BindFlags, D3D11_BIND_CONSTANT_BUFFER
mov cd.ByteWidth, 192
mov cd.Usage, D3D11_USAGE_DEFAULT
coinvoke d3dDevice, ID3D11Device, CreateBuffer, addr cd, 0, addr d3dWvpCB
invoke SystemError, TEXT_("Failed to create constant buffer.")

; Show window once initialisation has succeeded
invoke ShowWindow, hWnd, 1

; Main loop
.while 1
; Windows message pump
invoke PeekMessage, ADDR msg, NULL, 0, 0, PM_REMOVE
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.if msg.message == WM_QUIT
.break
.endif

; Update the frame rate counter
invoke TimerFPS

; Set render target as active
coinvoke d3dContext, ID3D11DeviceContext, OMSetRenderTargets, 1, addr d3dBackBufferRTV, 0

; Clear back buffer
coinvoke d3dContext, ID3D11DeviceContext, ClearRenderTargetView, d3dBackBufferRTV,addr BackgroundColor

; Set shaders
coinvoke d3dContext, ID3D11DeviceContext, VSSetShader, d3dVertexShader, 0, 0
coinvoke d3dContext, ID3D11DeviceContext, PSSetShader, d3dPixelShader, 0, 0

; Draw the quad
coinvoke d3dContext, ID3D11DeviceContext, IASetInputLayout, d3dInputLayout
coinvoke d3dContext, ID3D11DeviceContext, IASetVertexBuffers, 0, 1, addr d3dVertexBuffer, addr dataStride, addr dataOffset
coinvoke d3dContext, ID3D11DeviceContext, IASetPrimitiveTopology, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
coinvoke d3dContext, ID3D11DeviceContext, Draw, 6, 0

; Present
coinvoke d3dSwapchain, IDXGISwapChain, Present, 0, 0
.endw

call SystemExitApplication

WinMain endp
end WinMain

Lot's of error handling. So if something breaks, I should know where to look for the cause (generally a result of the end system not being compatible with some call I have made). In an ideal world, the end user won't have any problems.

I'd spoil it and send more screenshot of what my game looked like in C++ back when I was working on it, but it would be cooler knowing the screenshots are coming from my ASM version. So I'll have to hold out on you for the moment on that front.  :biggrin:

Ascended

  • Member
  • ***
  • Posts: 331
Re: Lonewolff's ASM game creation thread
« Reply #23 on: April 15, 2018, 07:34:19 PM »
It's weird...

I am fleshing out my matrix calculations in C++ and comparing against DirectXMath to make sure my results are correct and my un-optimised code is running rings around Microsoft's implementation  :icon_eek:

I'm up to 436% faster already.  :dazzled:


Siekmanski

  • Member
  • *****
  • Posts: 1600
Re: Lonewolff's ASM game creation thread
« Reply #24 on: April 15, 2018, 09:41:33 PM »
It's weird...

I am fleshing out my matrix calculations in C++ and comparing against DirectXMath to make sure my results are correct and my un-optimised code is running rings around Microsoft's implementation  :icon_eek:

I'm up to 436% faster already.  :dazzled:

Have you fasten your seat belts?  :bgrin:

"mov ebx, offset constDesc"
About EBX you need to preserve that one, also counts for ESI and EDI.
Creative coders use backward thinking techniques as their strategy.

Ascended

  • Member
  • ***
  • Posts: 331
Re: Lonewolff's ASM game creation thread
« Reply #25 on: April 16, 2018, 07:41:10 AM »
Thanks man!

How do you preserve it? Noob here.  :bgrin:

jj2007

  • Member
  • *****
  • Posts: 8608
  • Assembler is fun ;-)
    • MasmBasic
Re: Lonewolff's ASM game creation thread
« Reply #26 on: April 16, 2018, 08:03:45 AM »
push ebx  ; preserved
mov ebx, 123
pop ebx   ; restored

Ascended

  • Member
  • ***
  • Posts: 331
Re: Lonewolff's ASM game creation thread
« Reply #27 on: April 16, 2018, 08:06:20 AM »
Ah, ok. Thanks JJ  :icon_cool:

Ascended

  • Member
  • ***
  • Posts: 331
Re: Lonewolff's ASM game creation thread
« Reply #28 on: April 16, 2018, 02:16:14 PM »
Almost have enough of my matrix library made to make something usable.

Fleshed it out in C++. And I'm already beating Microsoft's implementation by a mile.



The top results are MS's and the bottom are my own implementation.

Will translate this over to ASM shortly and see if I can then set up a 3D camera for this project.  8)
« Last Edit: April 16, 2018, 04:10:35 PM by Lonewolff »

Ascended

  • Member
  • ***
  • Posts: 331
Re: Lonewolff's ASM game creation thread
« Reply #29 on: April 20, 2018, 12:25:48 PM »
Almost finished writing part one of my matrix library (yet another thing I had to learn from scratch - LOL  :bgrin:)

The results are pretty good.



Beating Microsoft's matrix library by a huge amount and am just behind my own C++ implementation.

This is a great result as I can see plenty of places I can improve my ASM code. At this point I am just making the calculations work out correctly - which they are.  :t

MatrixTranspose and MatrixMultiply to finish off next and then I should be good to set up a 3D camera.