Skip to content

Add native pipeline support and texture related functionality#8871

Merged
harry-cpp merged 13 commits intoMonoGame:developfrom
sepcnt:develop
Jul 6, 2025
Merged

Add native pipeline support and texture related functionality#8871
harry-cpp merged 13 commits intoMonoGame:developfrom
sepcnt:develop

Conversation

@sepcnt
Copy link
Contributor

@sepcnt sepcnt commented Jul 2, 2025

This PR addresses bounty #8641 by replacing the FreeImage and StbImageSharp dependencies with a new, in-house native C++ pipeline library (mgpipeline) for texture importing.
The changes improve modularity and performance by consolidating image-related operations into the mgpipeline library. Additionally, submodule management and project dependencies have been updated to reflect these changes.

Image Processing Refactor:

Native Library Integration:

Submodule and Workflow Updates:

  • .gitmodules: Added a new submodule for external/stb, ensuring proper version control for dependencies.
  • .github/workflows/main.yml: Updated the repository cloning step to include submodules recursively in deploy stage.

File Format Export:

Cleanup and Simplification:

- Updated .gitignore to include Premake generated files.
- Added new submodule for stb_image.
- Created native pipeline library with C API for bitmap import.
- Implemented texture importing using native methods in TextureImporter.
- Enhanced build process for native pipeline with Premake and MSBuild.
- Added README and API headers for the native pipeline.
Copy link
Member

@harry-cpp harry-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the test that is failing, for the switching to stb_image we have decided to not support any image format not supported by it for importing.

@sepcnt sepcnt force-pushed the develop branch 3 times, most recently from d3cfc00 to 8589466 Compare July 3, 2025 04:44
@sepcnt sepcnt requested a review from harry-cpp July 3, 2025 05:25
- Rename native pipeline to `mgpipeline`
- Remove TIFF format test and asset
- Update .gitignore and enhance BuildContentPipelineTask for cross-platform support
- Remove system-specific path from platform target in premake5.lua
- Refactor API export macros for improved cross-platform compatibility
- Refactor `MGCP_Bitmap` to use reference types for better memory management and error handling
- Fix Linux native pipeline library reference in project file
- Refactor `MP_ImportBitmap` to satisfy GCC
@sepcnt
Copy link
Contributor Author

sepcnt commented Jul 3, 2025

To totally remove FreeImage and StbImage(Write)Sharp, there are few more APIs to implement:

  • MG_ResizeBitmap
  • MG_ExportBitmap

However, there's a critical bug in BasicUHelpers and CrunchHelpers:

PngFileHelper.WritePngToIntermediate(sourceBitmap, out pngFileName);

var colorBitmap = new PixelBitmapContent<Color>(sourceBitmap.Width, sourceBitmap.Height);

That means all textures are converts to rgba8 regardless of there original color depth (16bit or float)

@sepcnt sepcnt changed the title Add native pipeline support and texture importing functionality Add native pipeline support and texture related functionality Jul 3, 2025
@harry-cpp
Copy link
Member

Since its happening on the current develop branch I'd recommend just leaving it working as is in here, and just opening a new issue about it (with a couple of comments in code about the issue).

Tho if its something thats easy to fix, feel free to do it here.

@sepcnt
Copy link
Contributor Author

sepcnt commented Jul 3, 2025

Since its happening on the current develop branch I'd recommend just leaving it working as is in here, and just opening a new issue about it (with a couple of comments in code about the issue).

Tho if its something thats easy to fix, feel free to do it here.

Okay, it's weird but works. I opened an issue for it here #8874

Copy link
Member

@harry-cpp harry-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to setup a way to package up MonoGame.Content.Pipeline for all the platforms, right now each platform is makings its own nuget that only has 1 native assembly in it for itself which would break stuff.

To do this I recommend:

  • Upload each mgpipeline native lib as an artifact during build
  • Download each mgpipeline native lib during Deploy, place them in the Artifacts folder and combine then rebuild just the MonoGame.Content.Pipeline by creating a brand new cake task

We use GitHub actions located in .github/workflows and C# Cake project located by opening Build.sln in root for CI operations, I believe you just need to modify the C# side of things for this, you can test on your local fork by enabling github actions on it.

Another thing to note is that mgpipeline needs to be statically linked and the CI should check for that. You can grab the code for that from: https://github.com/MonoGame/MonoGame.Library.BuildScripts/blob/5cd1ee39dfa0e570b125260d4d19753232c1c29e/Tasks/TestLinuxTask.cs#L5 (there is 1 task for each platform)

@harry-cpp
Copy link
Member

PS. Feel free to ping me on discord for me to review the PR or if you have any questions about this, I should notice it much quicker then on github ^^

sepcnt added 3 commits July 4, 2025 23:00
…p processing, add resizing functionality, and update related enums and structures.
@sepcnt sepcnt requested a review from harry-cpp July 4, 2025 15:42
@sepcnt sepcnt requested a review from harry-cpp July 4, 2025 18:44
@sepcnt sepcnt force-pushed the develop branch 2 times, most recently from da0fe76 to 6ae52f8 Compare July 5, 2025 04:41
- Fix bpp calculation bug to avoid wasting memory
- Add static library check task
- Fix premake5 configuration for macOS universal support, static linkage on
  Windows

#define MG_FIELD_OFFSET(off, type, name) struct { char _pad_##name[off]; type name; }

#if defined(_WIN32) || defined(__CYGWIN__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how these changes in the export will affect the consoles... will have to test it later and fix things. It however worked before.

@harry-cpp harry-cpp merged commit 7c9db54 into MonoGame:develop Jul 6, 2025
7 checks passed
@harry-cpp
Copy link
Member

Looking good so merging! Thank you very much for getting this work done @sepcnt !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants