Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix-float multiplication cross-compilation fails #103

Closed
nbentyNV opened this issue Jul 15, 2017 · 5 comments
Closed

Matrix-float multiplication cross-compilation fails #103

nbentyNV opened this issue Jul 15, 2017 · 5 comments

Comments

@nbentyNV
Copy link
Collaborator

float f;
mat4 a;
mat b = a*f; // This is legal in GLSL but fails compilation inside Slang

Looks like it's a Slang bug, since the GLSL compiler is never invoked.

We are using it for vertex-blending- ShaderCommon.slang::59 - getBlendedWorldMat

@tangent-vector-personal

Can you copy-paste in the error message you see?

My guess is that I'm just missing some overloads of operator*. I hope it isn't something more serious.

@tangent-vector-personal

One more note-to-self issue here is that I'm realizing there could be subtle problems if cross-compilation involves scalar-to-matrix conversion. float4x4(a) produces a matrix with 16 elements of a, while mat4(a) produces a diagonal matrix.

There is a similar issue where I need to make sure to translate HLSL operator* on matrices to the appropriate componentMul call.

@nbentyNV
Copy link
Collaborator Author

image

@tangent-vector
Copy link
Contributor

I think I misunderstood this error. The problem is not that we are giving an error on a matrix-scalar multiply in GLSL code, but rather that we are giving the error on Slang code that tries to do matrix-times-scalar.

It seems like this error shouldn't be specific to cross-compilation, then, and should occur for any Slang code that tries to do this.

@tangent-vector
Copy link
Contributor

Yep. I can repro this is a bare Slang file, so this is just a plain old screw-up on my part.

There are two reasonable ways to fix this:

  • Implement implicit promotion of scalars to matrices, after which the ordinary component-wise multiply will be taken
  • Implement explicit overloads of operator* (and probably others) for the matrix/scalar and scalar/matrix cases (and same for vector/scalar, ...)

It isn't clear to me which is the way that HLSL interprets this kind of things internally.

tangent-vector added a commit to tangent-vector/slang that referenced this issue Jul 17, 2017
Fixes shader-slang#103

- Previously I was relying on scalar-to-vector promotion to pick the right type in these cases, but I hadn't implemented scalar-to-matrix promotion (I should...)

- Rather than relying on promotion behavior, this change goes ahead and adds explicit overloads. I think this is probably a better decision in the long term, since one might want to support these cases for operators, while warning (or erroring) on the more general cases of implicit conversion.

- This covers matrix/scalar, scalar/matrix, vector/scalar, and scalar/vector cases
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

No branches or pull requests

3 participants