-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add boolN types #4
Comments
@redorav Is this feature still planned? I find myself frequently using HLSL's |
Hi @natevm let me respond in parts
The only reason boolN might be desirable is that it avoids an intermediate check for 0 so it would be slightly faster. However, the cost to pay is quite big in terms of implementation and I never really got to it and no one found it useful anyway. Hopefully that answers your question, if you have more questions let me know |
Really, I’m aiming for a framework where I can share slang code with the host. I agree that the direction HLSL went with this is frustrating… In slang, both && and || are legal, so I don’t actually use Would it be less work to implement some sort of typedef to have BoolN’s map to uintN’s? |
What does your code look like so I can get an idea of what you're looking to make work? A boolN is not like a uintN as far as I can tell, a boolN as far as I know only takes 2 values, 0 and 0xffffffff, and those are used as masks. HLSL++ treats floatN and uintN and "bools" when they return from a function like == or != in the sense that they get preemptively masked so they can be passed to other functions that require masks. In HLSL these implicit conversions have never been warnings so I'm not sure why Slang would be more pedantic about these. I have a feeling you'll have an easier time convincing Slang to be less strict about it. In any case let's see the code and discuss it |
floatN and uintN are not Boolean’s, but the binary comparison operators Iiuc, the motivation behind these intrinsics, beyond performance, are to give HLSL more well defined behavior for shortcircuiting. |
One of the motivating reasons for why folks use slang at the moment is the more strict type behavior. How strict the type safeness is becomes more of a subjective debate, and there is a compiler flag to disable the warnings, but personally I find that they help me avoid bugs. I’m not really willing to disable those warnings to adopt a library like this. |
I understand that you don't want to disable the warnings in Slang, and that's fine. However, consider that this is a library that takes HLSL as the model and not GLSL for example. There are compromises and things it cannot or are inconvenient to do. There are also concessions where it is simple to do so. Ultimately, the library may not work for you or you may want to fork it. I have been thinking about how to best implement boolN types. First off there are some requirements. Certain implicit conversions happen all the time. This works Simply adding a boolN type means that I now lose the swizzle functionality or I need to implement a full-on type to interact with the existing ones. I hesitate to add those because of compile times, but I also don't know how these interact with e.g. double types. Those would also need to interact with bools but now conversions with doubles become more difficult instead of staying in double land. In turn something like select() becomes more complicated because it needs to turn a boolN into a size that is compatible with the size of double. double4 result = select(boolVector, result1, result2) means that I need to turn boolVector into a mask somehow whereas the current implementation already works. None of these are huge problems, but I don't plan on doing this in the near term and I'd have to think it through properly. If you have a proposal and would like to suggest something I'm all ears |
No description provided.
The text was updated successfully, but these errors were encountered: