What is this and what does it do?
(this has got to play in the background)
The the belief that most matter is concentrated in galaxies is false. A relatively huge portion of the matter in our universe is concentrated there, the heaviest of building blocks having been forged in the hearts of collapsing stars and fiery deaths of neutron star collisions, but the vast majority is actually concentrated in the galactic filaments that weave through our universe like roots of a tree or the neurons of some cosmic brain.
Sadly, only a minuscule fraction of the matter in the universe are the heavy elements needed for technology, like copper, nickel, zinc, tin, platinum, gold and lead, all of which are heavier than iron, the nuclear ash of supermassive stars that can fuse past helium throughout their lives.
This means basically all of it is concentrated within galaxies where these stars form, live and die, and so this is what this great machine might fix for a Kardashev Type-3 civilization.
How might it work?
Even I don't pretend to know how one might be built and operated, but I have a basic operating principle in mind. The foundry itself would be built around a rotating black hole, most probably at the churning heart of a galactic quasar, where matter is already kicking up a storm.
As billions of solar masses are syphoned from the galactic filaments per second, they are poured down and into the quasar's accretion disk, converting massive quantities of mass into energy that is funneled into a relativistic jet. The heat and friction as the gas accelerates to a fraction of light-speed as it falls in would be harnessed by this machine to fuse elements, first with a positive net energy, and continuing past iron to fuse even heavier elements.
Such a machine would be beautiful and yet unfathomable in scale, the burning heart and crowning jewel of an intergalactic civilization which satiates its need for raw materials to continue its empire.
The setting for such a machine
After predicting and finally testing the first methods of inter-dimensional travel, a higher plane of existence is discovered, in which abstract concepts start to bleed into reality, and what we collectively believe begins to hold immense power.
This civilizations 'magic', as far as we understand it, directed the energy that permeates the universe to the whims of the minds of these aliens. Part of this technology is controlled by runes carved in stone, which seem to direct energy and hold complex instructions like code for a computer, so far beyond us it might as well be magic.
In this higher dimension, location, relative to our universe, stops making sense. It exists nowhere and everywhere, and controlling the construct that breaches out of this dimension and into the next, space can be traversed in an instant. In effect, teleportation.
But this discovery is their undoing. As they begin to experiment, they realize that there is something beyond this dimension, beyond all of them. A place where the writhing insanity of nonexistance is more than real. The darkness in the back of the minds of the depraved, incarnate.
As they test their machine once again, they realize they have breached reality itself and have begun an invasion of our world. With no way to undo it, they try to stop the Old Ones, cosmic beings of indescribable power, by with their immense knowledge of manipulating black holes, build the Barrier, a machine powered by the Penrose process and accelerated evaporation of a supermassive black hole, which will power the machine and lock away the Outsiders for as long as it continues running.
Why is it important for the story?
As the protagonist touches an inscription carved in stone and imbued with power, they witness a fractured memory of the Empire, a shard of which is the remnant of a space installation which became the moon of Neptune, Triton. Along with it they discover the ancient past of the millions of terraformed planets across the galaxy, and of a supermassive black hole which the forge was built around.
And so my question is this: How would this machine operate? Given the kinds of technology this empire would be using, they're knowledge and machinery to manipulate black holes, and extrapolations of it.
Is it even theoretically possible, in the same way as a black hole bomb is theoretically possible? I don't have a good understanding of the math and physics which operate around black holes, and don't know if such a structure has been theorized and by who.
Is this a believable megastructure for a Kardashev Type-3+ civilization to have built? And if so, how would the math pan out for the energy released by a black hole when fed matter as an accretion disk? Could it be usefully harnessed to make heavier-than-iron elements? How efficient would it be? (within a few orders of magnitude) As far as I understand, it's an efficient mass-energy conversion method, but I don't understand enough about black holes to be sure.
Edit
I should have properly specified that there would be independent infrastructure harvesting, processing and transporting the gas to the Foundry, on an equally massive scale. The black hole and the foundry built on it only process the gas into heavy elements for use as raw materials.
Not really concerned how they manage to do it, just that it is done. It doesn't seem out of character for a godlike civilization to be able to move billions of solar masses worth of mass in the blink of an eye, given that they've mastered black holes.