Declare structs to LLVM

This commit is contained in:
Magnus Norddahl 2016-11-11 20:12:09 +01:00
parent 0938420871
commit 667f35bfce
4 changed files with 91 additions and 26 deletions

View file

@ -87,6 +87,10 @@ private:
static llvm::Type *GetDrawWallArgsStruct(llvm::LLVMContext &context); static llvm::Type *GetDrawWallArgsStruct(llvm::LLVMContext &context);
static llvm::Type *GetDrawSkyArgsStruct(llvm::LLVMContext &context); static llvm::Type *GetDrawSkyArgsStruct(llvm::LLVMContext &context);
static llvm::Type *GetWorkerThreadDataStruct(llvm::LLVMContext &context); static llvm::Type *GetWorkerThreadDataStruct(llvm::LLVMContext &context);
static llvm::Type *GetTriVertexStruct(llvm::LLVMContext &context);
static llvm::Type *GetTriMatrixStruct(llvm::LLVMContext &context);
static llvm::Type *GetTriUniformsStruct(llvm::LLVMContext &context);
static llvm::Type *GetTriDrawTriangleArgs(llvm::LLVMContext &context);
LLVMProgram mProgram; LLVMProgram mProgram;
}; };
@ -461,6 +465,67 @@ llvm::Type *LLVMDrawersImpl::GetWorkerThreadDataStruct(llvm::LLVMContext &contex
return llvm::StructType::create(context, elements, "ThreadData", false)->getPointerTo(); return llvm::StructType::create(context, elements, "ThreadData", false)->getPointerTo();
} }
llvm::Type *LLVMDrawersImpl::GetTriVertexStruct(llvm::LLVMContext &context)
{
std::vector<llvm::Type *> elements;
for (int i = 0; i < 6; i++)
elements.push_back(llvm::Type::getFloatTy(context));
return llvm::StructType::create(context, elements, "TriVertex", false)->getPointerTo();
}
llvm::Type *LLVMDrawersImpl::GetTriMatrixStruct(llvm::LLVMContext &context)
{
std::vector<llvm::Type *> elements;
for (int i = 0; i < 4 * 4; i++)
elements.push_back(llvm::Type::getFloatTy(context));
return llvm::StructType::create(context, elements, "TriMatrix", false)->getPointerTo();
}
llvm::Type *LLVMDrawersImpl::GetTriUniformsStruct(llvm::LLVMContext &context)
{
std::vector<llvm::Type *> elements;
elements.push_back(llvm::Type::getInt32Ty(context)); // uint32_t light;
elements.push_back(llvm::Type::getInt32Ty(context)); // uint32_t subsectorDepth;
elements.push_back(llvm::Type::getInt16Ty(context)); // uint16_t light_alpha;
elements.push_back(llvm::Type::getInt16Ty(context)); // uint16_t light_red;
elements.push_back(llvm::Type::getInt16Ty(context)); // uint16_t light_green;
elements.push_back(llvm::Type::getInt16Ty(context)); // uint16_t light_blue;
elements.push_back(llvm::Type::getInt16Ty(context)); // uint16_t fade_alpha;
elements.push_back(llvm::Type::getInt16Ty(context)); // uint16_t fade_red;
elements.push_back(llvm::Type::getInt16Ty(context)); // uint16_t fade_green;
elements.push_back(llvm::Type::getInt16Ty(context)); // uint16_t fade_blue;
elements.push_back(llvm::Type::getInt16Ty(context)); // uint16_t desaturate;
elements.push_back(llvm::Type::getInt32Ty(context)); // uint32_t flags;
elements.push_back(GetTriMatrixStruct(context)); // TriMatrix objectToClip
return llvm::StructType::create(context, elements, "TriUniforms", false)->getPointerTo();
}
llvm::Type *LLVMDrawersImpl::GetTriDrawTriangleArgs(llvm::LLVMContext &context)
{
std::vector<llvm::Type *> elements;
elements.push_back(llvm::Type::getInt8PtrTy(context)); // uint8_t *dest;
elements.push_back(llvm::Type::getInt32Ty(context)); // int32_t pitch;
elements.push_back(GetTriVertexStruct(context)->getPointerTo()); // TriVertex *v1;
elements.push_back(GetTriVertexStruct(context)->getPointerTo()); // TriVertex *v2;
elements.push_back(GetTriVertexStruct(context)->getPointerTo()); // TriVertex *v3;
elements.push_back(llvm::Type::getInt32Ty(context)); // int32_t clipleft;
elements.push_back(llvm::Type::getInt32Ty(context)); // int32_t clipright;
elements.push_back(llvm::Type::getInt32Ty(context)); // int32_t cliptop;
elements.push_back(llvm::Type::getInt32Ty(context)); // int32_t clipbottom;
elements.push_back(llvm::Type::getInt8PtrTy(context)); // const uint8_t *texturePixels;
elements.push_back(llvm::Type::getInt32Ty(context)); // uint32_t textureWidth;
elements.push_back(llvm::Type::getInt32Ty(context)); // uint32_t textureHeight;
elements.push_back(llvm::Type::getInt32Ty(context)); // uint32_t solidcolor;
elements.push_back(GetTriUniformsStruct(context)->getPointerTo()); // const TriUniforms *uniforms;
elements.push_back(llvm::Type::getInt8PtrTy(context)); // uint8_t *stencilValues;
elements.push_back(llvm::Type::getInt32PtrTy(context)); // uint32_t *stencilMasks;
elements.push_back(llvm::Type::getInt32Ty(context)); // int32_t stencilPitch;
elements.push_back(llvm::Type::getInt8Ty(context)); // uint8_t stencilTestValue;
elements.push_back(llvm::Type::getInt8Ty(context)); // uint8_t stencilWriteValue;
elements.push_back(llvm::Type::getInt32PtrTy(context)); // uint32_t *subsectorGBuffer;
return llvm::StructType::create(context, elements, "TriDrawTriangle", false)->getPointerTo();
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
namespace { static bool LogFatalErrors = false; } namespace { static bool LogFatalErrors = false; }

View file

@ -236,25 +236,25 @@ struct TriUniforms
TriMatrix objectToClip; TriMatrix objectToClip;
}; };
struct ScreenPolyTriangleDrawerArgs struct TriDrawTriangleArgs
{ {
uint8_t *dest; uint8_t *dest;
int pitch; int32_t pitch;
TriVertex *v1; TriVertex *v1;
TriVertex *v2; TriVertex *v2;
TriVertex *v3; TriVertex *v3;
int clipleft; int32_t clipleft;
int clipright; int32_t clipright;
int cliptop; int32_t cliptop;
int clipbottom; int32_t clipbottom;
const uint8_t *texturePixels; const uint8_t *texturePixels;
int textureWidth; uint32_t textureWidth;
int textureHeight; uint32_t textureHeight;
uint32_t solidcolor; uint32_t solidcolor;
const TriUniforms *uniforms; const TriUniforms *uniforms;
uint8_t *stencilValues; uint8_t *stencilValues;
uint32_t *stencilMasks; uint32_t *stencilMasks;
int stencilPitch; int32_t stencilPitch;
uint8_t stencilTestValue; uint8_t stencilTestValue;
uint8_t stencilWriteValue; uint8_t stencilWriteValue;
uint32_t *subsectorGBuffer; uint32_t *subsectorGBuffer;

View file

@ -53,7 +53,7 @@ void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, PolyDrawVaria
if (drawargs.vcount < 3) if (drawargs.vcount < 3)
return; return;
void(*drawfunc)(const ScreenPolyTriangleDrawerArgs *, WorkerThreadData *); void(*drawfunc)(const TriDrawTriangleArgs *, WorkerThreadData *);
switch (variant) switch (variant)
{ {
default: default:
@ -63,7 +63,7 @@ void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, PolyDrawVaria
case PolyDrawVariant::Stencil: drawfunc = ScreenPolyTriangleDrawer::stencil; break; case PolyDrawVariant::Stencil: drawfunc = ScreenPolyTriangleDrawer::stencil; break;
} }
ScreenPolyTriangleDrawerArgs args; TriDrawTriangleArgs args;
args.dest = dc_destorg; args.dest = dc_destorg;
args.pitch = dc_pitch; args.pitch = dc_pitch;
args.clipleft = drawargs.clipleft; args.clipleft = drawargs.clipleft;
@ -128,7 +128,7 @@ TriVertex PolyTriangleDrawer::shade_vertex(const TriUniforms &uniforms, TriVerte
return uniforms.objectToClip * v; return uniforms.objectToClip * v;
} }
void PolyTriangleDrawer::draw_shaded_triangle(const TriVertex *vert, bool ccw, ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread, void(*drawfunc)(const ScreenPolyTriangleDrawerArgs *, WorkerThreadData *)) void PolyTriangleDrawer::draw_shaded_triangle(const TriVertex *vert, bool ccw, TriDrawTriangleArgs *args, WorkerThreadData *thread, void(*drawfunc)(const TriDrawTriangleArgs *, WorkerThreadData *))
{ {
// Cull, clip and generate additional vertices as needed // Cull, clip and generate additional vertices as needed
TriVertex clippedvert[max_additional_vertices]; TriVertex clippedvert[max_additional_vertices];
@ -288,7 +288,7 @@ void PolyTriangleDrawer::clipedge(const TriVertex *verts, TriVertex *clippedvert
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
void ScreenPolyTriangleDrawer::draw(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread) void ScreenPolyTriangleDrawer::draw(const TriDrawTriangleArgs *args, WorkerThreadData *thread)
{ {
uint8_t *dest = args->dest; uint8_t *dest = args->dest;
int pitch = args->pitch; int pitch = args->pitch;
@ -523,7 +523,7 @@ void ScreenPolyTriangleDrawer::draw(const ScreenPolyTriangleDrawerArgs *args, Wo
} }
} }
void ScreenPolyTriangleDrawer::fill(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread) void ScreenPolyTriangleDrawer::fill(const TriDrawTriangleArgs *args, WorkerThreadData *thread)
{ {
uint8_t *dest = args->dest; uint8_t *dest = args->dest;
int pitch = args->pitch; int pitch = args->pitch;
@ -681,7 +681,7 @@ void ScreenPolyTriangleDrawer::fill(const ScreenPolyTriangleDrawerArgs *args, Wo
} }
} }
void ScreenPolyTriangleDrawer::stencil(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread) void ScreenPolyTriangleDrawer::stencil(const TriDrawTriangleArgs *args, WorkerThreadData *thread)
{ {
const TriVertex &v1 = *args->v1; const TriVertex &v1 = *args->v1;
const TriVertex &v2 = *args->v2; const TriVertex &v2 = *args->v2;
@ -833,7 +833,7 @@ void ScreenPolyTriangleDrawer::stencil(const ScreenPolyTriangleDrawerArgs *args,
} }
} }
void ScreenPolyTriangleDrawer::draw32(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread) void ScreenPolyTriangleDrawer::draw32(const TriDrawTriangleArgs *args, WorkerThreadData *thread)
{ {
uint32_t *dest = (uint32_t *)args->dest; uint32_t *dest = (uint32_t *)args->dest;
int pitch = args->pitch; int pitch = args->pitch;
@ -1145,7 +1145,7 @@ void ScreenPolyTriangleDrawer::draw32(const ScreenPolyTriangleDrawerArgs *args,
} }
} }
void ScreenPolyTriangleDrawer::drawsubsector32(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread) void ScreenPolyTriangleDrawer::drawsubsector32(const TriDrawTriangleArgs *args, WorkerThreadData *thread)
{ {
uint32_t *dest = (uint32_t *)args->dest; uint32_t *dest = (uint32_t *)args->dest;
int pitch = args->pitch; int pitch = args->pitch;
@ -1412,7 +1412,7 @@ void ScreenPolyTriangleDrawer::drawsubsector32(const ScreenPolyTriangleDrawerArg
} }
} }
void ScreenPolyTriangleDrawer::fill32(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread) void ScreenPolyTriangleDrawer::fill32(const TriDrawTriangleArgs *args, WorkerThreadData *thread)
{ {
uint32_t *dest = (uint32_t *)args->dest; uint32_t *dest = (uint32_t *)args->dest;
int pitch = args->pitch; int pitch = args->pitch;

View file

@ -26,7 +26,7 @@
#include "r_triangle.h" #include "r_triangle.h"
struct ScreenPolyTriangleDrawerArgs; struct TriDrawTriangleArgs;
enum class PolyDrawVariant enum class PolyDrawVariant
{ {
@ -74,7 +74,7 @@ public:
private: private:
static TriVertex shade_vertex(const TriUniforms &uniforms, TriVertex v); static TriVertex shade_vertex(const TriUniforms &uniforms, TriVertex v);
static void draw_arrays(const PolyDrawArgs &args, PolyDrawVariant variant, WorkerThreadData *thread); static void draw_arrays(const PolyDrawArgs &args, PolyDrawVariant variant, WorkerThreadData *thread);
static void draw_shaded_triangle(const TriVertex *vertices, bool ccw, ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread, void(*drawfunc)(const ScreenPolyTriangleDrawerArgs *, WorkerThreadData *)); static void draw_shaded_triangle(const TriVertex *vertices, bool ccw, TriDrawTriangleArgs *args, WorkerThreadData *thread, void(*drawfunc)(const TriDrawTriangleArgs *, WorkerThreadData *));
static bool cullhalfspace(float clipdistance1, float clipdistance2, float &t1, float &t2); static bool cullhalfspace(float clipdistance1, float clipdistance2, float &t1, float &t2);
static void clipedge(const TriVertex *verts, TriVertex *clippedvert, int &numclipvert); static void clipedge(const TriVertex *verts, TriVertex *clippedvert, int &numclipvert);
@ -228,14 +228,14 @@ private:
class ScreenPolyTriangleDrawer class ScreenPolyTriangleDrawer
{ {
public: public:
static void draw(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread); static void draw(const TriDrawTriangleArgs *args, WorkerThreadData *thread);
static void fill(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread); static void fill(const TriDrawTriangleArgs *args, WorkerThreadData *thread);
static void stencil(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread); static void stencil(const TriDrawTriangleArgs *args, WorkerThreadData *thread);
static void draw32(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread); static void draw32(const TriDrawTriangleArgs *args, WorkerThreadData *thread);
static void drawsubsector32(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread); static void drawsubsector32(const TriDrawTriangleArgs *args, WorkerThreadData *thread);
static void fill32(const ScreenPolyTriangleDrawerArgs *args, WorkerThreadData *thread); static void fill32(const TriDrawTriangleArgs *args, WorkerThreadData *thread);
private: private:
static float gradx(float x0, float y0, float x1, float y1, float x2, float y2, float c0, float c1, float c2); static float gradx(float x0, float y0, float x1, float y1, float x2, float y2, float c0, float c1, float c2);