Coder Social home page Coder Social logo

Comments (16)

realazthat avatar realazthat commented on August 22, 2024 4

As suggested in the original post, one horrible solution is to use GL_EXT_shader_image_load_formatted, then run your script through glslangValidator to convert it to SPV, then run spirv-opt with --inline-entry-points-exhaustive, which inlines everything. Then either load the SPV in vulkan or opengl (if implementation supports it) or, alternatively, use spirv-cross to convert it back to glsl, and then load it as normal. I've gotten most of such a pipeline working, though I can't say it will work for everyone or on all hardware. I also was simultaneously doing other horrible hacks, so take this all with a grain of salt until you try it and it works in all contexts.

from glsl.

graphitemaster avatar graphitemaster commented on August 22, 2024 4

Adding +1, it's been five years and it's still not possible to pass images around to functions.

from glsl.

StilesCrisis avatar StilesCrisis commented on August 22, 2024 3

Just adding my +1 here. This seems like a very serious functionality gap in the language.

from glsl.

DethRaid avatar DethRaid commented on August 22, 2024 2

Was a resolution reached for this? It's been four years and being able to pass a storage image to a function would make my code so much better

from glsl.

Raikiri avatar Raikiri commented on August 22, 2024 1

in vulkan 1.1.121.2 this code:

layout(binding = 0, r32f) uniform image2D testImage;
float Func(image2D image)
{
  return imageLoad(image, ivec2(0, 0)).r;
}
void main()
{
  float test = Func(testImage);
}

gives this error:

'format' : image formats must match

Why is it happening? Is there a workaround to pass image2D argument to a function?

from glsl.

realazthat avatar realazthat commented on August 22, 2024 1

Why is it happening? Is there a workaround to pass image2D argument to a function?

There is no way, it's mostly hardware limitation.

How is this sort of thing a hardware limitation, when - at least my understanding is - everything is basically inlined before being executed on the hardware, and if you manually inline this, it is valid?

from glsl.

spencerkohan avatar spencerkohan commented on August 22, 2024 1

Has there been any progress on this? I'm running into this exact issue today.

from glsl.

johnkslang avatar johnkslang commented on August 22, 2024

It seems like we should allow format qualifiers on function parameters, so that loads can be supported.

I think that's the right answer, and possibly to warn (or error) at the GLSL level if the argument type does not match the parameter type, including the format.

See KhronosGroup/glslang#1720 for a recent complaint about this.

from glsl.

ianromanick avatar ianromanick commented on August 22, 2024

We discussed on the call today that there was a very old bug (11466) about this issue. My recollection was that the driver was supposed to do whatever specialization of functions was necessary to make it work. Since most functions would be inlined, this would be trivial. It seems like the version of the shader with just g() should just work. SPIR-V makes things a bit more complicated.

from glsl.

NeilMonday avatar NeilMonday commented on August 22, 2024

On AMD, the example compute shader above compiles with no errors.

from glsl.

jeffbolznv avatar jeffbolznv commented on August 22, 2024

FWIW, the original issue was reported to me by an internal Vulkan developer. We should definitely answer the question for both GL and Vulkan, and as Ian says it is probably harder with SPIR-V.

from glsl.

pdaniell-nv avatar pdaniell-nv commented on August 22, 2024

Since we can't bugfix the current GLSL/ESSL specs for this, I think we need an extension so applications that want to use format qualifiers on function parameters know that it's supported by the implementation. If that makes sense we need a volunteer to create the extension.

from glsl.

johnkslang avatar johnkslang commented on August 22, 2024

Glslang is updated now to give an error if formats do not match between calling argument and formal parameter (unless the formal parameter is writeonly and at least one of caller/callee has an unknown format).

from glsl.

Raikiri avatar Raikiri commented on August 22, 2024

I saw a whole bunch of changes and discussions around this topic as it keeps popping up for the past 3 years whenever anybody attempts to pass a readwrite texture into a function. Is there any way (even a workaround) to do this as of today?

from glsl.

 avatar commented on August 22, 2024

I changed my mind about that question. I suppose that is language and/or compiler problem. At least, for Vulkan API, due SPIR-V. About OpenGL or OpenGL ES, I currently have no idea...

from glsl.

M-Gjerde avatar M-Gjerde commented on August 22, 2024

+1

from glsl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.