1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Extended memory loading support

This commit is contained in:
Brian Fiete 2025-01-17 10:18:50 -08:00
parent 0efdecb719
commit 29c0f82bba
7 changed files with 136 additions and 33 deletions

View file

@ -177,6 +177,7 @@
<LibraryPath>third_party\AK\lib\release;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86;$(FrameworkSDKDir)\lib</LibraryPath> <LibraryPath>third_party\AK\lib\release;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86;$(FrameworkSDKDir)\lib</LibraryPath>
<IncludePath>$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath);$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;C:\Program Files (x86)\Microsoft DirectX SDK (June 2007)\Include;C:\temp\wx\wxMSW-2.8.12\include;C:\temp\wx\wxMSW-2.8.12\include\msvc</IncludePath> <IncludePath>$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath);$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;C:\Program Files (x86)\Microsoft DirectX SDK (June 2007)\Include;C:\temp\wx\wxMSW-2.8.12\include;C:\temp\wx\wxMSW-2.8.12\include\msvc</IncludePath>
<OutDir>$(SolutionDir)\IDE\dist\</OutDir> <OutDir>$(SolutionDir)\IDE\dist\</OutDir>
<TargetName>$(ProjectName)64_Static</TargetName>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
@ -414,11 +415,12 @@ copy /y "$(OutDir)$(TargetName).lib" "$(SolutionDir)\BeefLibs\Beefy2D\dist\"</Co
<PrecompiledHeader> <PrecompiledHeader>
</PrecompiledHeader> </PrecompiledHeader>
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>false</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;BFSYSLIB_DYNAMIC;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;BFSYSLIB_DYNAMIC;BF_NO_FBX;FT2_BUILD_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>./; ./platform/win/; third_party/agg-2.4/include; third_party/agg-2.4/include/platform/win32; third_party/; third_party/libffi/i686-pc-cygwin; third_party/libffi/i686-pc-cygwin/include; third_party/libffi/include</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>./;./platform/win/;./platform/sdl/;third_party/agg-2.4/include;third_party/agg-2.4/include/platform/win32;third_party/;third_party/libffi/i686-pc-cygwin;third_party/libffi/i686-pc-cygwin/include;third_party/libffi/include;third_party/SDL2-2.0.1/include;../extern/fbxsdk/include;third_party/freetype/include;../BeefLibs/SDL2/include</AdditionalIncludeDirectories>
<WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -482,7 +484,7 @@ copy /y "$(OutDir)$(TargetName).lib" "$(SolutionDir)\BeefLibs\Beefy2D\dist\"</Co
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="platform\sdl\SdlBFApp.cpp"> <ClCompile Include="platform\sdl\SdlBFApp.cpp">
@ -492,7 +494,7 @@ copy /y "$(OutDir)$(TargetName).lib" "$(SolutionDir)\BeefLibs\Beefy2D\dist\"</Co
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="platform\win\CrashCatcher.cpp" /> <ClCompile Include="platform\win\CrashCatcher.cpp" />
@ -2001,7 +2003,7 @@ copy /y "$(OutDir)$(TargetName).lib" "$(SolutionDir)\BeefLibs\Beefy2D\dist\"</Co
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
</ClInclude> </ClInclude>
<ClInclude Include="platform\sdl\SdlBFApp.h"> <ClInclude Include="platform\sdl\SdlBFApp.h">
@ -2010,7 +2012,7 @@ copy /y "$(OutDir)$(TargetName).lib" "$(SolutionDir)\BeefLibs\Beefy2D\dist\"</Co
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
</ClInclude> </ClInclude>
<ClInclude Include="platform\win\CrashCatcher.h" /> <ClInclude Include="platform\win\CrashCatcher.h" />

View file

@ -1380,6 +1380,16 @@ void Beefy::BFFatalError(const char* message, const char* file, int line)
BFFatalError(String(message), String(file), line); BFFatalError(String(message), String(file), line);
} }
void MakeUpper(const StringImpl& theString) bool Beefy::ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize)
{ {
if (str.StartsWith("@"))
{
int colon = (int)str.IndexOf(':');
String addrStr = str.Substring(1, colon - 1);
String lenStr = str.Substring(colon + 1);
outPtr = (void*)(intptr)strtoll(addrStr.c_str(), NULL, 16);
outSize = (int)strtol(lenStr.c_str(), NULL, 10);
return true;
}
return false;
} }

View file

@ -242,6 +242,7 @@ bool FileExists(const StringImpl& path, String* outActualName = NULL);
bool DirectoryExists(const StringImpl& path, String* outActualName = NULL); bool DirectoryExists(const StringImpl& path, String* outActualName = NULL);
bool RecursiveCreateDirectory(const StringImpl& dirName); bool RecursiveCreateDirectory(const StringImpl& dirName);
bool RecursiveDeleteDirectory(const StringImpl& dirName); bool RecursiveDeleteDirectory(const StringImpl& dirName);
bool ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize);
#define CHARTAG(val) FromBIGEndian(val) #define CHARTAG(val) FromBIGEndian(val)

View file

