Advanced programming for 3D Graphics Applications Console developement.

29
Advanced programming Advanced programming for 3D Graphics for 3D Graphics Applications Applications Console developement Console developement

Transcript of Advanced programming for 3D Graphics Applications Console developement.

Page 1: Advanced programming for 3D Graphics Applications Console developement.

Advanced programming Advanced programming for 3D Graphics for 3D Graphics

ApplicationsApplications

Console developementConsole developement

Page 2: Advanced programming for 3D Graphics Applications Console developement.

Components of a Video Components of a Video GameGame• 3D graphics3D graphics

• User interactionUser interaction

• Sound effects and musicSound effects and music

• 3D models 3D models

• 2D textures 2D textures

• AnimationAnimation

• Game and level designGame and level design

• Immersion, excitement, alternate realityImmersion, excitement, alternate reality

Page 3: Advanced programming for 3D Graphics Applications Console developement.

PlayStation Net Yaroze (1997)PlayStation Net Yaroze (1997)(Official “hobbyist” Game Development)(Official “hobbyist” Game Development)

• Host-target Host-target DevelopmentDevelopment

• Net Yaroze games Net Yaroze games dev librariesdev libraries

• No access to No access to hardwarehardware

• Sub-optimal Sub-optimal PerformancePerformance

Page 4: Advanced programming for 3D Graphics Applications Console developement.

PlayStation2 Games ConsolePlayStation2 Games Console

European Launch: November 2000European Launch: November 2000

Page 5: Advanced programming for 3D Graphics Applications Console developement.
Page 6: Advanced programming for 3D Graphics Applications Console developement.

Professional Development Professional Development EnvironmentEnvironmentThe TOOLThe TOOL

• Use the Linux-based tools Use the Linux-based tools that come with the TOOLthat come with the TOOL

LANLAN

PCPC

TVTV

ControllersControllers

• Use third party dev Use third party dev tools such as tools such as CodeWarrior or SN CodeWarrior or SN systemssystems

LinuxBox

LinuxBox

Page 7: Advanced programming for 3D Graphics Applications Console developement.

• USB keyboard & mouseUSB keyboard & mouse

• 10/100 Ethernet Adapter10/100 Ethernet Adapter

• 40GB Hard Disk40GB Hard Disk

• DVDsDVDs– Linux operating systemLinux operating system– Hardware ManualsHardware Manuals– Development ToolsDevelopment Tools– Example ApplicationsExample Applications

PlayStation2 Linux Kit – May PlayStation2 Linux Kit – May 20022002

Page 8: Advanced programming for 3D Graphics Applications Console developement.

Graphics Transformation Graphics Transformation PipelinePipeline

• Transforms vertices from model or local Transforms vertices from model or local space to 2D screen space for rasterisationspace to 2D screen space for rasterisation

Page 9: Advanced programming for 3D Graphics Applications Console developement.

PS2 Graphics ArchitecturePS2 Graphics Architecture

EE CoreVU0(4k)

VU1(16k)

I$16k

D$8k

SP16k VIF0 VIF1

128-bit Data Bus

GIF GS

Path 1

Path 3

Path 2

DMACMain

Memory

FPU

Timer

32 128

64

Vsync/Hsync

2.4Gb/sec

Page 10: Advanced programming for 3D Graphics Applications Console developement.

PS2 Specific PipelinePS2 Specific Pipeline• Transformation Matrices built by CPUTransformation Matrices built by CPU• Matrices and untransformed vertex data sent to VU1Matrices and untransformed vertex data sent to VU1• VU1 performs vertex transformation, clipping, VU1 performs vertex transformation, clipping,

lighting, view port scaling.lighting, view port scaling.• Transformed data sent to GS.Transformed data sent to GS.• GS performs texturing and rasterisation.GS performs texturing and rasterisation.• All above (3 processes) can run in parallel !!All above (3 processes) can run in parallel !!

EE CoreVU0(4k)

VU1(16k)

I$16k

D$8k

SP16k VIF0 VIF1

128-bit Data Bus

GIF GS

Path 1

Path 3

Path 2

DMACMain

Memory

FPU

Timer

32 128

64

Vsync/Hsync

2.4Gb/sec

Page 11: Advanced programming for 3D Graphics Applications Console developement.

Organisation of MemoryOrganisation of Memory• Dynamic buffer contains data Dynamic buffer contains data

