Commit a29d653e by Nicolas Capens

Deprecate support for constant pointers.

The use of constant pointers produces code that cannot be relocated. They also cause issues in Subzero when offsetting them due to not having constant folding support. We only used them for Direct3D cursor rendering, which can just pass in the data as an argument instead. Bug swiftshader:14 Change-Id: Id7f16c3fcaeed3fe64b569af6a49c32f6baec483 Reviewed-on: https://swiftshader-review.googlesource.com/8257Reviewed-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 47eca450
...@@ -34,15 +34,7 @@ namespace sw ...@@ -34,15 +34,7 @@ namespace sw
{ {
extern bool forceWindowed; extern bool forceWindowed;
void *FrameBuffer::cursor; FrameBuffer::Cursor FrameBuffer::cursor = {0};
int FrameBuffer::cursorWidth = 0;
int FrameBuffer::cursorHeight = 0;
int FrameBuffer::cursorHotspotX;
int FrameBuffer::cursorHotspotY;
int FrameBuffer::cursorPositionX;
int FrameBuffer::cursorPositionY;
int FrameBuffer::cursorX;
int FrameBuffer::cursorY;
bool FrameBuffer::topLeftOrigin = false; bool FrameBuffer::topLeftOrigin = false;
FrameBuffer::FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin) FrameBuffer::FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin)
...@@ -114,29 +106,29 @@ namespace sw ...@@ -114,29 +106,29 @@ namespace sw
{ {
if(cursorImage) if(cursorImage)
{ {
cursor = cursorImage->lockExternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); cursor.image = cursorImage->lockExternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC);
cursorImage->unlockExternal(); cursorImage->unlockExternal();
cursorWidth = cursorImage->getWidth(); cursor.width = cursorImage->getWidth();
cursorHeight = cursorImage->getHeight(); cursor.height = cursorImage->getHeight();
} }
else else
{ {
cursorWidth = 0; cursor.width = 0;
cursorHeight = 0; cursor.height = 0;
} }
} }
void FrameBuffer::setCursorOrigin(int x0, int y0) void FrameBuffer::setCursorOrigin(int x0, int y0)
{ {
cursorHotspotX = x0; cursor.hotspotX = x0;
cursorHotspotY = y0; cursor.hotspotY = y0;
} }
void FrameBuffer::setCursorPosition(int x, int y) void FrameBuffer::setCursorPosition(int x, int y)
{ {
cursorPositionX = x; cursor.positionX = x;
cursorPositionY = y; cursor.positionY = y;
} }
void FrameBuffer::copy(void *source, Format format, size_t stride) void FrameBuffer::copy(void *source, Format format, size_t stride)
...@@ -162,8 +154,8 @@ namespace sw ...@@ -162,8 +154,8 @@ namespace sw
target = (byte*)source + (height - 1) * stride; target = (byte*)source + (height - 1) * stride;
} }
cursorX = cursorPositionX - cursorHotspotX; cursor.x = cursor.positionX - cursor.hotspotX;
cursorY = cursorPositionY - cursorHotspotY; cursor.y = cursor.positionY - cursor.hotspotY;
if(ASYNCHRONOUS_BLIT) if(ASYNCHRONOUS_BLIT)
{ {
...@@ -188,8 +180,8 @@ namespace sw ...@@ -188,8 +180,8 @@ namespace sw
update.destFormat = destFormat; update.destFormat = destFormat;
update.sourceFormat = sourceFormat; update.sourceFormat = sourceFormat;
update.stride = stride; update.stride = stride;
update.cursorWidth = cursorWidth; update.cursorWidth = cursor.width;
update.cursorHeight = cursorHeight; update.cursorHeight = cursor.height;
if(memcmp(&blitState, &update, sizeof(BlitState)) != 0) if(memcmp(&blitState, &update, sizeof(BlitState)) != 0)
{ {
...@@ -197,10 +189,10 @@ namespace sw ...@@ -197,10 +189,10 @@ namespace sw
delete blitRoutine; delete blitRoutine;
blitRoutine = copyRoutine(blitState); blitRoutine = copyRoutine(blitState);
blitFunction = (void(*)(void*, void*))blitRoutine->getEntry(); blitFunction = (void(*)(void*, void*, Cursor*))blitRoutine->getEntry();
} }
blitFunction(locked, target); blitFunction(locked, target, &cursor);
} }
Routine *FrameBuffer::copyRoutine(const BlitState &state) Routine *FrameBuffer::copyRoutine(const BlitState &state)
...@@ -213,10 +205,11 @@ namespace sw ...@@ -213,10 +205,11 @@ namespace sw
const int sBytes = Surface::bytes(state.sourceFormat); const int sBytes = Surface::bytes(state.sourceFormat);
const int sStride = topLeftOrigin ? (sBytes * width2) : -(sBytes * width2); const int sStride = topLeftOrigin ? (sBytes * width2) : -(sBytes * width2);
Function<Void(Pointer<Byte>, Pointer<Byte>)> function; Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function;
{ {
Pointer<Byte> dst(function.Arg<0>()); Pointer<Byte> dst(function.Arg<0>());
Pointer<Byte> src(function.Arg<1>()); Pointer<Byte> src(function.Arg<1>());
Pointer<Byte> cursor(function.Arg<2>());
For(Int y = 0, y < height, y++) For(Int y = 0, y < height, y++)
{ {
...@@ -539,10 +532,10 @@ namespace sw ...@@ -539,10 +532,10 @@ namespace sw
} }
} }
Int x0 = *Pointer<Int>(&cursorX); Int x0 = *Pointer<Int>(cursor + OFFSET(Cursor,x));
Int y0 = *Pointer<Int>(&cursorY); Int y0 = *Pointer<Int>(cursor + OFFSET(Cursor,y));
For(Int y1 = 0, y1 < cursorHeight, y1++) For(Int y1 = 0, y1 < state.cursorHeight, y1++)
{ {
Int y = y0 + y1; Int y = y0 + y1;
...@@ -550,9 +543,9 @@ namespace sw ...@@ -550,9 +543,9 @@ namespace sw
{ {
Pointer<Byte> d = dst + y * dStride + x0 * dBytes; Pointer<Byte> d = dst + y * dStride + x0 * dBytes;
Pointer<Byte> s = src + y * sStride + x0 * sBytes; Pointer<Byte> s = src + y * sStride + x0 * sBytes;
Pointer<Byte> c = *Pointer<Pointer<Byte> >(&cursor) + y1 * cursorWidth * 4; Pointer<Byte> c = *Pointer<Pointer<Byte>>(cursor + OFFSET(Cursor,image)) + y1 * state.cursorWidth * 4;
For(Int x1 = 0, x1 < cursorWidth, x1++) For(Int x1 = 0, x1 < state.cursorWidth, x1++)
{ {
Int x = x0 + x1; Int x = x0 + x1;
......
...@@ -75,22 +75,27 @@ namespace sw ...@@ -75,22 +75,27 @@ namespace sw
void *target; // Render target buffer void *target; // Render target buffer
void (*blitFunction)(void *dst, void *src); struct Cursor
{
void *image;
int x;
int y;
int width;
int height;
int hotspotX;
int hotspotY;
int positionX;
int positionY;
};
static Cursor cursor;
void (*blitFunction)(void *dst, void *src, Cursor *cursor);
Routine *blitRoutine; Routine *blitRoutine;
BlitState blitState; BlitState blitState;
static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c); static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c);
static void *cursor;
static int cursorWidth;
static int cursorHeight;
static int cursorHotspotX;
static int cursorHotspotY;
static int cursorPositionX;
static int cursorPositionY;
static int cursorX;
static int cursorY;
Thread *blitThread; Thread *blitThread;
Event syncEvent; Event syncEvent;
Event blitEvent; Event blitEvent;
......
...@@ -705,26 +705,7 @@ namespace sw ...@@ -705,26 +705,7 @@ namespace sw
mask[3] ? 7 : 3, mask[3] ? 7 : 3,
}; };
Value *shuffle = Nucleus::createShuffleVector(lhs, rhs, swizzle); return Nucleus::createShuffleVector(lhs, rhs, swizzle);
return shuffle;
}
Value *Nucleus::createConstantPointer(const void *address, Type *Ty, unsigned int align)
{
const GlobalValue *existingGlobal = ::executionEngine->getGlobalValueAtAddress(const_cast<void*>(address)); // FIXME: Const
if(existingGlobal)
{
return (Value*)existingGlobal;
}
llvm::GlobalValue *global = new llvm::GlobalVariable(*::module, Ty, true, llvm::GlobalValue::ExternalLinkage, 0, "");
global->setAlignment(align);
::executionEngine->addGlobalMapping(global, const_cast<void*>(address));
return V(global);
} }
Type *Nucleus::getPointerType(Type *ElementType) Type *Nucleus::getPointerType(Type *ElementType)
......
...@@ -163,7 +163,6 @@ namespace sw ...@@ -163,7 +163,6 @@ namespace sw
static Value *createNullPointer(Type *type); static Value *createNullPointer(Type *type);
static Value *createConstantVector(const int64_t *constants, Type *type); static Value *createConstantVector(const int64_t *constants, Type *type);
static Value *createConstantVector(const double *constants, Type *type); static Value *createConstantVector(const double *constants, Type *type);
static Value *createConstantPointer(const void *external, Type *type, unsigned int align = 0);
static Type *getPointerType(Type *elementType); static Type *getPointerType(Type *elementType);
......
...@@ -2094,7 +2094,6 @@ namespace sw ...@@ -2094,7 +2094,6 @@ namespace sw
} }
Pointer(Argument<Pointer<T>> argument); Pointer(Argument<Pointer<T>> argument);
explicit Pointer(const void *external);
Pointer(); Pointer();
Pointer(RValue<Pointer<T>> rhs); Pointer(RValue<Pointer<T>> rhs);
...@@ -2475,14 +2474,6 @@ namespace sw ...@@ -2475,14 +2474,6 @@ namespace sw
} }
template<class T> template<class T>
Pointer<T>::Pointer(const void *external) : alignment((intptr_t)external & 0x0000000F ? 1 : 16)
{
Value *globalPointer = Nucleus::createConstantPointer(external, T::getType(), alignment);
LValue<Pointer<T>>::storeValue(globalPointer);
}
template<class T>
Pointer<T>::Pointer() : alignment(1) Pointer<T>::Pointer() : alignment(1)
{ {
LValue<Pointer<T>>::storeValue(Nucleus::createNullPointer(T::getType())); LValue<Pointer<T>>::storeValue(Nucleus::createNullPointer(T::getType()));
......
...@@ -1081,18 +1081,6 @@ namespace sw ...@@ -1081,18 +1081,6 @@ namespace sw
return result; return result;
} }
Value *Nucleus::createConstantPointer(const void *address, Type *Ty, unsigned int align)
{
if(sizeof(void*) == 8)
{
return createAssign(::context->getConstantInt64(reinterpret_cast<intptr_t>(address)));
}
else
{
return createAssign(::context->getConstantInt32(reinterpret_cast<intptr_t>(address)));
}
}
Type *Nucleus::getPointerType(Type *ElementType) Type *Nucleus::getPointerType(Type *ElementType)
{ {
if(sizeof(void*) == 8) if(sizeof(void*) == 8)
...@@ -1165,15 +1153,8 @@ namespace sw ...@@ -1165,15 +1153,8 @@ namespace sw
Value *Nucleus::createNullPointer(Type *Ty) Value *Nucleus::createNullPointer(Type *Ty)
{ {
if(true)
{
return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32));
} }
else
{
return createConstantPointer(nullptr, Ty);
}
}
Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment