summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2025-08-11gst-decoder: Inline buffer_to_image() inside video_frame()HEADmasterAndrew Davis1-36/+16
As an existing comment suggests, buffer_to_image() can be inlined into the video_frame() function. Do this here. Signed-off-by: Andrew Davis <afd@ti.com>
2025-08-11gst-decoder: Use GStreamer glupload for video cubeAndrew Davis4-184/+67
Currently gst-decoder.c manually uploads each video frame provided by GStreamer. It does this by attaching the DMA-BUF (or making a DMA-BUF if GStreamer doesn't provide one) to an EGLImage. It then binds this EGLImage to an external texture sampler target. The GStreamer "glupload" element can do all this for us and much more. The glupload element supports many more formats and also checks if the GPU can directly import these formats, while also handling converting in shaders if the format is not supported. While we could add these checks and missing texture format support to kmscube, that effort would be better spent improving the core GStreamer glupload, as improvements there benefit all GStreamer users. The plugin gets better OES_EGL_image_external support starting in 1.24, but as kmscube only requires 1.22 currently we move to using normal GL_TEXTURE_2D in cube-video.c. We can switch back to GL_TEXTURE_EXTERNAL_OES when we move to 1.24 if it shows better performance on some platforms, but so far no platform I have tested on shows any issue with using regular 2D texture targets. Switch to using glupload here. The result is less code to maintain in kmscube while also providing a much greater range of supported formats. Signed-off-by: Andrew Davis <afd@ti.com>
2025-08-09kmscube: add write to png option to offscreenErico Nunes4-8/+44
Add an option to write frames to png files. libpng was already an optional dependency to kmscube and texturator already had that feature, so we can reuse most of that. This is mainly useful in the offscreen mode to view the rendered frames when using a machine without an accessible display, so for now limit this feature to offscreen. Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
2025-08-09common: move write to png functionality to commonErico Nunes3-39/+48
This was originally in the texturator program, but it can be used as-is to implement write to file in kmscube, so move it common. Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
2025-08-08kmscube: try drmModeAddFB if drmModeAddFB2 doesn't workMaya Matuszczyk1-0/+11
Upstream Linux disables addfb2 ioctl on big_endian machines on most drivers. This commit works around that issue. Signed-off-by: Maya Matuszczyk <maccraft123mc@gmail.com>
2025-07-25kmscube: Move cube vertex data to common locationAndrew Davis7-554/+91
All the cubes can share a common set of vertex data which simplifies each cube and saves program data. Factor out the common cube vertex data into a common location. Also interleave the vertex data which allows for loading this data to the GPU with a single glBufferData() call. This should also make the vertex fetching slightly more efficient by keeping the data for each vertex closer in memory (not that this really matters much, but it is nice to have example code like this do things the right way). Lastly, label the data components to more easily see what is going into each vertex while defining the data structure. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25kmscube: Combine shader compiling and linking functionAndrew Davis8-70/+19
As we now do not need to set binding locations in-between compiling and linking our shaders, we can combine these two into one function that does both. Do this here for all cubes. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25kmscube: Get attribute locations dynamically over static bindingsAndrew Davis6-92/+80
While both specifying the binding location and letting the compiler pick the location do work, setting the binding manually often leads to bugs like found in previous patches. Since we do not need to force aliasing here we can switch to letting the compiler pick. This also allows for combining compilation and linking as no in-between step of specifying the binding location is needed. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25gst-decoder: Reuse already fetched sink padAndrew Davis1-4/+2
The pad handle for our "sink" element is already fetched and correctly unref'd above when setting up the query probe. Use the same for the event probe. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-video: Use new VBO for blit vertex dataAndrew Davis1-3/+19
The 3 cubes: gears, shadertoy, and video all use a second program for rendering something other than a cube. For the first two they already use a second VBO for the non-cube vertex data, but video cube aliases the cube VBO to define vertices for the background rendering. While this does work, it is easy to define exactly the vertex data we need and put this in a separate VBO. This helps later if we want to better split background rendering from cube face rendering. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-video: Create new frame after setting up new decoderAndrew Davis1-0/+9
When we get to the end of a video a NULL frame is returned, this signals that we should rebuild the decoder to start a new video. The issue is after making this new decoder we do not fetch a new frame, which means a NULL frame EGLImage is set as the texture target. This is usually harmless and results in a single frame of black video. Instead fetch a new frame. While here also check that the new decoder was created successfully. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-video: Do not setup VertexAttribPointer in initAndrew Davis1-6/+18
Vertex attribute information should be setup each draw loop as we switch shader programs and each may use different attribute information. They do not currently, but will in a later patch. This is also cleaner as we should be disabling attribute arrays not used by the current program. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-video: Do not setup texture parameters each drawAndrew Davis1-6/+5
We do not need to delete and re-generate our texture object at the end of video, keep the same object. This allows us to set the texture parameters for this texture object as part of init and not each draw loop. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-gears: Save and restore viewportAndrew Davis1-6/+5
Instead of setting the viewport each draw loop based on the stored screen width and height, if we need to modify the viewport for offscreen rendering, save the current viewport and restore it when done. This allows us to avoid saving the width and height. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-gears: Only generate framebuffer texture and renderbuffer onceAndrew Davis1-12/+9
Instead of destroying and re-creating the gear framebuffer each draw loop, create it once on init and simply re-bind it in each draw loop. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-gears: Do not use renderbuffer texture targetsAndrew Davis1-12/+3
Using a normal texture as the renderbuffer target is actually an extension and not always available in GLES2.0. Instead we can use glRenderbufferStorage and glFramebufferRenderbuffer for the same result here as we do not later make use of the depth buffer as a texture. This makes this more portable to more basic GLES2.0 implementations. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-gears: Only set vertex attributes when neededAndrew Davis1-9/+6
Without vertex array objects (not available in ES2.0), vertex attributes are global and so should be setup, enabled, and then disabled around the draw function that make use of them. This keeps state local to prevent bugs. The draw_gear() function already does this, but the cube drawing does not. Move the vertex attribute setup out of init() and to draw(). This will prevent any accidental overwriting of vertex attributes should any other attribute location alias these in a different program (attribute locations are per-program, but attribute indexes are global!). Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-gears: Redisable depth testing before drawing cubeAndrew Davis1-4/+2
If we leave depth testing enabled but do not clear the depth buffer then drawing this cube may end up being masked by the gears' depth buffer. Since we do not need depth testing when drawing the cube, redisable depth testing before drawing the cube. While here, do not enable and disable face culling each draw loop, it is enabled in setup and can be left enabled. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-tex: Bind attribute location 2 to in_TexCoord not in_colorAndrew Davis1-1/+1
The attribute name we are looking for is called "in_TexCoord" in the shader, but we set the bind number for "in_color". This usually works okay anyway as 2 would be the next available number, but we should ensure correct behavior by specifying the correct attribute name. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-shadertoy: Save and restore viewportAndrew Davis1-7/+5
Instead of setting the viewport each draw loop based on the stored screen width and height, if we need to modify the viewport for offscreen rendering, save the current viewport and restore it when done. This allows us to avoid saving the width and height. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-shadertoy: Do not assume 0 is default framebuffer numberAndrew Davis1-2/+9
The function draw_shadertoy() binds a texture framebuffer object for rendering the shadertoy onto and then restores the old framebuffer. But it assumes the old framebuffer object number was 0, which is usually the case but that is not guaranteed. To be fully correct we should fetch the current framebuffer number and restore to that. This exposes another issue that init_shadertoy() rebinds the framebuffer but never sets it back to the original value. This was masked by the unconditional binding to 0 in draw_shadertoy(). Now that it doesn't always rebind to 0, we never rebind to the original. So save and restore the framebuffer number in init_shadertoy() also. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-shadertoy: Do not setup VertexAttribPointer in initAndrew Davis1-6/+0
Vertex attribute information is setup each loop before drawing, no need to set this up in init as it will be overwritten each draw call anyway. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-shadertoy: Do not setup texture parameters each drawAndrew Davis1-5/+0
The texture parameters for this texture object are already setup as part of init, no need to do these each draw loop. It also was setting GL_TEXTURE_WRAP_R which is unneeded for 2D textures. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-shadertoy: Bind attribute location 2 to in_TexCoord not in_colorAndrew Davis1-1/+1
The attribute name we are looking for is called "in_TexCoord" in the shader, but we set the bind number for "in_color". This usually works okay anyway as 2 would be the next available number, but we should ensure correct behavior by specifying the correct attribute name. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-shadertoy: Bind attribute location for correct programAndrew Davis1-1/+1
The attribute "position" in the shadertoy program should be bound to 0 location, but we call glBindAttribLocation on the cube program instead. This still tends to work out as 0 is the default lowest binding index, but we should be explicit here and ensure correct behavior. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25cube-shadertoy: Do not re-enable face culling each draw loopAndrew Davis1-1/+0
This is enabled on setup and nothing disables it, no need to re-enable face culling each draw loop. This matches most other cubes. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25kmscube: The clear color only needs set onceAndrew Davis7-12/+12
The clear color is global state that only needs set once. Move this to the cube init functions and out of the draw loops, only the glClear() call itself needs done each loop. Remove the glClear() from the kmscube main function while here as all cubes already call this as part of their draw loop anyway. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25kmscube: Do not recompute projection matrix each frameAndrew Davis5-34/+25
The projection matrix only changes with aspect ratio changes, track the projection matrix for the current aspect ratio. This allows us to not recompute it each frame. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25kmscube: Cast normal matrix from modelview matrix in shaderAndrew Davis5-75/+10
The operation of taking the 3x3 matrix starting at 0,0 from a 4x4 matrix is common enough that it is the default action when casting mat4 to mat3. So instead of manually building out a 3x3 normal matrix from the modelview and passing that into the shader, simply have the shader cast the normal matrix from the already available modelview matrix. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25perfcntrs: Move timer function out of common to perfcntrsAndrew Davis3-14/+12
This timer function and related definitions are only used by the perfcntrs code, move them out of common. Signed-off-by: Andrew Davis <afd@ti.com>
2025-07-25esUtil: Remove unused definitions and function declarationsAndrew Davis1-169/+0
Only some parts of the esUtils are actually defined in esUtil.c, remove extra definitions and function declarations from esUtil.h. Signed-off-by: Andrew Davis <afd@ti.com>
2025-06-23kmscube: turn buf_to_fd() into a helper reused by cube-texAndrew Davis4-140/+69
Do as the TODO comment in gst-decoder.c suggests and turn this function into a common helper. Signed-off-by: Andrew Davis <afd@ti.com>
2025-06-04kmscube: factor out FPS reportingAndrew Davis5-88/+69
The FPS code is common for each run loop. Factor this out into and put in perfcntrs.c. Signed-off-by: Andrew Davis <afd@ti.com>
2025-06-04kmscube: factor out init_egl() from each cube initAndrew Davis12-68/+73
The call to init_egl() can be made before calling the cube init function. This allows it to be factored out into a common location. struct egl is then passed in to each init() for use as needed; the same as struct gbm. As the cube init function no longer needs to modify struct egl outside of setting the draw function, to keep egl const move the draw call out of egl. It didn't make much sense in here to begin with and seems to have been placed in this struct out of convenience. Move the draw function to a new struct of cube specific data. Signed-off-by: Andrew Davis <afd@ti.com>
2025-06-04kmscube: refactor init_egl() to return a new egl instanceAndrew Davis7-67/+64
This matches init_gbm() and allows for more refactoring in later patches. Signed-off-by: Andrew Davis <afd@ti.com>
2025-06-04kmscube: store width and height instead of gbmAndrew Davis2-7/+8
For a couple cubes we only store the gbm struct to get access to the screen buffer resolution. Just store the resolution directly. Signed-off-by: Andrew Davis <afd@ti.com>
2025-06-04cube-gears: Remove unneeded extension checksAndrew Davis1-5/+0
These EGL extension are not used in this cube, remove these checks. Signed-off-by: Andrew Davis <afd@ti.com>
2024-11-06kmscube: gears: use only GLES2Erico Nunes1-3/+1
The gears mode currently depends on either GLES3 or desktop GL to build, but in both cases without a proper meson dependency check. It also doesn't really use any features which would require those GL versions over GLES2, which is already a global dependency of kmscube. So just change it to use symbols which are available in GLES2 and it can be built and run in all platforms. Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
2024-09-26common: fix cast type in init_egl()Eric Engestrom1-1/+1
On some platforms, `EGLNativeDisplayType` is an int instead of a pointer, in which case the void pointer will raise a `-Wint-conversion`. Let's cast it to the correct type directly. Closes: https://gitlab.freedesktop.org/mesa/kmscube/-/issues/16
2024-09-26gst-decoder.c: switch to decodebin3Hugues Fruchet2-2/+2
decodebin3 is no more experimental since GStreamer-1.22: https://gstreamer.freedesktop.org/releases/1.22 decodebin3 is now prefered to decodebin till GStreamer-1.24: https://gstreamer.freedesktop.org/releases/1.24 This solves negotiation issues encountered with V4L2 stateless hardware video decoders when using kmscube video playback option. Signed-off-by: Hugues Fruchet <hugues.fruchet@foss.st.com>
2024-09-24kmscube: warn of missing mode argument in offscreen rendersAdrian Larumbe1-0/+5
Offscreen renders need an explicit video mode to be passed by the user. However, when it's missing, current error handling just says that initialising a DRM device failed, which sounds a bit misleading. Add a warning message asking for a video mode command line parameter. Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com> Apply 1 suggestion(s) to 1 file(s) Co-authored-by: Eric Engestrom <eric@engestrom.ch>
2024-05-07Allow running in background with STDIN set to O_NONBLOCKINGMarkus Niebel6-23/+33
Since commit 38986c1 (kmscube: add option to run for specified # of frames) we have the option of running for a given number of frames. This allows usage for instance in automatic system tests like climate chamber etc. To allow starting in background without termination from STDIN add a new option that prevents polling / selecting for console input. Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com> Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
2024-02-26kmscube: Fix incorrect modifier check in create_framebuffer functionChristopher Michael1-9/+7
When importing an egl image from a linux dma buf fd, we need to pass the proper image attributes to eglCreateImageKHR. The modifier check here should not ignore DRM_FORMAT_MOD_LINEAR when setting EGL_DMA_BUF_PLANE0_MODIFIER_LO/HI_EXT else the ordering of samples within a plane will be incorrect, resulting in incorrect/garbled pixels being presented. v2: Update code changes to set EGL_DMA_BUF_PLANE0_MODIFIER_LO/HI whenever an extension exposes modifiers so that INVALID modifiers are accepted (Daniel Stone)
2023-09-26kmscube: Add gears modeScott Moreau4-3/+797
Use gears mode with -g or --gears to render gears on each cube face. Renders gears to texture once and then renders the texture on each face. Based on cube-tex.c and of course, gears.
2023-09-26es: Update to prepare for gears modeScott Moreau2-51/+87
- Add esInvert() function - Add esTranspose() function - Rewrite esRotate() function - Set identity matrix at beginning of esFrustum()
2023-09-26ci: enable MR pipelinesEric Engestrom1-0/+8
2023-08-02Revert "ci: use gitlab proxy to avoid hitting dockerhub every time"Eric Engestrom1-2/+2
This reverts commit f296635648ba31454bfe6a9ff7495f6b28af26ec
2023-07-26kmscube: Add [-n N] option to specify connector IDRalph Campbell6-22/+51
Kmscube currently selects the first connector that has a link status of connected. Add a command line option to use a specific connector if more than one connector has a connected link status. Signed-off-by: Ralph Campbell <ralphcampbell1@gmail.com>
2023-07-12kmscube: add offscreen rendering supportDmitry Baryshkov5-3/+200
It is useful to be able to render the kube without touching the KMS. For example, this allows us to utilise DRM render devices or to measure the performance without waiting for vblank. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-07-08ci: use gitlab proxy to avoid hitting dockerhub every timeEric Engestrom1-2/+2
Signed-off-by: Eric Engestrom <eric@igalia.com>