Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy Xbox port #1

Open
wants to merge 93 commits into
base: master
Choose a base branch
from
Open

Dummy Xbox port #1

wants to merge 93 commits into from

Conversation

JayFoxRox
Copy link
Owner

@JayFoxRox JayFoxRox commented Sep 4, 2019

Build using:

git clone https://github.com/JayFoxRox/neverball.git neverball
cd neverball
git checkout origin/xbox
git clone --depth=1 https://github.com/xiph/vorbis                 xbox/nxdk-vorbis
git clone --depth=1 https://github.com/xiph/ogg                    xbox/nxdk-ogg

#FIXME: As your nxdk, use https://github.com/dracc/nxdk/pull/4
#FIXME: In your nxdk, check out https://github.com/JayFoxRox/nxdk-sdl/pull/1 as SDL2 submodule
#FIXME: In your nxdk, check out https://github.com/XboxDev/nxdk-pdclib/commit/8c8a3bf157bdef2bf8d09ef724cd8a36273adf40 (or newer) as pdclib submodule
#FIXME: Fix files here, as described in xbox/Makefile-*.xbox files

make #FIXME: Maybe not necessary - compiles PC version / compiles data?
make -f Makefile.nxdk # Build Xbox version

Missing ports (in xbox.c unless noted otherwise):

  • libjpeg (should exist already) (Ported, untested)
  • libpng (should exist already) (Ported, untested)
  • nxdk-sdl
    • Joystick API (should exist already; review #include and linker?) (Fixed by nxdk-sdl PR.. why?!)
      • SDL_JoystickClose
      • SDL_JoystickEventState
      • SDL_JoystickInstanceID
      • SDL_JoystickOpen
    • Audio API (dummy driver needs to be linked; see issue on nxdk-sdl) (Fixed by nxdk-sdl PR)
      • SDL_LockAudio
      • SDL_OpenAudio
      • SDL_PauseAudio
      • SDL_UnlockAudio
      • SDL_CloseAudio
  • dirent.h (consider https://github.com/tronkko/dirent [only supports wide-string] or port share/dir.c) (Ported share/dir.c, but missing GetFileAttributes in nxdk winapi)
  • direct.h (_mkdir only; part of Windows CRT see https://stackoverflow.com/questions/49747236/create-a-directory-in-c-for-kernel-driver for impl.)
  • sys/time.h (gettimeofday only) (only for mapc)
  • sys/stat.h (access and stat only; alternatively port share/common.c)
  • math.h (floor only; already a PR on nxdk-pdclib) (use nxdk-pdclib ahead of master)
  • ogg (Ported, untested)
  • vorbis (Ported, untested)
  • OpenGL ES 1.x (Waiting for "xgu" progress)
  • pick_home_path must be fixed in share/base_config.c (Current hack is fine)
  • Set CONFIG_USER, CONFIG_DATA and CONFIG_LOCALE in Makefile.nxdk (Uses safe defaults)
  • argv[0] in main function must be path to executable (see upstream issue 195) (Workaround present, waiting for upstream issue)
  • SDL2 needs ability to create a window with fake GL context (Workaround: GL init disabled in share/video.c)

mapc did also compile. Compilation of Neverputt was not tested.


Compare against development machine using:

reset && make neverball DEBUG=1 ENABLE_OPENGLES=1 && gdb --args ./neverball 

@JayFoxRox JayFoxRox force-pushed the xbox branch 3 times, most recently from 65e722d to afb6020 Compare September 6, 2019 02:52
xbox/alloca.h Outdated
@@ -0,0 +1 @@
#define alloca(size) __builtin_alloca (size)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be upstreamed.

@JayFoxRox JayFoxRox force-pushed the xbox branch 2 times, most recently from 48f8816 to c315cfc Compare September 6, 2019 19:59
@JayFoxRox JayFoxRox mentioned this pull request Sep 7, 2019
@JayFoxRox JayFoxRox force-pushed the xbox branch 4 times, most recently from cc6a30e to 7190173 Compare September 8, 2019 05:08
xbox/matrix.h Outdated
memcpy(r, m, sizeof(m));
}

void _math_matrix_rotate( GLfloat *m, GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review this - I took out some optimization to keep the code short. I also moved the initialization into the caller as done for other functions already (WHY?!).

@JayFoxRox
Copy link
Owner Author

GL TODO List for XGU

Getters

  • glGetIntegerv (GL state machine)
  • glGetString (GL state machine)

Clearing

  • glClear (Present in pbkit, should be isolated for xgu and deprecated in pbkit)
  • glClearColor (Present in pbkit, should be isolated for xgu and deprecated in pbkit)

Buffers

  • glGenBuffers (GL state machine, allocator part of Xbox kernel Mm)
  • glBindBuffer (GL state machine, allocator part of Xbox kernel Mm)
  • glBufferData (GL state machine, allocator part of Xbox kernel Mm)
  • glBufferSubData (GL state machine, allocator part of Xbox kernel Mm)
  • glDeleteBuffers (GL state machine, allocator part of Xbox kernel Mm)

Vertex buffers

  • glTexCoordPointer (Present in example codes probably, also in JFR GL code I think)
  • glColorPointer (Present in example codes probably, also in JFR GL code I think)
  • glNormalPointer (Present in example codes probably, also in JFR GL code I think)
  • glVertexPointer (Present in example codes probably, also in JFR GL code I think)

Also see https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php note about nvidia in "Custom Vertex Attributes" - I'm not sure if Xbox GPU exposes 2 interfaces (1. named vertex attributes, 2. nvidia indices for names), but they should be doing mostly the same, the index based interface would probably be fine for now

These functions also set various GPU registers, so each of them will have various commands for setting different things: setting address, setting type, setting count, ... - the proper NV function to be handled are NV097_SET_VERTEX_DATA_ARRAY_*

Draw calls

  • glDrawArrays (Part of example code, needs to be isolated)
  • glDrawElements (Not supported by hardware, needs unrolling of indices, instead implement xgu_elements16(uint16_t* indices, unsigned int count) and xgu_elements32(uint32_t* indices, unsigned int count) methods)

These will also require xgu_set_begin_end, however, it's could be a good idea to also expose that as 2 separate commands: xgu_begin and xgu_end (which can internally forward to xgu_set_begin_end; or we avoid xgu_set_begin_end) as resulting code will be much cleaner (in caller [game / high level API] and callee [xgu]). Also note for noobs: whereas pb_begin/end surround pushing GPU commands, xgu_begin/end will surround pushing vertex data / draw calls - so these 2 are very different.

Matrix functions

  • glMatrixMode (Registers named explicitly, needs xgu function for each supported matrix mode)
  • glLoadIdentity (Not part of GPU = not xgu, just math)
  • glMultMatrixf (Not part of GPU = not xgu, just math)
  • glOrthof (Not part of GPU = not xgu, just math)
  • glTranslatef (Not part of GPU = not xgu, just math)
  • glRotatef (Not part of GPU = not xgu, just math)
  • glScalef (Not part of GPU = not xgu, just math)
  • glPopMatrix (Not part of GPU = not xgu, just math)
  • glPushMatrix (Not part of GPU = not xgu, just math)
  • glViewport (Present in pbkit itself for surface clip size, also overlaps with viewport matrix stuff)

GL_TEXTURE is for the active texture slot, so we need to be able to submit the data for a specified int slot where slot is somewhere between 0 and 3 (GPU has 4 slots). Additionally, there's derived matrices which need to be submitted. So basically just look for GPU registers which have "MATRIX" in their name, and assume that we'll eventually need to support them.

Textures

  • glGenTextures (GL state machine = not xgu, allocator part of Xbox kernel Mm)
  • glBindTexture (GL state machine = not xgu)
  • glActiveTexture (GL state machine = not xgu, GPU regs addressed directly for TEXTURE0-3)
  • glClientActiveTexture (GL state machine = not xgu)
  • glDeleteTextures (GL state machine = not xgu, allocator part of Xbox kernel Mm)
  • glTexImage2D (Used in examples: various registers for setting texture address and format)
  • glTexParameteri (Used in examples: various registers for setting texture clamping etc. - possible overlap with format functions)

TexEnv

  • glTexEnvi (GL state machine = no xgu, but needs a lot of xgu for underlying hardware, see note)

This controls register combiners; so we specifically need all of NV097_SET_COMBINER_*

Renderstates

  • glAlphaFunc (Needs xgu API)
  • glBlendFunc (Needs xgu API)
  • glClipPlanef (Needs xgu API for everything NV097_SET_TEXGEN_*)
  • glColor4f (Needs xgu, Probably part of old JFR gl.h code)
  • glColor4ub (Needs xgu, Probably part of old JFR gl.h code)
  • glColorMask (Needs xgu API)
  • glCullFace (Needs xgu API)
  • glDepthFunc (Needs xgu API)
  • glDepthMask (Needs xgu API)
  • glDisable (Various xgu functions for each allowed parameter)
  • glDisableClientState (Unsure, probably mostly GL state machine only = maybe no xgu)
  • glEnable (Various xgu functions for each allowed parameter)
  • glEnableClientState (Unsure, probably mostly GL state machine only = maybe no xgu)
  • glFrontFace (Needs xgu API)

Compare Neverball gl.h with possible values for glDisable and glEnable; Remember that the xgu API is GPU focused, so it's not xgu_enable(int flag=alpha_test), but xgu_alpha_test(bool alpha_test_enable=true). If different flags are in one GPU register, then it would be xgu_render_state(bool alpha_test_enable=true, bool blend_enable=false) etc. - point being: For each possible value that can be passed to glEnable/glDisable, there'll be a new xgu function, although some might have to be grouped because they affect the same GPU register.

  • glEnable / glDisable list
    • GL_ALPHA_TEST
    • GL_BLEND
    • GL_CLIP_PLANE0 / GL_CLIP_PLANE1 / GL_CLIP_PLANE2
    • GL_COLOR_MATERIAL
    • GL_CULL_FACE
    • GL_DEPTH_TEST
    • GL_LIGHT0 / GL_LIGHT1 / GL_LIGHT2
    • GL_LIGHTING
    • GL_MULTISAMPLE
    • GL_NORMALIZE
    • GL_POINT_SPRITE
    • GL_POLYGON_OFFSET_FILL
    • GL_STENCIL_TEST
    • GL_TEXTURE_2D
    • GL_TEXTURE_GEN_S / GL_TEXTURE_GEN_T

Stencil actions

  • glStencilFunc (Needs xgu API)
  • glStencilOp (Needs xgu API)

Note: Probably broken in pbkit, but xgu API can still be made

Misc.

  • glPointParameterf (Needs xgu API, low priority)
  • glPointParameterfv (Needs xgu API, low priority)
  • glPointSize (Needs xgu API)
  • glPolygonOffset (Needs xgu API, low priority)

Pixel readback

  • glReadPixels (Raw memory access = not xgu, swizzling / unswizzling API should be added as part of pbkit, xgu or separate lib)

Lighting

  • glLightfv (Needs xgu API)
  • glLightModelf (Needs xgu API)
  • glLightModelfv (Needs xgu API)

Materials

  • glMaterialfv (Needs xgu API, low priority; NV_097_SET_COLOR_MATERIAL_* probably not supported in nv2a_regs.h yet)

Pixel pushing

  • glPixelStorei (GL state machine only)

Misc XGU stuff

We'll also want NV097_WAIT_FOR_IDLE and NV097_NO_OPERATION

xbox/xbox.c Outdated
| MASK(NV097_SET_COMBINER_COLOR_OCW_MUX_ENABLE, 0)
| MASK(NV097_SET_COMBINER_COLOR_OCW_AB_DOT_ENABLE, 0)
| MASK(NV097_SET_COMBINER_COLOR_OCW_CD_DOT_ENABLE, 0)
| MASK(NV097_SET_COMBINER_COLOR_OCW_OP, NV097_SET_COMBINER_COLOR_OCW_OP_NOSHIFT));
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME about RGB_SCALE and ALPHA_SCALE

| MASK(NV097_SET_COMBINER_ALPHA_ICW_B_SOURCE, x_b) | MASK(NV097_SET_COMBINER_ALPHA_ICW_B_ALPHA, x_b_alpha) | MASK(NV097_SET_COMBINER_ALPHA_ICW_B_MAP, x_b_map)
| MASK(NV097_SET_COMBINER_ALPHA_ICW_C_SOURCE, x_c) | MASK(NV097_SET_COMBINER_ALPHA_ICW_C_ALPHA, x_c_alpha) | MASK(NV097_SET_COMBINER_ALPHA_ICW_C_MAP, x_c_map)
| MASK(NV097_SET_COMBINER_ALPHA_ICW_D_SOURCE, x_d) | MASK(NV097_SET_COMBINER_ALPHA_ICW_D_ALPHA, x_d_alpha) | MASK(NV097_SET_COMBINER_ALPHA_ICW_D_MAP, x_d_map));
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire if / else garbage should probably be part of XGUX with underlying crap in XGU
CC @dracc

xbox/xbox.c Outdated
if (mask & GL_STENCIL_BUFFER_BIT) { flags |= XGU_CLEAR_STENCIL; }

uint32_t* p = pb_begin();
//FIXME: Set clear region
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder as this might crash

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No crash, but doesn't seem to work yet either. Did not try setting region yet - currently falling back to pb_fill()

xbox/xbox.c Outdated
}

GL_API void GL_APIENTRY glDepthMask (GLboolean flag) {
//FIXME: Missing from XGU
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for this CC @dracc

xbox/xbox.c Outdated
}

GL_API void GL_APIENTRY glDepthFunc (GLenum func) {
//FIXME: Missing from XGU
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for this CC @dracc

xbox/xbox.c Outdated

// Stencil actions
GL_API void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask) {
//FIXME: Missing from XGU
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for this CC @dracc

xbox/xbox.c Outdated
}

GL_API void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units) {
//FIXME: Missing from XGU
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really important (and potentially tricky); but still waiting for this CC @dracc

@JayFoxRox
Copy link
Owner Author

Normalization of light direction vectors / position seems to be incorrect: https://discord.com/channels/428359196719972353/428399682239332354/713814011182841859

(an issue for XQEMU must be created)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant