Reduce dynamic memory allocation in getting unif/varying variants of AtomicTypes
This commit is contained in:
17
type.cpp
17
type.cpp
@@ -186,6 +186,7 @@ const AtomicType *AtomicType::Void =
|
|||||||
AtomicType::AtomicType(BasicType bt, Variability v, bool ic)
|
AtomicType::AtomicType(BasicType bt, Variability v, bool ic)
|
||||||
: Type(ATOMIC_TYPE), basicType(bt), variability(v), isConst(ic) {
|
: Type(ATOMIC_TYPE), basicType(bt), variability(v), isConst(ic) {
|
||||||
asOtherConstType = NULL;
|
asOtherConstType = NULL;
|
||||||
|
asUniformType = asVaryingType = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -290,7 +291,13 @@ AtomicType::GetAsVaryingType() const {
|
|||||||
Assert(basicType != TYPE_VOID);
|
Assert(basicType != TYPE_VOID);
|
||||||
if (variability == Variability::Varying)
|
if (variability == Variability::Varying)
|
||||||
return this;
|
return this;
|
||||||
return new AtomicType(basicType, Variability::Varying, isConst);
|
|
||||||
|
if (asVaryingType == NULL) {
|
||||||
|
asVaryingType = new AtomicType(basicType, Variability::Varying, isConst);
|
||||||
|
if (variability == Variability::Uniform)
|
||||||
|
asVaryingType->asUniformType = this;
|
||||||
|
}
|
||||||
|
return asVaryingType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -299,7 +306,13 @@ AtomicType::GetAsUniformType() const {
|
|||||||
Assert(basicType != TYPE_VOID);
|
Assert(basicType != TYPE_VOID);
|
||||||
if (variability == Variability::Uniform)
|
if (variability == Variability::Uniform)
|
||||||
return this;
|
return this;
|
||||||
return new AtomicType(basicType, Variability::Uniform, isConst);
|
|
||||||
|
if (asUniformType == NULL) {
|
||||||
|
asUniformType = new AtomicType(basicType, Variability::Uniform, isConst);
|
||||||
|
if (variability == Variability::Varying)
|
||||||
|
asUniformType->asVaryingType = this;
|
||||||
|
}
|
||||||
|
return asUniformType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
type.h
2
type.h
@@ -333,7 +333,7 @@ private:
|
|||||||
const bool isConst;
|
const bool isConst;
|
||||||
AtomicType(BasicType basicType, Variability v, bool isConst);
|
AtomicType(BasicType basicType, Variability v, bool isConst);
|
||||||
|
|
||||||
mutable const AtomicType *asOtherConstType;
|
mutable const AtomicType *asOtherConstType, *asUniformType, *asVaryingType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user