Homebrew Ctrulib Question

cal64

Well-Known Member
OP
Newcomer
Joined
Oct 31, 2016
Messages
65
Trophies
0
Age
30
XP
436
Country
France
Hi! I've been studying the portal3DS source code for a while now, and there's something I can't quite understand:
In the source code are functions like GPU_DrawArrays() of which I can't find the declaration in the ctrulib source code, however they're listed in the libctru.cfg file (in the ctrulib repository).
Can anyone tell me what I'm not getting here/how these functions work?
Thanks in advance!
 

mashers

Stubborn ape
Member
Joined
Jun 10, 2015
Messages
3,837
Trophies
0
Age
40
Location
Kongo Jungle
XP
5,074
Country
If they're not defined in the ctrulib headers, they're probably functions provided by *hax. If you get warnings when building your homebrew, you could add a definition of the function and as long as it's compatible with the implementation (wherever it is) it should be fine.
 

cal64

Well-Known Member
OP
Newcomer
Joined
Oct 31, 2016
Messages
65
Trophies
0
Age
30
XP
436
Country
France
If they're not defined in the ctrulib headers, they're probably functions provided by *hax. If you get warnings when building your homebrew, you could add a definition of the function and as long as it's compatible with the implementation (wherever it is) it should be fine.
So, where can I find these functions? By *hax I get "whatever hax you're using", but in this case, where can I find them in the *hax source code?
(Sorry if I don't fully understand and this sounds silly, but might as well make sure :) ).
Also, before the section corresponding to the GPU_DrawElements() function I gave as an example in libctru.cfg is the line <!-- gpu/gpu.c -->, leading to a file that I could only find in the ctrulib repository.
Thanks for replying!
 
Last edited by cal64,

mashers

Stubborn ape
Member
Joined
Jun 10, 2015
Messages
3,837
Trophies
0
Age
40
Location
Kongo Jungle
XP
5,074
Country
So, where can I find these functions? By *hax I get "whatever hax you're using",
I'm assuming they're provided by the hax payload which is loaded using the entrypoint. The entrypoint probably doesn't matter - it's what's provided by the payload which is, I suspect, providing those functions and services.

but in this case, where can I find them in the *hax source code?
I'm not sure actually. The ninjhax repo on GitHub seems really out of date as there have definitely been updates to the payloads since then. I'll see if I can locate the source code for the newer hax payloads.

Also, before the section corresponding to the GPU_DrawElements() function I gave as an example in libctru.cfg is the line <!-- gpu/gpu.c -->, leading to a file that I could only find in the ctrulib repository.
Are you sure it's written like that? That is HTML comment markup. I would be surprised if it worked in a c file.

--------------------- MERGED ---------------------------

Oh I was looking at the wrong repo. This is the repo for the current hax payloads:

https://github.com/smealum/ninjhax2.x

However, I can't find any reference to that function in there either. Does the function definitely work? I'm wondering if it's actually deprecated which is why you can no longer find it in the headers.
 

cal64

Well-Known Member
OP
Newcomer
Joined
Oct 31, 2016
Messages
65
Trophies
0
Age
30
XP
436
Country
France
Are you sure it's written like that? That is HTML comment markup. I would be surprised if it worked in a c file.
Yes, however it's from a .cfg file, and not a .c file.
Thank you so much for all your help!
(I didn't try to compile the game, so I can't tell if the function actually works, figuring this whole thing out was mainly for Learning purposes. I can try to compile it if you want :) ).
 
Last edited by cal64,

mashers

Stubborn ape
Member
Joined
Jun 10, 2015
Messages
3,837
Trophies
0
Age
40
Location
Kongo Jungle
XP
5,074
Country
Yes, however it's from a .cfg file, and not a .c file.
Ahh, sorry, it's XML. That is definitely a comment. Looking at the file now, it would seem that the <function name=""> tags actually define functions which are probably then defined at build time. The implementation for these functions can be found in gpu-old.c (I didn't see it before). Why the functions aren't simply defined in a header I can't tell.

