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

Post Reply
JHjavaDev
Posts: 3
Joined: Mon Aug 21, 2017 11:31 am

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

Post by JHjavaDev » Sat Sep 23, 2017 12:46 am

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?

WinterMute
Site Admin
Posts: 1845
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

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

Post by WinterMute » Sun Sep 24, 2017 6:54 pm

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));
Help keep devkitPro toolchains free, Donate today

Personal Blog

JHjavaDev
Posts: 3
Joined: Mon Aug 21, 2017 11:31 am

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

Post by JHjavaDev » Mon Sep 25, 2017 11:24 am

I tried it and now it works perfectly.
Thank you very much!

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests