Page 1 of 1

GX indirect data shows only in Dolphin but not on the Wii

Posted: Sat Sep 23, 2017 12:46 am
by JHjavaDev
I want to load a model from a custom file format into something that I can pass to GX. I have confirmed this code to be working, however nothing is displayed on the Wii when I give the loaded data to GX. I think I have narrowed down the problem to the fact that I am dynamically allocating the arrays with the data. I put together a test to confirm this.

Not dynamic:

Code: Select all

...
f32 verts[]	ATTRIBUTE_ALIGN(32)	= {
	-1.0F, 0.0F, -1.5F,
	1.0F, -0.0F, -1.0F,
	-1.0F, -0.6F, 0.0F
};

u8 colors[]	ATTRIBUTE_ALIGN(32)	= {
	0, 255, 255, 255
};

GX_SetArray(GX_VA_POS, verts, 3 * sizeof(f32));
GX_SetArray(GX_VA_CLR0, colors, 4 * sizeof(u8));
...
Dynamic:

Code: Select all

...
u8 *vertsp = (f32*)(memalign(32, 9 * sizeof(f32)));
u8 *colorsp = (u8*)(memalign(32, 4 * sizeof(u8)));

for(int i = 0; i < 9; i++) {
	vertsp[i] = verts[i];
}
for(int i = 0; i < 4; i++) {
	colorsp[i] = colors[i];
}

GX_SetArray(GX_VA_POS, vertsp, 3 * sizeof(f32));
GX_SetArray(GX_VA_CLR0, colorsp, 4 * sizeof(u8));
...
The first code works but second one doesn't.
I am guessing this has something to do with the way the Wii handles dynamic memory compared to Dolphin.
How would I make this work on the Wii?

Re: GX indirect data shows only in Dolphin but not on the Wi

Posted: Sun Sep 24, 2017 6:54 pm
by WinterMute
It's cache related - you need to use DCFlushRange to ensure the data is written to memory before GPU can see it. With the non dynamic arrays this is done by loading the dol in the first place.

Code: Select all

u8 *vertsp = (f32*)(memalign(32, 9 * sizeof(f32)));
u8 *colorsp = (u8*)(memalign(32, 4 * sizeof(u8)));

for(int i = 0; i < 9; i++) {
   vertsp[i] = verts[i];
}
for(int i = 0; i < 4; i++) {
   colorsp[i] = colors[i];
}

DCFlushRange(vertsp, 9 * sizeof(f32));
DCFlushRange(colorsp, 4 * sizeof(u8));

GX_SetArray(GX_VA_POS, vertsp, 3 * sizeof(f32));
GX_SetArray(GX_VA_CLR0, colorsp, 4 * sizeof(u8));

Re: GX indirect data shows only in Dolphin but not on the Wi

Posted: Mon Sep 25, 2017 11:24 am
by JHjavaDev
I tried it and now it works perfectly.
Thank you very much!