(I didn't try to compile the game, so I can't tell if the function actually works, figuring this whole thing out was mainly for Learning purposes. I can try to compile it if you want :) ).
I think it will be fine. If you look at the implementation of these functions, I don't think there's anything you need to use in usermode programming. For example:

Code:
void GPU_DrawElements(GPU_Primitive_t primitive, u32* indexArray, u32 n)
{
    //set primitive type
    GPUCMD_AddMaskedWrite(GPUREG_PRIMITIVE_CONFIG, 0x2, primitive);
    GPUCMD_AddMaskedWrite(GPUREG_RESTART_PRIMITIVE, 0x2, 0x00000001);
    //index buffer (TODO : support multiple types)
    GPUCMD_AddWrite(GPUREG_INDEXBUFFER_CONFIG, 0x80000000|((u32)indexArray));
    //pass number of vertices
    GPUCMD_AddWrite(GPUREG_NUMVERTICES, n);
   
    GPUCMD_AddWrite(GPUREG_VERTEX_OFFSET, 0x00000000);
   
    GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG, 0x2, 0x00000100);
    GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG2, 0x2, 0x00000100);
   
    GPUCMD_AddMaskedWrite(GPUREG_START_DRAW_FUNC0, 0x1, 0x00000000);
    GPUCMD_AddWrite(GPUREG_DRAWELEMENTS, 0x00000001);
    GPUCMD_AddMaskedWrite(GPUREG_START_DRAW_FUNC0, 0x1, 0x00000001);
    GPUCMD_AddWrite(GPUREG_VTX_FUNC, 0x00000001);
   
    // CHECKME: does this one also require GPUREG_FRAMEBUFFER_FLUSH at the end?
}

This all looks like low level GPU access; you don't actually need to do that as there are higher-level drawing functions available.
 

cal64

Well-Known Member
OP
Newcomer
Joined
Oct 31, 2016
Messages
65
Trophies
0
Age
30
XP
436
Country
France
you don't actually need to do that as there are higher-level drawing functions available.
Wait, what? Where? I've always used writing to registers to draw stuff...
Also, Thanks A LOT for clearing all that up...
It even seems gpu-old.c was removed from the ctrulib repository...
 
Last edited by cal64,

mashers

Stubborn ape
Member
Joined
Jun 10, 2015
Messages
3,837
Trophies
0
Age
40
Location
Kongo Jungle
XP
5,074
Country
Last edited by mashers,

cal64

Well-Known Member
OP
Newcomer
Joined
Oct 31, 2016
Messages
65
Trophies
0
Age
30
XP
436
Country
France
Well, thanks anyway!
(Also, just to make sure if you don't mind, are there higher-level drawing functions in the end?)
Again, thanks for everything!
 

mashers

Stubborn ape
Member
Joined
Jun 10, 2015
Messages
3,837
Trophies
0
Age
40
Location
Kongo Jungle
XP
5,074
Country
Well, thanks anyway!
(Also, just to make sure if you don't mind, are there higher-level drawing functions in the end?)
Again, thanks for everything!
I don't know if there are any higher level GPU functions as everything I've done in ctrulib uses the framebuffer. But since you're already familiar with GPU rendering, you could just bypass ctrulib for that and write your own convenience functions which do the register stuff.
 

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,032
Country
United States
Hi! I've been studying the portal3DS source code for a while now, and there's something I can't quite understand:
In the source code are functions like GPU_DrawArrays() of which I can't find the declaration in the ctrulib source code, however they're listed in the libctru.cfg file (in the ctrulib repository).
Can anyone tell me what I'm not getting here/how these functions work?
Thanks in advance!
Portal3ds was written with a very early version of ctrulib. Nearly all of the 3D API calls have been deprecated and are now part of citro3d. Which you can get here https://github.com/fincs/citro3d and the are examples with devkitpro here https://github.com/devkitPro/3ds-examples/tree/master/graphics/gpu
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: Like for micro