slang icon indicating copy to clipboard operation
slang copied to clipboard

Implementation of SamplerTexture2D is incomplete

Open GlaireDaggers opened this issue 4 years ago • 5 comments

My engine relies on combined texture samplers in Vulkan to do texturing, but the implementation in Slang appears to be missing some functionality - mainly, attempting to sample from a SamplerTexture2D using the texture function gives the following error:

core.meta.slang(689): internal error 99999: unimplemented feature in Slang compiler: unexpected IR opcode during code emit

GlaireDaggers avatar Jun 22 '21 17:06 GlaireDaggers

Thanks for posting this as its own issue. I can probably try to tackle this, but I'm wondering what kind of timeline you have on when you'd need the implementation for this to be useful.

tangent-vector avatar Jun 22 '21 18:06 tangent-vector

I'm not in any particular hurry for what it's worth, since right now this is just for my own projects, but it is a blocker for remaining work on the rendering pipeline in the engine.

GlaireDaggers avatar Jun 22 '21 19:06 GlaireDaggers

I'm starting to work on this and have made some positive steps toward getting things fixed in my branch. When this stuff lands the names and signatures are likely to be different than what you are working with right now, so I will try to document stuff in this issue when that time comes.

tangent-vector avatar Jun 23 '21 21:06 tangent-vector

PR #1894 should fix up a lot of the compiler's behavior around these combined types, and those fixes should be available in the v0.19.0 and later releases. However, the change completely overhauls how combined texture/sampler type are written in input code.

Now, given an existing HLSL texture type like Texture2D the equivalent combined texture/sampler type has a name with Sampler in place of Texture. So the equivalent of Texture2D is the combined texture/sampler type Sampler2D.

Similarly, for any operations on a given Texture* type, the equivalent Sampler* type should have the same operations, just with any SamplerState parameter removed.

So if you would write the following with separate textures and samplers:

Texture2D t;
SamplerState s;

float4 test(float2 uv) { return t.Sample(s, uv); }

you would instead write the following to use the new combined types:

Sampler2D s;

float4 test(float2 uv) { return s.Sample(uv); }

Hopefully this large change doesn't cause too much disruption for your codebase @GlaireDaggers. Please feel free to let me know of any issues you run into with the newly re-enabled functionality. It is entirely possible that I've missed some important cases.

tangent-vector avatar Jun 25 '21 23:06 tangent-vector

Ah, sorry I've been silent for a bit. Been on vacation, just got back last night. Will take a look at this hopefully later tonight or tomorrow! Thanks for looking into it :)

GlaireDaggers avatar Jul 06 '21 16:07 GlaireDaggers