Commit aff3ad41 by Nicolas Capens

Deprecate DLL precaching support.

It has bitrotted and should be reimplemented with support from the Reactor back-end if needed again. Bug swiftshader:10 Change-Id: Ie926903ccd8117e91b9d13bf031a7b88287e7276 Reviewed-on: https://swiftshader-review.googlesource.com/7250Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 2ab69ee7
...@@ -677,8 +677,6 @@ if(WIN32) ...@@ -677,8 +677,6 @@ if(WIN32)
${SOURCE_DIR}/Main/FrameBufferGDI.hpp ${SOURCE_DIR}/Main/FrameBufferGDI.hpp
${SOURCE_DIR}/Main/FrameBufferWin.cpp ${SOURCE_DIR}/Main/FrameBufferWin.cpp
${SOURCE_DIR}/Main/FrameBufferWin.hpp ${SOURCE_DIR}/Main/FrameBufferWin.hpp
${SOURCE_DIR}/Reactor/DLL.cpp
${SOURCE_DIR}/Reactor/DLL.hpp
) )
list(APPEND OPENGL_COMPILER_LIST ${OPENGL_COMPILER_DIR}/ossource_win.cpp) list(APPEND OPENGL_COMPILER_LIST ${OPENGL_COMPILER_DIR}/ossource_win.cpp)
list(APPEND EGL_LIST ${OPENGL_DIR}/libEGL/libEGL.rc) list(APPEND EGL_LIST ${OPENGL_DIR}/libEGL/libEGL.rc)
......
...@@ -47,7 +47,6 @@ source_set("swiftshader_reactor") { ...@@ -47,7 +47,6 @@ source_set("swiftshader_reactor") {
] ]
if (is_win) { if (is_win) {
sources += [ "DLL.cpp" ]
configs -= [ "//build/config/win:unicode" ] configs -= [ "//build/config/win:unicode" ]
} }
......
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_DLL_hpp
#define sw_DLL_hpp
#include <windows.h>
#include <vector>
#include <map>
namespace sw
{
class DLL
{
public:
DLL(const char *name, const void *constants = 0, int constSize = 0);
~DLL();
void addFunction(const void *function, const void *entry, int size);
void addRelocation(const void *function, const void *address, bool ripRelative);
void emit();
private:
int pageAlign(int address) // Align to 4 kB virtual page size
{
return (address + 0xFFF) & -0x1000;
}
int fileAlign(int address) // Align to 512 byte file sections
{
return (address + 0x1FF) & -0x200;
}
char *dllName;
IMAGE_DOS_HEADER DOSheader;
IMAGE_NT_HEADERS32 COFFheader32;
IMAGE_NT_HEADERS64 COFFheader64;
IMAGE_SECTION_HEADER textSection;
IMAGE_SECTION_HEADER exportsSection;
IMAGE_SECTION_HEADER relocSection;
IMAGE_SECTION_HEADER constSection;
IMAGE_EXPORT_DIRECTORY exportDirectory;
struct Function
{
Function() {};
Function(unsigned int location, const void *function, const void *entry, int size) : location(location), entry(entry), size(size)
{
buffer = new unsigned char[size];
memcpy(buffer, function, size);
}
~Function()
{
delete[] buffer;
}
void *buffer;
unsigned int location;
const void *entry;
int size;
};
std::vector<const void*> functionOrder;
typedef std::map<const void*, Function*> FunctionList;
FunctionList functionList;
int codeSize;
const void *constants;
int constSize;
struct Relocation
{
Relocation(unsigned int offset, bool ripRelative) : offset(offset), ripRelative(ripRelative)
{
}
unsigned int offset;
bool ripRelative;
};
typedef std::map<const void*, std::vector<Relocation> > GlobalRelocations;
GlobalRelocations globalRelocations;
typedef std::map<unsigned int, std::vector<unsigned short> > PageRelocations;
PageRelocations pageRelocations;
};
}
#endif // sw_DLL_hpp
...@@ -266,13 +266,11 @@ ...@@ -266,13 +266,11 @@
</ProjectReference> </ProjectReference>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="DLL.cpp" />
<ClCompile Include="Nucleus.cpp" /> <ClCompile Include="Nucleus.cpp" />
<ClCompile Include="Routine.cpp" /> <ClCompile Include="Routine.cpp" />
<ClCompile Include="RoutineManager.cpp" /> <ClCompile Include="RoutineManager.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="DLL.hpp" />
<ClInclude Include="Nucleus.hpp" /> <ClInclude Include="Nucleus.hpp" />
<ClInclude Include="Reactor.hpp" /> <ClInclude Include="Reactor.hpp" />
<ClInclude Include="Routine.hpp" /> <ClInclude Include="Routine.hpp" />
......
...@@ -15,9 +15,6 @@ ...@@ -15,9 +15,6 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="DLL.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Nucleus.cpp"> <ClCompile Include="Nucleus.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
...@@ -29,9 +26,6 @@ ...@@ -29,9 +26,6 @@
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="DLL.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Nucleus.hpp"> <ClInclude Include="Nucleus.hpp">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
......
...@@ -34,141 +34,15 @@ namespace sw ...@@ -34,141 +34,15 @@ namespace sw
HMODULE precacheDLL; HMODULE precacheDLL;
#endif #endif
}; };
}
#if defined(_WIN32)
#include "Shader/Constants.hpp"
#include "Reactor/DLL.hpp"
#endif
namespace sw
{
template<class State> template<class State>
RoutineCache<State>::RoutineCache(int n, const char *precache) : LRUCache<State, Routine>(n), precache(precache) RoutineCache<State>::RoutineCache(int n, const char *precache) : LRUCache<State, Routine>(n), precache(precache)
{ {
#if defined(_WIN32)
precacheDLL = 0;
if(precache)
{
char dllName[1024]; sprintf(dllName, "%s.dll", precache);
char dirName[1024]; sprintf(dirName, "%s.dir", precache);
precacheDLL = LoadLibrary(dllName);
FILE *dir = fopen(dirName, "rb");
uintptr_t ordinal = 1;
while(precacheDLL && dir)
{
State state;
int offset;
int size;
size_t bytes = fread(&state, 1, sizeof(State), dir);
bytes += fread(&offset, 1, sizeof(offset), dir);
bytes += fread(&size, 1, sizeof(size), dir);
if(bytes != sizeof(State) + sizeof(offset) + sizeof(size))
{
break;
}
void (*routine)(void) = (void(*)(void))GetProcAddress(precacheDLL, (char*)ordinal);
ordinal++;
if(routine)
{
add(state, new Routine(routine, size, offset));
}
}
if(dir)
{
fclose(dir);
}
}
#endif
} }
template<class State> template<class State>
RoutineCache<State>::~RoutineCache() RoutineCache<State>::~RoutineCache()
{ {
#if defined(_WIN32)
char dllName[1024]; sprintf(dllName, "%s.dll", precache);
char dirName[1024]; sprintf(dirName, "%s.dir", precache);
if(precache)
{
DLL dll(dllName, &constants, sizeof(Constants));
FILE *dir = fopen(dirName, "wb");
for(int i = 0; i < getSize(); i++)
{
State &state = getKey(i);
Routine *routine = query(state);
if(routine)
{
unsigned char *buffer = (unsigned char*)routine->getBuffer();
unsigned char *entry = (unsigned char*)routine->getEntry();
int size = routine->getBufferSize();
int codeSize = routine->getCodeSize();
#ifndef _M_AMD64
for(int j = 1; j < codeSize - 4; j++)
{
unsigned char modRM_SIB = entry[j - 1];
unsigned int address = *(unsigned int*)&entry[j];
if((modRM_SIB & 0x05) == 0x05 && (address % 4) == 0)
{
if(address >= (unsigned int)buffer && address < (unsigned int)entry) // Constant stored above the function entry
{
dll.addRelocation(buffer, &entry[j], true);
j += 4;
}
}
}
#else
for(int j = 1; j < codeSize - 4; j++)
{
// unsigned char modRM_SIB = entry[j - 1];
uint64_t address = *(uint64_t*)&entry[j];
// if((modRM_SIB & 0x05) == 0x05 && (address % 4) == 0)
{
if(address >= (uint64_t)buffer && address < (uint64_t)entry) // Constant stored above the function entry
{
dll.addRelocation(buffer, &entry[j], true);
j += 4;
}
}
}
#endif
dll.addFunction(buffer, entry, size);
fwrite(&state, 1, sizeof(State), dir);
int offset = (int)(entry - buffer);
fwrite(&offset, 1, sizeof(offset), dir);
fwrite(&size, 1, sizeof(size), dir);
}
}
FreeLibrary(precacheDLL);
dll.emit();
fclose(dir);
}
else
{
FreeLibrary(precacheDLL);
remove(dllName);
remove(dirName);
}
#endif
} }
} }
......
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