Modify rules for default variability of pointed-to types.

Now, the pointed-to type is always uniform by default (if an explicit
rate qualifier isn't provided).  This rule is easier to remember and
seems to work well in more cases than the previous rule from 6d7ff7eba2.
This commit is contained in:
Matt Pharr
2012-02-29 14:21:03 -08:00
parent 2a1c7f2d47
commit 55b81e35a7
8 changed files with 31 additions and 35 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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];

View File

@@ -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;

View File

@@ -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);
}