Fix bugs with exported varyings.
This commit is contained in:
33
module.cpp
33
module.cpp
@@ -1156,11 +1156,11 @@ lContainsPtrToVarying(const StructType *st) {
|
||||
*/
|
||||
static void
|
||||
lEmitStructDecl(const StructType *st, std::vector<const StructType *> *emittedStructs,
|
||||
FILE *file, bool printGenericHeader=false, bool emitUnifs=true) {
|
||||
FILE *file, bool emitUnifs=true) {
|
||||
|
||||
// if we're emitting this for a generic dispatch header file and it's
|
||||
// struct that only contains uniforms, don't bother if we're emitting uniforms
|
||||
if (printGenericHeader && !emitUnifs && !lContainsPtrToVarying(st)) {
|
||||
if (!emitUnifs && !lContainsPtrToVarying(st)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1176,33 +1176,20 @@ lEmitStructDecl(const StructType *st, std::vector<const StructType *> *emittedSt
|
||||
const StructType *elementStructType =
|
||||
lGetElementStructType(st->GetElementType(i));
|
||||
if (elementStructType != NULL)
|
||||
lEmitStructDecl(elementStructType, emittedStructs, file, printGenericHeader, emitUnifs);
|
||||
lEmitStructDecl(elementStructType, emittedStructs, file, emitUnifs);
|
||||
}
|
||||
|
||||
// And now it's safe to declare this one
|
||||
emittedStructs->push_back(st);
|
||||
|
||||
|
||||
if (printGenericHeader && lContainsPtrToVarying(st)) {
|
||||
fprintf(file, "#ifndef __ISPC_STRUCT_%s%d__\n",
|
||||
st->GetStructName().c_str(),
|
||||
g->target->getVectorWidth());
|
||||
fprintf(file, "#define __ISPC_STRUCT_%s%d__\n",
|
||||
st->GetStructName().c_str(),
|
||||
g->target->getVectorWidth());
|
||||
}
|
||||
else {
|
||||
fprintf(file, "#ifndef __ISPC_STRUCT_%s__\n",st->GetStructName().c_str());
|
||||
fprintf(file, "#define __ISPC_STRUCT_%s__\n",st->GetStructName().c_str());
|
||||
}
|
||||
fprintf(file, "struct %s", st->GetStructName().c_str());
|
||||
fprintf(file, "#ifndef __ISPC_STRUCT_%s__\n",st->GetCStructName().c_str());
|
||||
fprintf(file, "#define __ISPC_STRUCT_%s__\n",st->GetCStructName().c_str());
|
||||
|
||||
fprintf(file, "struct %s", st->GetCStructName().c_str());
|
||||
if (st->GetSOAWidth() > 0)
|
||||
// This has to match the naming scheme in
|
||||
// StructType::GetCDeclaration().
|
||||
fprintf(file, "_SOA%d", st->GetSOAWidth());
|
||||
if (printGenericHeader && lContainsPtrToVarying(st)) {
|
||||
fprintf(file, "%d", g->target->getVectorWidth());
|
||||
}
|
||||
fprintf(file, " {\n");
|
||||
|
||||
for (int i = 0; i < st->GetElementCount(); ++i) {
|
||||
@@ -1219,10 +1206,10 @@ lEmitStructDecl(const StructType *st, std::vector<const StructType *> *emittedSt
|
||||
header file, emit their declarations.
|
||||
*/
|
||||
static void
|
||||
lEmitStructDecls(std::vector<const StructType *> &structTypes, FILE *file, bool printGenericHeader=false, bool emitUnifs=true) {
|
||||
lEmitStructDecls(std::vector<const StructType *> &structTypes, FILE *file, bool emitUnifs=true) {
|
||||
std::vector<const StructType *> emittedStructs;
|
||||
for (unsigned int i = 0; i < structTypes.size(); ++i)
|
||||
lEmitStructDecl(structTypes[i], &emittedStructs, file, printGenericHeader, emitUnifs);
|
||||
lEmitStructDecl(structTypes[i], &emittedStructs, file, emitUnifs);
|
||||
}
|
||||
|
||||
|
||||
@@ -1938,7 +1925,7 @@ Module::writeDispatchHeader(DispatchHeaderInfo *DHI) {
|
||||
lEmitVectorTypedefs(exportedVectorTypes, f);
|
||||
lEmitEnumDecls(exportedEnumTypes, f);
|
||||
}
|
||||
lEmitStructDecls(exportedStructTypes, f, true, DHI->EmitUnifs);
|
||||
lEmitStructDecls(exportedStructTypes, f, DHI->EmitUnifs);
|
||||
|
||||
// Update flags
|
||||
DHI->EmitUnifs = false;
|
||||
|
||||
35
type.cpp
35
type.cpp
@@ -456,15 +456,9 @@ AtomicType::GetCDeclaration(const std::string &name) const {
|
||||
ret += name;
|
||||
}
|
||||
|
||||
if (variability == Variability::Varying ||
|
||||
variability == Variability::SOA) {
|
||||
if (variability == Variability::SOA) {
|
||||
char buf[32];
|
||||
// get program count
|
||||
// g->mangleFunctionsNamesWithTarget - hack check for void *
|
||||
int vWidth = (variability == Variability::Varying) ?
|
||||
g->target->getVectorWidth() :
|
||||
variability.soaWidth;
|
||||
sprintf(buf, "[%d]", vWidth);
|
||||
sprintf(buf, "[%d]", variability.soaWidth);
|
||||
ret += buf;
|
||||
}
|
||||
|
||||
@@ -1096,20 +1090,27 @@ PointerType::GetCDeclaration(const std::string &name) const {
|
||||
}
|
||||
|
||||
std::string ret = baseType->GetCDeclaration("");
|
||||
|
||||
bool baseIsBasicVarying = (IsBasicType(baseType)) && (baseType->IsVaryingType());
|
||||
|
||||
if (baseIsBasicVarying) ret += std::string("(");
|
||||
ret += std::string(" *");
|
||||
if (isConst) ret += " const";
|
||||
ret += std::string(" ");
|
||||
ret += name;
|
||||
if (baseIsBasicVarying) ret += std::string(")");
|
||||
|
||||
if (variability == Variability::SOA ||
|
||||
variability == Variability::Varying) {
|
||||
int vWidth = (variability == Variability::Varying) ?
|
||||
g->target->getVectorWidth() :
|
||||
variability.soaWidth;
|
||||
if (variability == Variability::SOA) {
|
||||
char buf[32];
|
||||
sprintf(buf, "[%d]", vWidth);
|
||||
sprintf(buf, "[%d]", variability.soaWidth);
|
||||
ret += buf;
|
||||
}
|
||||
if (baseIsBasicVarying) {
|
||||
int vWidth = g->target->getVectorWidth();
|
||||
char buf[32];
|
||||
sprintf(buf, "[%d]", vWidth);
|
||||
ret += buf;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1890,6 +1891,10 @@ StructType::StructType(const std::string &n, const llvm::SmallVector<const Type
|
||||
}
|
||||
}
|
||||
|
||||
const std::string
|
||||
StructType::GetCStructName() const {
|
||||
return lMangleStructName(name, variability);
|
||||
}
|
||||
|
||||
Variability
|
||||
StructType::GetVariability() const {
|
||||
@@ -2078,7 +2083,7 @@ std::string
|
||||
StructType::GetCDeclaration(const std::string &n) const {
|
||||
std::string ret;
|
||||
if (isConst) ret += "const ";
|
||||
ret += std::string("struct ") + name;
|
||||
ret += std::string("struct ") + GetCStructName();
|
||||
if (lShouldPrintName(n)) {
|
||||
ret += std::string(" ") + n;
|
||||
|
||||
|
||||
3
type.h
3
type.h
@@ -714,7 +714,8 @@ public:
|
||||
const SourcePos &GetElementPosition(int i) const { return elementPositions[i]; }
|
||||
|
||||
/** Returns the name of the structure type. (e.g. struct Foo -> "Foo".) */
|
||||
const std::string &GetStructName() const { return name; }
|
||||
const std::string &GetStructName() const { return name; }
|
||||
const std::string GetCStructName() const;
|
||||
|
||||
private:
|
||||
static bool checkIfCanBeSOA(const StructType *st);
|
||||
|
||||
Reference in New Issue
Block a user