diff --git a/docs/ispc.rst b/docs/ispc.rst index 2dc59437..aba4104a 100644 --- a/docs/ispc.rst +++ b/docs/ispc.rst @@ -1507,9 +1507,8 @@ As with other basic types, pointers can be both ``uniform`` and ** Like other types in ``ispc``, pointers are ``varying`` by default, if an explicit ``uniform`` qualifier isn't provided. However, the default -variability of the pointed-to type (``uniform`` or ``varying``) is the -opposite of the pointer variability. ** This rule will be illustrated and -explained in examples below. +variability of the pointed-to type is uniform. ** This rule will be +illustrated and explained in examples below. For example, the ``ptr`` variable in the code below is a varying pointer to ``uniform float`` values. Each program instance has a separate pointer @@ -1529,7 +1528,7 @@ qualifier: :: float f = 0; - float * uniform pf = &f; // uniform pointer to a varying float + varying float * uniform pf = &f; // uniform pointer to a varying float *pf = 1; The placement of the ``uniform`` qualifier to declare a ``uniform`` pointer @@ -1546,7 +1545,7 @@ out with a separate location in memory for each program instance.) :: float a; - float * uniform pa = &a; + varying float * uniform pa = &a; *pa = programIndex; // same as (a = programIndex) Also as in C, arrays are silently converted into pointers: @@ -1554,8 +1553,8 @@ Also as in C, arrays are silently converted into pointers: :: float a[10] = { ... }; - float * uniform pa = a; // pointer to first element of a - float * uniform pb = a + 5; // pointer to 5th element of a + varying float * uniform pa = a; // pointer to first element of a + varying float * uniform pb = a + 5; // pointer to 5th element of a Any pointer type can be explicitly typecast to another pointer type, as long as the source type isn't a ``varying`` pointer when the destination diff --git a/expr.cpp b/expr.cpp index cdf4388c..a838ca1b 100644 --- a/expr.cpp +++ b/expr.cpp @@ -7432,11 +7432,8 @@ NewExpr::NewExpr(int typeQual, const Type *t, Expr *init, Expr *count, // varying new. isVarying = (typeQual == 0) || (typeQual & TYPEQUAL_VARYING); - if (allocType != NULL && allocType->HasUnboundVariability()) { - Type::Variability childVariability = isVarying ? - Type::Uniform : Type::Varying; - allocType = allocType->ResolveUnboundVariability(childVariability); - } + if (allocType != NULL && allocType->HasUnboundVariability()) + allocType = allocType->ResolveUnboundVariability(Type::Uniform); } diff --git a/stdlib.ispc b/stdlib.ispc index 82993e32..738e3a36 100644 --- a/stdlib.ispc +++ b/stdlib.ispc @@ -446,8 +446,8 @@ count_trailing_zeros(int64 v) { // AOS/SOA conversion static inline void -aos_to_soa3(uniform float a[], float * uniform v0, float * uniform v1, - float * uniform v2) { +aos_to_soa3(uniform float a[], varying float * uniform v0, + varying float * uniform v1, varying float * uniform v2) { __aos_to_soa3_float(a, v0, v1, v2); } @@ -457,8 +457,9 @@ soa_to_aos3(float v0, float v1, float v2, uniform float a[]) { } static inline void -aos_to_soa4(uniform float a[], float * uniform v0, float * uniform v1, - float * uniform v2, float * uniform v3) { +aos_to_soa4(uniform float a[], varying float * uniform v0, + varying float * uniform v1, varying float * uniform v2, + varying float * uniform v3) { __aos_to_soa4_float(a, v0, v1, v2, v3); } @@ -468,10 +469,10 @@ soa_to_aos4(float v0, float v1, float v2, float v3, uniform float a[]) { } static inline void -aos_to_soa3(uniform int32 a[], int32 * uniform v0, int32 * uniform v1, - int32 * uniform v2) { - aos_to_soa3((uniform float * uniform)a, (float * uniform)v0, - (float * uniform)v1, (float * uniform)v2); +aos_to_soa3(uniform int32 a[], varying int32 * uniform v0, + varying int32 * uniform v1, varying int32 * uniform v2) { + aos_to_soa3((uniform float * uniform)a, (varying float * uniform)v0, + (varying float * uniform)v1, (varying float * uniform)v2); } static inline void @@ -481,11 +482,12 @@ soa_to_aos3(int32 v0, int32 v1, int32 v2, uniform int32 a[]) { } static inline void -aos_to_soa4(uniform int32 a[], int32 * uniform v0, int32 * uniform v1, - int32 * uniform v2, int32 * uniform v3) { - aos_to_soa4((uniform float * uniform)a, (float * uniform )v0, - (float * uniform)v1, (float * uniform)v2, - (float * uniform)v3); +aos_to_soa4(uniform int32 a[], varying int32 * uniform v0, + varying int32 * uniform v1, varying int32 * uniform v2, + varying int32 * uniform v3) { + aos_to_soa4((uniform float * uniform)a, (varying float * uniform )v0, + (varying float * uniform)v1, (varying float * uniform)v2, + (varying float * uniform)v3); } static inline void @@ -765,7 +767,7 @@ static unsigned int64 exclusive_scan_or(unsigned int64 v) { static inline uniform int packed_load_active(uniform unsigned int a[], - unsigned int * uniform vals) { + varying unsigned int * uniform vals) { return __packed_load_active(a, vals, (UIntMaskType)__mask); } @@ -776,7 +778,7 @@ packed_store_active(uniform unsigned int a[], } static inline uniform int -packed_load_active(uniform int a[], int * uniform vals) { +packed_load_active(uniform int a[], varying int * uniform vals) { return __packed_load_active(a, vals, (IntMaskType)__mask); } diff --git a/tests/ptr-21.ispc b/tests/ptr-21.ispc index 6d162682..5abcf3ed 100644 --- a/tests/ptr-21.ispc +++ b/tests/ptr-21.ispc @@ -6,7 +6,7 @@ struct Foo { uniform float b; }; -void update(Foo * uniform fp) { +void update(varying Foo * uniform fp) { fp->a += 1; fp->b = 1; } diff --git a/tests/struct-nested-4.ispc b/tests/struct-nested-4.ispc index 5c2432f8..872a3296 100644 --- a/tests/struct-nested-4.ispc +++ b/tests/struct-nested-4.ispc @@ -17,7 +17,7 @@ void init(uniform Ray rays[], uniform int count, float v) { } } -void zero_dx(Ray * uniform r) { +void zero_dx(varying Ray * uniform r) { r->d.x = 0; } diff --git a/tests_errors/new-delete-6.ispc b/tests_errors/new-delete-6.ispc index 0462cbca..250441c2 100644 --- a/tests_errors/new-delete-6.ispc +++ b/tests_errors/new-delete-6.ispc @@ -1,4 +1,4 @@ -// Can't convert from type "uniform int32 * varying" to type "varying int32 * uniform" for return +// Can't convert from type "uniform int32 * varying" to type "uniform int32 * uniform" for return int * uniform func(int x) { return new int[x]; diff --git a/tests_errors/ptrcast-lose-info.ispc b/tests_errors/ptrcast-lose-info.ispc index eb564482..a8776206 100644 --- a/tests_errors/ptrcast-lose-info.ispc +++ b/tests_errors/ptrcast-lose-info.ispc @@ -1,4 +1,4 @@ -// Pointer type cast of type "varying int32 * uniform" to integer type "uniform int32" may lose information. +// Pointer type cast of type "uniform int32 * uniform" to integer type "uniform int32" may lose information. int32 foo(int * uniform x) { return (int32) x; diff --git a/type.cpp b/type.cpp index cabcc41b..cb863a01 100644 --- a/type.cpp +++ b/type.cpp @@ -986,10 +986,8 @@ PointerType::ResolveUnboundVariability(Variability v) const { Assert(v != Unbound); Variability ptrVariability = (variability == Unbound) ? v : variability; - Variability childVariability = (ptrVariability == Varying) ? - Uniform : Varying; - return new PointerType(baseType->ResolveUnboundVariability(childVariability), - ptrVariability, isConst); + const Type *resolvedBaseType = baseType->ResolveUnboundVariability(Uniform); + return new PointerType(resolvedBaseType, ptrVariability, isConst); }