@ -147,13 +147,24 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize)
String useFileName = fileName; String useFileName = fileName;
int faceIdx = 0; int faceIdx = 0;
int atPos = (int)useFileName.IndexOf('@'); int atPos = (int)useFileName.IndexOf('@', 1);
if (atPos != -1) if (atPos != -1)
{ {
faceIdx = atoi(useFileName.c_str() + atPos + 1); faceIdx = atoi(useFileName.c_str() + atPos + 1);
useFileName.RemoveToEnd(atPos); useFileName.RemoveToEnd(atPos);
} }
auto error = FT_New_Face(gFTLibrary, useFileName.c_str(), faceIdx, &ftFace);
void* memPtr = NULL;
int memLen = 0;
if (ParseMemorySpan(fileName, memPtr, memLen))
{
FT_New_Memory_Face(gFTLibrary, (FT_Byte*)memPtr, memLen, faceIdx, &ftFace);
}
else
{
FT_New_Face(gFTLibrary, useFileName.c_str(), faceIdx, &ftFace);
}
face->mFTFace = ftFace; face->mFTFace = ftFace;
} }
else else

View file

@ -150,14 +150,12 @@ Texture* RenderDevice::LoadTexture(const StringImpl& fileName, int flags)
if (!handled) if (!handled)
{ {
imageData->mWantsAlphaPremultiplied = (flags & TextureFlag_NoPremult) == 0; imageData->mWantsAlphaPremultiplied = (flags & TextureFlag_NoPremult) == 0;
if (fileName.StartsWith("@"))
{ void* memPtr = NULL;
int colon = (int)fileName.IndexOf(':'); int memLen = 0;
String addrStr = fileName.Substring(1, colon - 1); if (ParseMemorySpan(fileName, memPtr, memLen))
String lenStr = fileName.Substring(colon + 1); {
void* addr = (void*)(intptr)strtoll(addrStr.c_str(), NULL, 16); if (!imageData->LoadFromMemory(memPtr, memLen))
int len = (int)strtol(lenStr.c_str(), NULL, 10);
if (!imageData->LoadFromMemory(addr, len))
{ {
failed = true; failed = true;
delete imageData; delete imageData;

View file

@ -5,6 +5,7 @@
#include "img/ImageData.h" #include "img/ImageData.h"
#include "util/PerfTimer.h" #include "util/PerfTimer.h"
#include "util/BeefPerf.h" #include "util/BeefPerf.h"
#include "Span.h"
#include "FileStream.h" #include "FileStream.h"
#include "DDS.h" #include "DDS.h"
@ -225,12 +226,14 @@ void DXShader::ReleaseNative()
mConstBuffer = NULL; mConstBuffer = NULL;
} }
extern "C" extern "C" typedef HRESULT(WINAPI* Func_D3DX10CompileFromFileW)(LPCWSTR pSrcFile, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude,
typedef HRESULT(WINAPI* Func_D3DX10CompileFromFileW)(LPCWSTR pSrcFile, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude,
LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs); LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs);
static Func_D3DX10CompileFromFileW gFunc_D3DX10CompileFromFileW; static Func_D3DX10CompileFromFileW gFunc_D3DX10CompileFromFileW;
extern "C" typedef HRESULT(WINAPI* Func_D3DX10Compile)(void* srcData, size_t srcSize, char* sourceName, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude,
LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs);
static Func_D3DX10Compile gFunc_D3DX10Compile;
static bool LoadDXShader(const StringImpl& filePath, const StringImpl& entry, const StringImpl& profile, ID3D10Blob** outBuffer) static bool LoadDXShader(const StringImpl& filePath, const StringImpl& entry, const StringImpl& profile, ID3D10Blob** outBuffer)
{ {
HRESULT hr; HRESULT hr;
@ -239,7 +242,7 @@ static bool LoadDXShader(const StringImpl& filePath, const StringImpl& entry, co
bool useCache = false; bool useCache = false;
auto srcDate = ::BfpFile_GetTime_LastWrite(filePath.c_str()); auto srcDate = ::BfpFile_GetTime_LastWrite(filePath.c_str());
auto cacheDate = ::BfpFile_GetTime_LastWrite(outObj.c_str()); auto cacheDate = ::BfpFile_GetTime_LastWrite(outObj.c_str());
if (cacheDate >= srcDate) if ((cacheDate != 0) && (cacheDate >= srcDate))
useCache = true; useCache = true;
if (!useCache) if (!useCache)
@ -257,16 +260,37 @@ static bool LoadDXShader(const StringImpl& filePath, const StringImpl& entry, co
if (!useCache) if (!useCache)
{ {
if (gFunc_D3DX10CompileFromFileW == NULL) bool useCompile = true;
{
auto lib = LoadLibraryA("D3DCompiler_47.dll");
if (lib != NULL)
gFunc_D3DX10CompileFromFileW = (Func_D3DX10CompileFromFileW)::GetProcAddress(lib, "D3DCompileFromFile");
}
HRESULT dxResult;
ID3D10Blob* errorMessage = NULL; ID3D10Blob* errorMessage = NULL;
auto dxResult = gFunc_D3DX10CompileFromFileW(UTF8Decode(filePath).c_str(), NULL, NULL, entry.c_str(), profile.c_str(), if (useCompile)
D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_STRICTNESS, 0, outBuffer, &errorMessage); {
if (gFunc_D3DX10Compile == NULL)
{
auto lib = LoadLibraryA("D3DCompiler_47.dll");
if (lib != NULL)
gFunc_D3DX10Compile = (Func_D3DX10Compile)::GetProcAddress(lib, "D3DCompile");
}
int memSize = 0;
uint8* memPtr = LoadBinaryData(filePath, &memSize);
dxResult = gFunc_D3DX10Compile(memPtr, memSize, "Shader", NULL, NULL, entry.c_str(), profile.c_str(),
D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_STRICTNESS, 0, outBuffer, &errorMessage);
}
else
{
if (gFunc_D3DX10CompileFromFileW == NULL)
{
auto lib = LoadLibraryA("D3DCompiler_47.dll");
if (lib != NULL)
gFunc_D3DX10CompileFromFileW = (Func_D3DX10CompileFromFileW)::GetProcAddress(lib, "D3DCompileFromFile");
}
dxResult = gFunc_D3DX10CompileFromFileW(UTF8Decode(filePath).c_str(), NULL, NULL, entry.c_str(), profile.c_str(),
D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_STRICTNESS, 0, outBuffer, &errorMessage);
}
if (DXFAILED(dxResult)) if (DXFAILED(dxResult))
{ {
@ -310,6 +334,36 @@ static bool LoadDXShader(const StringImpl& filePath, const StringImpl& entry, co
return true; return true;
} }
static bool LoadDXShader(Span<uint8> fileData, const StringImpl& entry, const StringImpl& profile, ID3D10Blob** outBuffer)
{
HRESULT hr;
if (gFunc_D3DX10Compile == NULL)
{
auto lib = LoadLibraryA("D3DCompiler_47.dll");
if (lib != NULL)
gFunc_D3DX10Compile = (Func_D3DX10Compile)::GetProcAddress(lib, "D3DCompile");
}
ID3D10Blob* errorMessage = NULL;
auto dxResult = gFunc_D3DX10Compile(fileData.mVals, fileData.mSize, "ShaderSource", NULL, NULL, entry.c_str(), profile.c_str(),
D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_STRICTNESS, 0, outBuffer, &errorMessage);
if (DXFAILED(dxResult))
{
if (errorMessage != NULL)
{
BF_FATAL(StrFormat("Vertex shader load failed: %s", (char*)errorMessage->GetBufferPointer()).c_str());
errorMessage->Release();
}
else
BF_FATAL("Shader load failed");
return false;
}
return true;
}
bool DXShader::Load() bool DXShader::Load()
{ {
//HRESULT hr; //HRESULT hr;
@ -318,8 +372,35 @@ bool DXShader::Load()
ID3D10Blob* vertexShaderBuffer = NULL; ID3D10Blob* vertexShaderBuffer = NULL;
ID3D10Blob* pixelShaderBuffer = NULL; ID3D10Blob* pixelShaderBuffer = NULL;
LoadDXShader(mSrcPath + ".fx", "VS", "vs_4_0", &vertexShaderBuffer); void* memPtr = NULL;
LoadDXShader(mSrcPath + ".fx", "PS", "ps_4_0", &pixelShaderBuffer); int memSize = 0;
if (ParseMemorySpan(mSrcPath, memPtr, memSize))
{
int crPos = (int)mSrcPath.IndexOf('\n');
if (crPos != -1)
{
void* memPtr2 = NULL;
int memSize2 = 0;
if (ParseMemorySpan(mSrcPath.Substring(crPos + 1), memPtr2, memSize2))
{
D3D10CreateBlob(memSize, &vertexShaderBuffer);
memcpy(vertexShaderBuffer->GetBufferPointer(), memPtr, memSize);
D3D10CreateBlob(memSize2, &pixelShaderBuffer);
memcpy(pixelShaderBuffer->GetBufferPointer(), memPtr2, memSize2);
}
}
else
{
Span<uint8> span((uint8*)memPtr, memSize);
LoadDXShader(span, "VS", "vs_4_0", &vertexShaderBuffer);
LoadDXShader(span, "PS", "ps_4_0", &pixelShaderBuffer);
}
}
else
{
LoadDXShader(mSrcPath + ".fx", "VS", "vs_4_0", &vertexShaderBuffer);
LoadDXShader(mSrcPath + ".fx", "PS", "ps_4_0", &pixelShaderBuffer);
}
defer( defer(
{ {

View file

@ -320,7 +320,7 @@ public:
#define BP_EXPORT BF_EXPORT #define BP_EXPORT BF_EXPORT
#define BP_CALLTYPE BF_CALLTYPE #define BP_CALLTYPE BF_CALLTYPE
#else #else
#define BP_EXPORT #define BP_EXPORT extern "C"
#define BP_CALLTYPE #define BP_CALLTYPE
#endif #endif