Move true color sky drawing to its own drawers and chamge r_stretchsky to false as the new drawers can fade to a solid color
This commit is contained in:
parent
cfb985ceb3
commit
491a4e28c0
13 changed files with 482 additions and 17 deletions
127
src/r_compiler/fixedfunction/drawskycodegen.cpp
Normal file
127
src/r_compiler/fixedfunction/drawskycodegen.cpp
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
|
||||
#include "i_system.h"
|
||||
#include "r_compiler/llvm_include.h"
|
||||
#include "r_compiler/fixedfunction/drawskycodegen.h"
|
||||
#include "r_compiler/ssa/ssa_function.h"
|
||||
#include "r_compiler/ssa/ssa_scope.h"
|
||||
#include "r_compiler/ssa/ssa_for_block.h"
|
||||
#include "r_compiler/ssa/ssa_if_block.h"
|
||||
#include "r_compiler/ssa/ssa_stack.h"
|
||||
#include "r_compiler/ssa/ssa_function.h"
|
||||
#include "r_compiler/ssa/ssa_struct_type.h"
|
||||
#include "r_compiler/ssa/ssa_value.h"
|
||||
|
||||
void DrawSkyCodegen::Generate(DrawSkyVariant variant, bool fourColumns, SSAValue args, SSAValue thread_data)
|
||||
{
|
||||
dest = args[0][0].load(true);
|
||||
source0[0] = args[0][1].load(true);
|
||||
source0[1] = args[0][2].load(true);
|
||||
source0[2] = args[0][3].load(true);
|
||||
source0[3] = args[0][4].load(true);
|
||||
source1[0] = args[0][5].load(true);
|
||||
source1[1] = args[0][6].load(true);
|
||||
source1[2] = args[0][7].load(true);
|
||||
source1[3] = args[0][8].load(true);
|
||||
pitch = args[0][9].load(true);
|
||||
count = args[0][10].load(true);
|
||||
dest_y = args[0][11].load(true);
|
||||
texturefrac[0] = args[0][12].load(true);
|
||||
texturefrac[1] = args[0][13].load(true);
|
||||
texturefrac[2] = args[0][14].load(true);
|
||||
texturefrac[3] = args[0][15].load(true);
|
||||
iscale[0] = args[0][16].load(true);
|
||||
iscale[1] = args[0][17].load(true);
|
||||
iscale[2] = args[0][18].load(true);
|
||||
iscale[3] = args[0][19].load(true);
|
||||
textureheight0 = args[0][20].load(true);
|
||||
textureheight1 = args[0][21].load(true);
|
||||
top_color = SSAVec4i::unpack(args[0][22].load(true));
|
||||
bottom_color = SSAVec4i::unpack(args[0][23].load(true));
|
||||
|
||||
thread.core = thread_data[0][0].load(true);
|
||||
thread.num_cores = thread_data[0][1].load(true);
|
||||
thread.pass_start_y = thread_data[0][2].load(true);
|
||||
thread.pass_end_y = thread_data[0][3].load(true);
|
||||
|
||||
count = count_for_thread(dest_y, count, thread);
|
||||
dest = dest_for_thread(dest_y, pitch, dest, thread);
|
||||
|
||||
pitch = pitch * thread.num_cores;
|
||||
|
||||
int numColumns = fourColumns ? 4 : 1;
|
||||
for (int i = 0; i < numColumns; i++)
|
||||
{
|
||||
stack_frac[i].store(texturefrac[i] + iscale[i] * skipped_by_thread(dest_y, thread));
|
||||
fracstep[i] = iscale[i] * thread.num_cores;
|
||||
}
|
||||
|
||||
Loop(variant, fourColumns);
|
||||
}
|
||||
|
||||
void DrawSkyCodegen::Loop(DrawSkyVariant variant, bool fourColumns)
|
||||
{
|
||||
int numColumns = fourColumns ? 4 : 1;
|
||||
|
||||
stack_index.store(SSAInt(0));
|
||||
{
|
||||
SSAForBlock loop;
|
||||
SSAInt index = stack_index.load();
|
||||
loop.loop_block(index < count);
|
||||
|
||||
SSAInt frac[4];
|
||||
for (int i = 0; i < numColumns; i++)
|
||||
frac[i] = stack_frac[i].load();
|
||||
|
||||
SSAInt offset = index * pitch * 4;
|
||||
|
||||
if (fourColumns)
|
||||
{
|
||||
SSAVec4i colors[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
colors[i] = FadeOut(frac[i], Sample(frac[i], i, variant));
|
||||
|
||||
SSAVec16ub color(SSAVec8s(colors[0], colors[1]), SSAVec8s(colors[2], colors[3]));
|
||||
dest[offset].store_unaligned_vec16ub(color);
|
||||
}
|
||||
else
|
||||
{
|
||||
SSAVec4i color = FadeOut(frac[0], Sample(frac[0], 0, variant));
|
||||
dest[offset].store_vec4ub(color);
|
||||
}
|
||||
|
||||
stack_index.store(index.add(SSAInt(1), true, true));
|
||||
for (int i = 0; i < numColumns; i++)
|
||||
stack_frac[i].store(frac[i] + fracstep[i]);
|
||||
loop.end_block();
|
||||
}
|
||||
}
|
||||
|
||||
SSAVec4i DrawSkyCodegen::Sample(SSAInt frac, int index, DrawSkyVariant variant)
|
||||
{
|
||||
SSAInt sample_index = (((frac << 8) >> FRACBITS) * textureheight0) >> FRACBITS;
|
||||
if (variant == DrawSkyVariant::Single)
|
||||
{
|
||||
return source0[index][sample_index * 4].load_vec4ub(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
SSAInt sample_index2 = SSAInt::MIN(sample_index, textureheight1);
|
||||
SSAVec4i color0 = source0[index][sample_index * 4].load_vec4ub(false);
|
||||
SSAVec4i color1 = source1[index][sample_index2 * 4].load_vec4ub(false);
|
||||
return blend_alpha_blend(color0, color1);
|
||||
}
|
||||
}
|
||||
|
||||
SSAVec4i DrawSkyCodegen::FadeOut(SSAInt frac, SSAVec4i color)
|
||||
{
|
||||
int start_fade = 2; // How fast it should fade out
|
||||
|
||||
SSAInt alpha_top = SSAInt::MAX(SSAInt::MIN(frac.ashr(16 - start_fade), SSAInt(256)), SSAInt(0));
|
||||
SSAInt alpha_bottom = SSAInt::MAX(SSAInt::MIN(((2 << 24) - frac).ashr(16 - start_fade), SSAInt(256)), SSAInt(0));
|
||||
SSAInt inv_alpha_top = 256 - alpha_top;
|
||||
SSAInt inv_alpha_bottom = 256 - alpha_bottom;
|
||||
|
||||
color = (color * alpha_top + top_color * inv_alpha_top) / 256;
|
||||
color = (color * alpha_bottom + bottom_color * inv_alpha_bottom) / 256;
|
||||
return color.insert(3, 255);
|
||||
}
|
||||
39
src/r_compiler/fixedfunction/drawskycodegen.h
Normal file
39
src/r_compiler/fixedfunction/drawskycodegen.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "drawercodegen.h"
|
||||
|
||||
enum class DrawSkyVariant
|
||||
{
|
||||
Single,
|
||||
Double
|
||||
};
|
||||
|
||||
class DrawSkyCodegen : public DrawerCodegen
|
||||
{
|
||||
public:
|
||||
void Generate(DrawSkyVariant variant, bool fourColumns, SSAValue args, SSAValue thread_data);
|
||||
|
||||
private:
|
||||
void Loop(DrawSkyVariant variant, bool fourColumns);
|
||||
SSAVec4i Sample(SSAInt frac, int index, DrawSkyVariant variant);
|
||||
SSAVec4i FadeOut(SSAInt frac, SSAVec4i color);
|
||||
|
||||
SSAStack<SSAInt> stack_index, stack_frac[4];
|
||||
|
||||
SSAUBytePtr dest;
|
||||
SSAUBytePtr source0[4];
|
||||
SSAUBytePtr source1[4];
|
||||
SSAInt pitch;
|
||||
SSAInt count;
|
||||
SSAInt dest_y;
|
||||
SSAInt texturefrac[4];
|
||||
SSAInt iscale[4];
|
||||
SSAInt textureheight0;
|
||||
SSAInt textureheight1;
|
||||
SSAVec4i top_color;
|
||||
SSAVec4i bottom_color;
|
||||
SSAWorkerThread thread;
|
||||
|
||||
SSAInt fracstep[4];
|
||||
};
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include "r_compiler/fixedfunction/drawspancodegen.h"
|
||||
#include "r_compiler/fixedfunction/drawwallcodegen.h"
|
||||
#include "r_compiler/fixedfunction/drawcolumncodegen.h"
|
||||
#include "r_compiler/fixedfunction/drawskycodegen.h"
|
||||
#include "r_compiler/ssa/ssa_function.h"
|
||||
#include "r_compiler/ssa/ssa_scope.h"
|
||||
#include "r_compiler/ssa/ssa_for_block.h"
|
||||
|
|
@ -48,10 +49,12 @@ private:
|
|||
void CodegenDrawColumn(const char *name, DrawColumnVariant variant, DrawColumnMethod method);
|
||||
void CodegenDrawSpan(const char *name, DrawSpanVariant variant);
|
||||
void CodegenDrawWall(const char *name, DrawWallVariant variant, int columns);
|
||||
void CodegenDrawSky(const char *name, DrawSkyVariant variant, int columns);
|
||||
|
||||
static llvm::Type *GetDrawColumnArgsStruct(llvm::LLVMContext &context);
|
||||
static llvm::Type *GetDrawSpanArgsStruct(llvm::LLVMContext &context);
|
||||
static llvm::Type *GetDrawWallArgsStruct(llvm::LLVMContext &context);
|
||||
static llvm::Type *GetDrawSkyArgsStruct(llvm::LLVMContext &context);
|
||||
static llvm::Type *GetWorkerThreadDataStruct(llvm::LLVMContext &context);
|
||||
|
||||
LLVMProgram mProgram;
|
||||
|
|
@ -140,6 +143,10 @@ LLVMDrawersImpl::LLVMDrawersImpl()
|
|||
CodegenDrawWall("tmvline4_subclamp", DrawWallVariant::SubClamp, 4);
|
||||
CodegenDrawWall("tmvline1_revsubclamp", DrawWallVariant::RevSubClamp, 1);
|
||||
CodegenDrawWall("tmvline4_revsubclamp", DrawWallVariant::RevSubClamp, 4);
|
||||
CodegenDrawSky("DrawSky1", DrawSkyVariant::Single, 1);
|
||||
CodegenDrawSky("DrawSky4", DrawSkyVariant::Single, 4);
|
||||
CodegenDrawSky("DrawDoubleSky1", DrawSkyVariant::Double, 1);
|
||||
CodegenDrawSky("DrawDoubleSky4", DrawSkyVariant::Double, 4);
|
||||
|
||||
mProgram.CreateEE();
|
||||
|
||||
|
|
@ -201,6 +208,10 @@ LLVMDrawersImpl::LLVMDrawersImpl()
|
|||
tmvline4_subclamp = mProgram.GetProcAddress<void(const DrawWallArgs *, const WorkerThreadData *)>("tmvline4_subclamp");
|
||||
tmvline1_revsubclamp = mProgram.GetProcAddress<void(const DrawWallArgs *, const WorkerThreadData *)>("tmvline1_revsubclamp");
|
||||
tmvline4_revsubclamp = mProgram.GetProcAddress<void(const DrawWallArgs *, const WorkerThreadData *)>("tmvline4_revsubclamp");
|
||||
DrawSky1 = mProgram.GetProcAddress<void(const DrawSkyArgs *, const WorkerThreadData *)>("DrawSky1");
|
||||
DrawSky4 = mProgram.GetProcAddress<void(const DrawSkyArgs *, const WorkerThreadData *)>("DrawSky4");
|
||||
DrawDoubleSky1 = mProgram.GetProcAddress<void(const DrawSkyArgs *, const WorkerThreadData *)>("DrawDoubleSky1");
|
||||
DrawDoubleSky4 = mProgram.GetProcAddress<void(const DrawSkyArgs *, const WorkerThreadData *)>("DrawDoubleSky4");
|
||||
|
||||
#if 0
|
||||
std::vector<uint32_t> foo(1024 * 4);
|
||||
|
|
@ -292,6 +303,25 @@ void LLVMDrawersImpl::CodegenDrawWall(const char *name, DrawWallVariant variant,
|
|||
I_FatalError("verifyFunction failed for " __FUNCTION__);
|
||||
}
|
||||
|
||||
void LLVMDrawersImpl::CodegenDrawSky(const char *name, DrawSkyVariant variant, int columns)
|
||||
{
|
||||
llvm::IRBuilder<> builder(mProgram.context());
|
||||
SSAScope ssa_scope(&mProgram.context(), mProgram.module(), &builder);
|
||||
|
||||
SSAFunction function(name);
|
||||
function.add_parameter(GetDrawSkyArgsStruct(mProgram.context()));
|
||||
function.add_parameter(GetWorkerThreadDataStruct(mProgram.context()));
|
||||
function.create_public();
|
||||
|
||||
DrawSkyCodegen codegen;
|
||||
codegen.Generate(variant, columns == 4, function.parameter(0), function.parameter(1));
|
||||
|
||||
builder.CreateRetVoid();
|
||||
|
||||
if (llvm::verifyFunction(*function.func))
|
||||
I_FatalError("verifyFunction failed for " __FUNCTION__);
|
||||
}
|
||||
|
||||
llvm::Type *LLVMDrawersImpl::GetDrawColumnArgsStruct(llvm::LLVMContext &context)
|
||||
{
|
||||
std::vector<llvm::Type *> elements;
|
||||
|
|
@ -375,6 +405,17 @@ llvm::Type *LLVMDrawersImpl::GetDrawWallArgsStruct(llvm::LLVMContext &context)
|
|||
return llvm::StructType::create(context, elements, "DrawWallArgs", false)->getPointerTo();
|
||||
}
|
||||
|
||||
llvm::Type *LLVMDrawersImpl::GetDrawSkyArgsStruct(llvm::LLVMContext &context)
|
||||
{
|
||||
std::vector<llvm::Type *> elements;
|
||||
elements.push_back(llvm::Type::getInt8PtrTy(context));
|
||||
for (int i = 0; i < 8; i++)
|
||||
elements.push_back(llvm::Type::getInt8PtrTy(context));
|
||||
for (int i = 0; i < 15; i++)
|
||||
elements.push_back(llvm::Type::getInt32Ty(context));
|
||||
return llvm::StructType::create(context, elements, "DrawSkyArgs", false)->getPointerTo();
|
||||
}
|
||||
|
||||
llvm::Type *LLVMDrawersImpl::GetWorkerThreadDataStruct(llvm::LLVMContext &context)
|
||||
{
|
||||
std::vector<llvm::Type *> elements;
|
||||
|
|
|
|||
|
|
@ -133,6 +133,29 @@ struct DrawColumnArgs
|
|||
}
|
||||
};
|
||||
|
||||
struct DrawSkyArgs
|
||||
{
|
||||
uint32_t *dest;
|
||||
const uint32_t *source0[4];
|
||||
const uint32_t *source1[4];
|
||||
int32_t pitch;
|
||||
int32_t count;
|
||||
int32_t dest_y;
|
||||
uint32_t texturefrac[4];
|
||||
uint32_t iscale[4];
|
||||
uint32_t textureheight0;
|
||||
uint32_t textureheight1;
|
||||
uint32_t top_color;
|
||||
uint32_t bottom_color;
|
||||
|
||||
FString ToString()
|
||||
{
|
||||
FString info;
|
||||
info.Format("dest_y = %i, count = %i", dest_y, count);
|
||||
return info;
|
||||
}
|
||||
};
|
||||
|
||||
class LLVMDrawers
|
||||
{
|
||||
public:
|
||||
|
|
@ -203,6 +226,11 @@ public:
|
|||
void(*tmvline1_revsubclamp)(const DrawWallArgs *, const WorkerThreadData *) = nullptr;
|
||||
void(*tmvline4_revsubclamp)(const DrawWallArgs *, const WorkerThreadData *) = nullptr;
|
||||
|
||||
void(*DrawSky1)(const DrawSkyArgs *, const WorkerThreadData *) = nullptr;
|
||||
void(*DrawSky4)(const DrawSkyArgs *, const WorkerThreadData *) = nullptr;
|
||||
void(*DrawDoubleSky1)(const DrawSkyArgs *, const WorkerThreadData *) = nullptr;
|
||||
void(*DrawDoubleSky4)(const DrawSkyArgs *, const WorkerThreadData *) = nullptr;
|
||||
|
||||
private:
|
||||
static LLVMDrawers *Singleton;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -47,6 +47,11 @@ SSAInt SSAInt::add(SSAInt b, bool no_unsigned_wrap, bool no_signed_wrap)
|
|||
return SSAInt::from_llvm(SSAScope::builder().CreateAdd(v, b.v, SSAScope::hint(), no_unsigned_wrap, no_signed_wrap));
|
||||
}
|
||||
|
||||
SSAInt SSAInt::ashr(int bits)
|
||||
{
|
||||
return SSAInt::from_llvm(SSAScope::builder().CreateAShr(v, bits, SSAScope::hint()));
|
||||
}
|
||||
|
||||
SSAInt operator+(const SSAInt &a, const SSAInt &b)
|
||||
{
|
||||
return SSAInt::from_llvm(SSAScope::builder().CreateAdd(a.v, b.v, SSAScope::hint()));
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public:
|
|||
static SSAInt MAX(SSAInt a, SSAInt b);
|
||||
|
||||
SSAInt add(SSAInt b, bool no_unsigned_wrap, bool no_signed_wrap);
|
||||
SSAInt ashr(int bits);
|
||||
|
||||
llvm::Value *v;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -171,20 +171,6 @@ SSAVec4i SSAVec4i::sqrt(SSAVec4i f)
|
|||
return SSAVec4i::from_llvm(SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::x86_sse2_sqrt_pd), f.v, SSAScope::hint()));
|
||||
}
|
||||
|
||||
/*
|
||||
SSAVec4i SSAVec4i::min_sse41(SSAVec4i a, SSAVec4i b)
|
||||
{
|
||||
llvm::Value *values[2] = { a.v, b.v };
|
||||
return SSAVec4i::from_llvm(SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::x86_sse41_pminsd), values, SSAScope::hint()));
|
||||
}
|
||||
|
||||
SSAVec4i SSAVec4i::max_sse41(SSAVec4i a, SSAVec4i b)
|
||||
{
|
||||
llvm::Value *values[2] = { a.v, b.v };
|
||||
return SSAVec4i::from_llvm(SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::x86_sse41_pmaxsd), values, SSAScope::hint()));
|
||||
}
|
||||
*/
|
||||
|
||||
SSAVec4i operator+(const SSAVec4i &a, const SSAVec4i &b)
|
||||
{
|
||||
return SSAVec4i::from_llvm(SSAScope::builder().CreateAdd(a.v, b.v, SSAScope::hint()));
|
||||
|
|
|
|||
|
|
@ -35,8 +35,6 @@ public:
|
|||
static SSAVec4i combinehi(SSAVec8s v0, SSAVec8s v1);
|
||||
static SSAVec4i combinelo(SSAVec8s v0, SSAVec8s v1);
|
||||
static SSAVec4i sqrt(SSAVec4i f);
|
||||
//static SSAVec4i min_sse41(SSAVec4i a, SSAVec4i b);
|
||||
//static SSAVec4i max_sse41(SSAVec4i a, SSAVec4i b);
|
||||
static SSAVec4i from_llvm(llvm::Value *v) { return SSAVec4i(v); }
|
||||
static llvm::Type *llvm_type();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue