LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Thu Sep 14, 2017 6:47 am

One rotating wavefront OBJ 3D mesh
https://streamable.com/yte1n

Code is up
https://github.com/LdB-ECM/Raspberry-Pi ... LES2_Model

Now we are getting way beyond just a simple rotating triangle :-)

Anyhow off to find out where they have hidden the shader compiler I want some colours so it looks like this
Image

Who said you can't baremetal accelerated graphics.

User avatar
Gavinmc42
Posts: 2122
Joined: Wed Aug 28, 2013 3:31 am

Re: Accelerated graphics

Thu Sep 14, 2017 8:46 am

Had trouble with the 3D model img files, nothing on screen.
Will check later at home.

But triangle and rotate version worked.
If you can map the jpg onto the 3D surface, that will be something.
Might take me 6 months to figure it out and catch up:oops:

Hardware Scaler next on your list?
Or try the JPEG hardware?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Thu Sep 14, 2017 10:25 am

If you have the display text showing vertex count etc it means the model is too big for the screen resolution and has hit the clip limits.

It doesn't display when that happens, I haven't worked out how to turn them off :-)

I am on 1280 x 1024 and at a guess your default is smaller so let me scale the model smaller and make a quick bit of code to select the appropriate one. Thanks for that I forgot that could happen.

I am getting an ever increasing list.

1.) The VBO on the GL pipe is limited so I need to organize splitter code to transverse multiple VBO's when needed for really large models.
2.) I need to sort the text/jpeg loading which I have sort of worked out how it all happens. I know how to bind it and UV and normal maps to the triangle surface already but I need to adapt one of the free jpeg libraries for the load. I have SDCard and FAT32 running so can work on that now.
3.) I need to find the shader compiler so I can bind my own shader code.
4.) The scaler should come in solo under message system will look for that.
5.) The one I would like to do is bind a MMAL surface to two triangles (AKA a square) so I can play video on a surface. I assume the PI can do that as it came in with OpenGL 3.1.

I haven't got much interest in it but now understanding the VCOS properly I could do the camera because someone already worked out how to shim that. That stuff Eric Anholt commented just peeled open so much because you can know what is happening on the GPU GL pipeline side.
https://github.com/drhastings/cameragl

User avatar
Gavinmc42
Posts: 2122
Joined: Wed Aug 28, 2013 3:31 am

Re: Accelerated graphics

Thu Sep 14, 2017 11:51 am

My normal Pi screens are the old Dells with USB hubs which are 1280x1024.
This is my standard PI development resolution.

Had trouble with the img files on old model 2 and 3 but the triangle/quad img files work on Zero, A+ , B+ and original B.
The 3D model version does not work on any, the activity led flashes once and then nothing :(
On the Zero after the led blinks I notice a very quick flash on screen.
The monitor LED goes green so it knows something is coming in, pull off power and monitor goes the orange standby mode.

I mostly do Ultibo development on Zero's as I use USB boot mode to download my Ultibo kernel.img, no more programming SD cards ;)
viewtopic.php?f=72&t=184840
And the Zero is the fastest BCM2835 model 8-)

I had trouble with your boot files, replaced yours with the latest and both your triangle examples work on Zero USB boot :P
The RPIboot program is a bit fussy with the boot files.

Burtyb has a version for his Clusterhat that downloads extra stuff, it could be modified for data/image folders?
https://github.com/burtyb/usbboot

The 3D model won't work because the data folder does not get copied by the rpiboot program I run on Mint but I did get a quick flash of three lines , some about "waiting for interrupt".

Videos on surfaces should be possible as it was in the normal VC hello demo code so I assume it uses hardware acceleration.
That assumes you can get video working :D

There seems to be some scaler code in the Linux kernel gpu/drm/vc4 folders, not sure how useful that would be or even if Eric uses it yet?
I think on one of his posts there was something about it.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
Gavinmc42
Posts: 2122
Joined: Wed Aug 28, 2013 3:31 am

Re: Accelerated graphics

Thu Sep 14, 2017 12:20 pm

There is also a mouse cursor tile engine that goes up to 64x64 pixels,
I used the mouse cursor example to pay with it
https://github.com/ultibohub/Examples/t ... ouseCursor

Been having some fun with it, is should be relatively easr for you to make a baremetal version.
https://ultibo.org/forum/viewtopic.php? ... use+cursor.
You can see why I am keen on the gpu stuff ;)

3D procedurally generated terrain with textures, only weeks away?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Thu Sep 14, 2017 1:36 pm

Just read what you were doing and yes you won't be able to run the rotating model because the code specifically mounts the sdCard and tries to load the file from that. I will add mounting USB and loading file from that to me to do list, you will be able to use it then :-)

However in the meantime I autoscaled it so it should work on every resolution.

Update: I found that Eric confirmed what I suspected that you can bind the camera output directly onto a VC4 plane (http://anholt.livejournal.com/46702.html) and he has provided hack code to do it. Might do that for another sample.

User avatar
Gavinmc42
Posts: 2122
Joined: Wed Aug 28, 2013 3:31 am

Re: Accelerated graphics

Fri Sep 15, 2017 3:35 am

Not too worried about the SD card at this time for the Zero
Ultibo already has SD card support, but there are ways to embedded the files in the kernel.img.
USB loading will be interesting.

We have some flight sims around the place, making real glass instruments based on USB Zeros would be fun and low cost.
Something I had thought about years ago, now looking doable. Just need to figure out how to do circles etc.
Better get myself some more Zero's, now that I figured out a way to use lots :lol:

Camera will be interesting.
Not sure if you can use the ISP, magic pixie dust in that, so no lens correction etc but there is a RAW camera sensor post.
viewtopic.php?f=43&t=109137
You will probably need to get i2c working first.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Mon Sep 18, 2017 6:44 pm

Okay so got textures working I just need to now write a quick texture loader (at least I have FAT32 running so only half work to loading model).

Eric Anholt was so kind as to actually answer my question of where the shader compiler is.
Quote => The entire shader compiler is in the Mesa vc4 driver.

It's open source so looks like I am also going to have to slice and dice a minimal shader compiler from it, because I really needed more work :-)

I will probably cheat for speed initially and make a couple of shaders on Raspbian and save the binary, I have worked out how to get to them.

User avatar
Gavinmc42
Posts: 2122
Joined: Wed Aug 28, 2013 3:31 am

Re: Accelerated graphics

Tue Sep 19, 2017 1:30 am

The entire shader compiler is in the Mesa vc4 driver.
in here?
https://github.com/anholt/mesa/tree/mas ... rivers/vc4

Had not looked too hard in the mesa stuff.
Hmm, gears example in there too?

This the compiler?
https://github.com/anholt/mesa/tree/master/src/compiler
Look like a bunch of learning, getting a bit complex for me.
Really don't want to learn C++ and Linux driver stuff if I can help it, I don't think I have that much neuroplasticity left :lol:
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Tue Sep 19, 2017 5:25 am

That is the one and it looks like it produces byte code which you pass to the GL pipeline, I would say.

I wish there was someone to ask some real basic questions, like how many memory handles does the VC4 have. I am packing stuff together to make bigger structures to limit how many blocks I have allocated and locked because I am concerned there are limited VC4 memory handles.
Like I am binding all my textures into one big long memory allocation, rather than 1 for each. makes loading and removing a texture much harder. The thing is you just don't know I could be doing it all wrong :-)

LizardLad_1
Posts: 126
Joined: Sat Jan 13, 2018 12:29 am

Re: Accelerated graphics

Thu Aug 30, 2018 10:45 am

Hi all,

I'm probably looking at code that is too old and obsolete however I'm only trying to make a two layer compositor with triangles using LdB's GLES code I'm currently looking at using the GLES code not GLES_Rotate or GLES_Model because that has functionality that isn't required. I'm trying to draw four triangles with textures on them with the front pair having an alpha channel. Is this possible and if so how should I approach this?

EDIT:
GLES_Rotate looks a bit cleaner but it is still fairly confusing. For example why for each vertex do so many uint* need to be emitted?

User avatar
Paeryn
Posts: 2168
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Accelerated graphics

Thu Aug 30, 2018 12:33 pm

LizardLad_1 wrote:
Thu Aug 30, 2018 10:45 am
GLES_Rotate looks a bit cleaner but it is still fairly confusing. For example why for each vertex do so many uint* need to be emitted?
I just had a look and each emit for the verticies is commented.

7 vertices to make 1 triangle and 1 quad (a quad is 2 triangles sharing 2 verticies). Each vertex needs its position (4 emits for x, y, z, 1/w) and colour (3 emits for r, g, b). 7 verticies * 7 emits needed.
She who travels light — forgot something.

LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Thu Aug 30, 2018 2:56 pm

All emit does is write the value and advances the pointer.

The floats on the VC4 are 4 bytes floats exactly, depending what compiler setting you compile with on the arm your floats aren't usually 4 bytes.
It's probably not too bad for you as I believe you are compiling AARCH64 with hard floats so your standards are set. My code as written I have no idea what compiler of settings people are using.

http://infocenter.arm.com/help/index.js ... 06s01.html

Code: Select all

Table 4.7. Operand name for differently sized floats
Precision	Size (bits)	Name
Half	            16	           Hn
Single	             32	           Sn
Double	             64	           Dn
So hardware AARCH64 single precision is the right size whether they are in the right order you would need to look at, they are registers on the VC and the ARM.

So we "emit" so we know that the data we are writing is the right size and order.

So basically you write code to emit the basic types in the right byte order and advance the pointer out of pure safety. You can also store sizes and pointers along the way because often the structure needs VC offsets and sizes. You can't just use ARM sizes you need the VC sizes.

Once you have built things via emit you don't recreate them you can scale, rotate etc by simply changing the viewing matrix. SO speed is not an issue here it's a model. Look at a software GL pipeline it's easier to understand
https://www.davrous.com/2013/07/18/tuto ... ing-webgl/

That is the end of the series go back to lesson 1, which covers the camera

When you build your triangles to a point it doesn't really matter how big or small they are. Okay if you made them really small and zoom in on them they will get all jaggies along them and make them to big and the VC will take microseconds longer to render because of the scale. But in some middle ground the size is not significant, you setup a viewing matrix to give what you need.

If you look at the rotating plane I build the model exactly once ... the rotation is purely a viewing matrix change.

LizardLad_1
Posts: 126
Joined: Sat Jan 13, 2018 12:29 am

Re: Accelerated graphics

Sat Sep 01, 2018 2:28 am

Hi,

I understand the GLES code now, thanks.The error unable to allocate memory from videocore now occurs. I have got almost exactly the same functions LdB uses for mailbox communication and I thought I did it correctly but apparently not. Does anyone know a reason the videocore couldn't allocate memory?

LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Sat Sep 01, 2018 3:43 pm

You asked for too much or your message structure wasn't 16 byte aligned with a VC address :-)

I am guessing aligned issue .. there is a trick in my code look at the mailbox command.
first I copy the data you provide to an align 16 message

Code: Select all

uint32_t __attribute__((aligned(16))) message[32];
The second thing is for those functions you need to pass the message as a VC address NOT an ARM

Code: Select all

mailbox_write(MB_CHANNEL_TAGS, ARMaddrToGPUaddr(&message[0])); // Write message to mailbox
                                ^^^^^^^^^^^^^^^^^^^^  
                                NOTE THIS
On all the other tag messages you were able to pass ARM addresses (well except if you are on old firmware .. you used to have to send VC addresses). They sort of patched the GPU on most of the normal TAG stuff to add the adjust the address in the VC if you forgot. On those messages they haven't they must be VC addresses to your structure address (so OR is with 0xC0000000). There are no kid gloves when playing with the GL Pipieline always check what address you have used.

But anyhow the GPU defaults to only 80Mb or something like that from memory, when you start playing with the VC4 you need to give it some more.

Make a text file called config.txt and put a single line in it
gpu_mem=128

Stick it on the SD with your normal 4 files and try again. Off the top of my head I believe the limit is 300Mb which would be for intensive OpenGL apps.

If you use the pi mailbox memory tags and get memory info you should see the memory split has shifted to confirm it worked and the GPU read the file and changed it at boot.

LizardLad_1
Posts: 126
Joined: Sat Jan 13, 2018 12:29 am

Re: Accelerated graphics

Sun Sep 02, 2018 5:10 am

I think I found an even larger bug. My code that I use to get the memory split fails. I have certainly done something wrong. I will continue looking into it.

UPDATE: I fixed it it was an mmu error I can now return the gpu memory split. The allocation error still occurs I will continue looking into that also.

LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Sun Sep 02, 2018 10:09 am

Having the MMU on adds in problems, as in cache issues, get your code working without it first ... that is my advice as the VC4 is doing all the real work and nothing you do arm side is going to affect it's speed :-)

You will have the same problem as the activity LED code when you lost control of the mailbox, do you remember what I had to do to the message before I sent it to the VC !!!!!

LizardLad_1
Posts: 126
Joined: Sat Jan 13, 2018 12:29 am

Re: Accelerated graphics

Mon Sep 03, 2018 7:03 am

Hello,

I turned the mmu off and I still get the unable to allocate memory error. I have checked alignment and it looks all good are there other reasons it wouldn't function?

LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Mon Sep 03, 2018 8:16 am

Throw it on github and I will have a look :-)


