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