that changes from frame to that changes from frame to frame, e.g. transformed data, frame, e.g. transformed data, transformation matrices.transformation matrices.

• Two dynamic buffers needed Two dynamic buffers needed to exploit parallelism of PS2to exploit parallelism of PS2

• One buffer is being compiled One buffer is being compiled by the CPU whilst the other is by the CPU whilst the other is being sent for rendering.being sent for rendering.

• Utilises Parallelism of PS2Utilises Parallelism of PS2

Static MemoryBuffer

DynamicMemory Buffer

(0)

DynamicMemory Buffer

(1)

Tot

al A

lloca

ted

Mem

ory

Written by CPU

Read by DMAC

Swap Every Frame

Page 12: Advanced programming for 3D Graphics Applications Console developement.

The Game LoopThe Game Loop

while(Game_Running)while(Game_Running){{Fire();Fire(); // Start data transfer// Start data transferGetUserInput();GetUserInput(); ////DoGameLogic();DoGameLogic(); // AI, Physics, Logic….// AI, Physics, Logic….

// Following code ONLY puts render data into memory// Following code ONLY puts render data into memory

BeginScene();BeginScene(); // Clear frame buffer// Clear frame bufferSetStaticData();SetStaticData(); // textures, 3d models etc// textures, 3d models etcSetDynamicData();SetDynamicData(); // Matrices, T&L, etc.// Matrices, T&L, etc.EndScene();EndScene(); // Wait for previous frame to // Wait for previous frame to renderrender}}

Page 13: Advanced programming for 3D Graphics Applications Console developement.

VU OverviewVU Overview

Page 14: Advanced programming for 3D Graphics Applications Console developement.

Architecture of VU1Architecture of VU1

• 16k data memory, address in qwords (128-bit)16k data memory, address in qwords (128-bit)

• 16k program memory, address in dwords (64-16k program memory, address in dwords (64-bit)bit)

• 32 x 128-bit floating point registers32 x 128-bit floating point registers

• 16 x 16-bit integer registers (newbie killer!)16 x 16-bit integer registers (newbie killer!)

• Two execution units (upper and lower)Two execution units (upper and lower)

• Special registers (ACC, I, Q, R, P)Special registers (ACC, I, Q, R, P)

• Dual stream assembly language (.vsm file)Dual stream assembly language (.vsm file)

• VU assembler provided by Sony (VU assembler provided by Sony (ee-dvp-as)ee-dvp-as)– Latency, scheduling, pairing, issues.Latency, scheduling, pairing, issues.

Page 15: Advanced programming for 3D Graphics Applications Console developement.

Typical vsm assembly Typical vsm assembly (dual stream)(dual stream)

NOP lq VF06,7(VI02) NOP lq VF06,7(VI02) mulax ACC,VF02,VF06x iaddiu VI01,VI01,0x00000001 mulax ACC,VF02,VF06x iaddiu VI01,VI01,0x00000001 madday ACC,VF03,VF06y iaddiu VI02,VI02,0x00000002 madday ACC,VF03,VF06y iaddiu VI02,VI02,0x00000002 maddaz ACC,VF04,VF06z NOP maddaz ACC,VF04,VF06z NOP maddw VF06,VF05,VF06w NOP maddw VF06,VF05,VF06w NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP mulaw.xyz ACC,VF01,VF00w div Q,VF00w,VF06w mulaw.xyz ACC,VF01,VF00w div Q,VF00w,VF06w NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP mulq.xyz VF06,VF06,Q waitq mulq.xyz VF06,VF06,Q waitq NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP

Page 16: Advanced programming for 3D Graphics Applications Console developement.

Typical VCLTypical VCL(Single Stream)(Single Stream)

loop:loop:lqlq Vert, StartVert(iVertPtr)Vert, StartVert(iVertPtr)

MatrixMultiplyVertex MatrixMultiplyVertex Vert, fTransform, VertVert, fTransform, Vert div div q, vf00[w], Vert[w]q, vf00[w], Vert[w] mul.xyz mul.xyz Vert, Vert, qVert, Vert, q mula.xyzmula.xyz acc, fScales, vf00[w]acc, fScales, vf00[w] madd.xyzmadd.xyz Vert, Vert, fScalesVert, Vert, fScales

ftoi4.xyzftoi4.xyz Vert, VertVert, Vert

Page 17: Advanced programming for 3D Graphics Applications Console developement.
Page 18: Advanced programming for 3D Graphics Applications Console developement.

Why is the PS2 used?Why is the PS2 used?• Introduce console development topicsIntroduce console development topics• 2D graphics, frame buffers, graphics 2D graphics, frame buffers, graphics

packets, graphics processors, memory packets, graphics processors, memory management, console architecture….management, console architecture….

• 3D graphics, 3D console architecture, 3D graphics, 3D console architecture, Vector Units, Parallel processing, vertex Vector Units, Parallel processing, vertex transformation, clipping, lighting.transformation, clipping, lighting.

• C++ concepts in a games context, Sprite C++ concepts in a games context, Sprite classes etc., structure of a games classes etc., structure of a games program, Low level vertex processing.program, Low level vertex processing.

• Creating a 3D game engineCreating a 3D game engine

Page 19: Advanced programming for 3D Graphics Applications Console developement.

Development ConfigurationDevelopment Configuration(Several Options)(Several Options)

University Ethernet Network

Windows PC Television

LCD MonitorKeyboard

Mouse

ConnectionBox

Control Pads

PlayStation2

• Host/TargetHost/Target• NativeNative

Page 20: Advanced programming for 3D Graphics Applications Console developement.
Page 21: Advanced programming for 3D Graphics Applications Console developement.

Development ToolsDevelopment Tools

• GNU gcc and g++ compilersGNU gcc and g++ compilers• GNU gdb debugger!GNU gdb debugger!• Vector Command Line Pre-processorVector Command Line Pre-processor• Vector Unit assemblerVector Unit assembler• Visual Vector Unit DebuggerVisual Vector Unit Debugger

• Development can be done “offline” Development can be done “offline” with Visual Studio”with Visual Studio”

Page 22: Advanced programming for 3D Graphics Applications Console developement.

Development EnvironmentDevelopment Environment

Page 23: Advanced programming for 3D Graphics Applications Console developement.

SPS2: Direct Access Environment

•Developed by PS2Linux developer community

•1.What is it?

•2.Why use it?

•3.How do I use it?

•4.Are there disadvantages?

Page 24: Advanced programming for 3D Graphics Applications Console developement.

What is SPS2?

••Kernel module loaded at runtime

••Gives direct access to the hardware

••Has been used to create samples requiring lots of processing power

••Linux friendly

Page 25: Advanced programming for 3D Graphics Applications Console developement.

AdvantagesAdvantages

• Required for DMA transfers• –Guarantee to have unswappable/unmovable

memory• •Only 4kb continuous memory is guarantied• –Physical address of memory• •You fill the buffers using Linux virtual addresses

and sends the data using physical addresses• –Direct access to the hardware registers• •EE• •GS

Page 26: Advanced programming for 3D Graphics Applications Console developement.

• •DMA packet checker• –Set of functions for debugging purposes• –Helps prevent crashes• •Easy to crash the system• •Very good documentation• •Samples to illustrate usage• •Currently being developed and improved• •The module can be installed/uninstalled at

runtime• –No need to recompile the kernel• –No memory is reserved• –No need to even reboot

Page 27: Advanced programming for 3D Graphics Applications Console developement.

How to use SPS2How to use SPS2

• •Load the kernel at runtime• –Scripts are provided to make it easy• •Use the library provided• –Just a set of headers to include• –System calls are taken care of• •Build DMA packets the same way you’d do on a

DevKit• –Use memory allocated by the module• –Build small 4kb chunks linked in a chain• •Use macros to set the DMA registers• –Macros are assembly code writing directly to the

registers

Page 28: Advanced programming for 3D Graphics Applications Console developement.

SPS2 project framework

• •Written by members of the community• –Professional developers• •Takes cares of display initialisation• •Deals with DMA packet building• •Provides a solid base for your code• •Samples of advanced techniques used in a game• –Mskpath3• –Bump mapping• –Interlock

Page 29: Advanced programming for 3D Graphics Applications Console developement.

EvaluationEvaluation

• Games Employers Value Console SkillsGames Employers Value Console Skills

• Steep learning curve for studentsSteep learning curve for students

• In-house development framework neededIn-house development framework needed

• Similarities to Pro-developmentSimilarities to Pro-development

• Motivational for studentsMotivational for students

• Introduces Linux & Linux development tool Introduces Linux & Linux development tool chainchain