LizardLad_1
Posts: 126
Joined: Sat Jan 13, 2018 12:29 am

Re: Accelerated graphics

Mon Sep 10, 2018 2:40 am

Do you have any idea of why it would be failing?

LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Mon Sep 10, 2018 5:26 am

There is nothing wrong with your the Videocore code it works perfectly (on Pi3 & Pi3B+), just comment out these two in main

Code: Select all

clocks_init();
init_audio_jack();
You will get this.
Image

Whatever is going wrong with those two functions triggers something that clears the screen. It's that thing I refuse to debug the rest of your code because the coding style is horrible to me, I am not saying it's wrong I just don't code like that. There is something in those two units but as every unit includes every header via project.h working out what is calling what becomes detective work as the functions it is calling can literally be in any file. So when I go to find clocks_init I have no idea where it is I have to start searching every file.

Took only a minute to find because I just started commenting everything out so I had the bare minimum to walk thru.

Just a comment all this casting is not required

Code: Select all

render_quad(lfb_width, lfb_height, ARM_addr_to_GPU_addr((void*)(uintptr_t)lfb));
lfb is a a pointer just pass it thru

Code: Select all

render_quad(lfb_width, lfb_height, ARM_addr_to_GPU_addr(lfb);
Oh and if you get the triangles much bigger you will probably need to allocate a bit more binning buffer space.

LdB
Posts: 866
Joined: Wed Dec 07, 2016 2:29 pm

Re: Accelerated graphics

Tue Sep 11, 2018 6:26 am

I was feeling benevolent so crawled thru umpteen files ... Same old same old

clocks_init is bugged because Getmaxclock speed is Tag: 0x00030004 the funny part is your comment 3 lines up even says that yet you use
Tag: 0x00038004. That is an illegal tag and not sure what it does, but the VC refuses to talk after you send it. Weirdly the VC is still running but you just can't communicate with it. The mailbox documentation doesn't mention it but it's almost like it is waiting for us to do something to clear the error. I have no clues what to do but it's clear don't send bad tags to the VC :-)

I also warn you clocks_init calls directly thru mailbox_tag_write and mailbox_tag_read which don't have the flush on the address etc you have on the buffered call

I was lazy and just modified them to use the buffered call

Code: Select all

void set_cpu_clock(uint32_t clock_rate)
{
	mailbox_tag_message(0, 5,
		0x00038002, 8, 8, 3, clock_rate);
}

Code: Select all

uint32_t get_cpu_max_clock()
{
	uint32_t buffer[5] = { 0 };
	if (mailbox_tag_message(0, 5,
		0x00030004, 8, 8, 3, 0))
	{
		return buffer[4];
	}
	return 0;
}
There is still an issue with init_audio_jack but that is all assembler and I am not feeling that benevolent :-)
I don't think it has anything to do with the mailbox it just seems to start spewing junk up on the screen, clearing your GLES output in the process.

LizardLad_1
Posts: 126
Joined: Sat Jan 13, 2018 12:29 am

Re: Accelerated graphics

Tue Sep 11, 2018 8:28 am

Thank you LdB. Sorry about my coding style I'm in an Australian high school where the only language the teacher knows is php and pascal. My teacher I think had a worse coding style than me all of his programs use global variables, nothing local. If you have any ideas of how I can improve and learn please feel free to share them.

Another question, what would it involve to get a shader compiler working as I am interested in looking into that area?

User avatar
Gavinmc42
Posts: 2122
Joined: Wed Aug 28, 2013 3:31 am

Re: Accelerated graphics

Tue Sep 11, 2018 8:32 am

Pascal?
Show your teacher this, it's ozzie too :D
https://ultibo.org/
And yes accelerated graphics works now.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Return to “Bare metal, Assembly language”