diff options
| author | Yong He <yonghe@outlook.com> | 2024-11-06 16:42:14 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-06 16:42:14 -0800 |
| commit | 989847f6a9408b68e90ac242f4a19d3266054c3e (patch) | |
| tree | 1cfeb1b12f0c6d1de2669936878cce0f4c542709 /source | |
| parent | d9cb281f5fd456d6a1df2e8e156810a86f56fc6e (diff) | |
Fix IntVal unification logic to insert type casts + buffer element lowering regression. (#5508)
* Fix IntVal unification logic to insert type casts.
* Fix regression.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/hlsl.meta.slang | 4 | ||||
| -rw-r--r-- | source/slang/slang-check-constraint.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-ir-lower-buffer-element-type.cpp | 3 | ||||
| -rw-r--r-- | source/slang/slang-ir-util.cpp | 11 | ||||
| -rw-r--r-- | source/slang/slang-ir-util.h | 2 |
5 files changed, 23 insertions, 3 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index b3a8ec4cf..e35dc1eee 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -4160,7 +4160,7 @@ struct StructuredBuffer /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE. __intrinsic_op($(kIROp_StructuredBufferLoad)) [__readNone] - [require(cpp_cuda_glsl_hlsl_spirv, structuredbuffer)] + [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, structuredbuffer)] T Load<TIndex : __BuiltinIntegerType>(TIndex location); __intrinsic_op($(kIROp_StructuredBufferLoadStatus)) @@ -5299,7 +5299,7 @@ for(auto item : kMutableStructuredBufferCases) { __generic<T, L:IBufferDataLayout=DefaultDataLayout> __magic_type(HLSL$(item.name)Type) __intrinsic_type($(item.op)) -[require(cpp_cuda_glsl_hlsl_metal_spirv, structuredbuffer_rw)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, structuredbuffer_rw)] /** Represents an opaque handle to a mutable structured buffer allocated in global memory. A structured buffer can be viewed as an array of the specified element type. diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp index 13e3e4be6..872d2616c 100644 --- a/source/slang/slang-check-constraint.cpp +++ b/source/slang/slang-check-constraint.cpp @@ -925,6 +925,12 @@ bool SemanticsVisitor::TryUnifyIntParam( // We want to constrain the given parameter to equal the given value. Constraint constraint; constraint.decl = paramDecl; + // If `val` is of different type than `paramDecl`, we want to insert a type cast. + if (val->getType() != paramDecl->getType()) + { + auto cast = m_astBuilder->getTypeCastIntVal(paramDecl->getType(), val); + val = cast; + } constraint.val = val; constraints.constraints.add(constraint); diff --git a/source/slang/slang-ir-lower-buffer-element-type.cpp b/source/slang/slang-ir-lower-buffer-element-type.cpp index f9017ebe1..2f8631e18 100644 --- a/source/slang/slang-ir-lower-buffer-element-type.cpp +++ b/source/slang/slang-ir-lower-buffer-element-type.cpp @@ -999,7 +999,8 @@ struct LoweredElementTypeContext // the base array. // We should setup loweredElementTypeInfo so the remaining logic can handle // this case and insert proper packing/unpacking logic around it. - if (arrayType->getElementType() != originalElementType) + if (arrayType->getElementType() != originalElementType && + isScalarOrVectorType(originalElementType)) { loweredElementTypeInfo.loweredType = arrayType->getElementType(); loweredElementTypeInfo.originalType = (IRType*)originalElementType; diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index c7b40da8b..3d2a539a6 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -221,6 +221,17 @@ bool isValueType(IRInst* dataType) } } +bool isScalarOrVectorType(IRInst* type) +{ + switch (type->getOp()) + { + case kIROp_VectorType: + return true; + default: + return as<IRBasicType>(type) != nullptr; + } +} + bool isSimpleDataType(IRType* type) { type = (IRType*)unwrapAttributedType(type); diff --git a/source/slang/slang-ir-util.h b/source/slang/slang-ir-util.h index b483d950c..9a712ba96 100644 --- a/source/slang/slang-ir-util.h +++ b/source/slang/slang-ir-util.h @@ -98,6 +98,8 @@ inline bool isScalarIntegerType(IRType* type) // No side effect can take place through a value of a "Value" type. bool isValueType(IRInst* type); +bool isScalarOrVectorType(IRInst* type); + bool isSimpleDataType(IRType* type); bool isSimpleHLSLDataType(IRInst* inst); |
