Skip to content

Commit

Permalink
Merge pull request #154 from ConfettiFX/confetti-dev
Browse files Browse the repository at this point in the history
Release 1.38 - November 14th - Cross-Platform Path Tracer
  • Loading branch information
wolfgangfengel authored Nov 14, 2019
2 parents ce71355 + b06100b commit c908080
Show file tree
Hide file tree
Showing 66 changed files with 7,361 additions and 1,671 deletions.
26 changes: 20 additions & 6 deletions Common_3/OS/Android/AndroidBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,20 @@ int AndroidMain(void* param, IApp* app)


if (!MemAllocInit())
{
__android_log_print(ANDROID_LOG_ERROR, "The-Forge", "Error starting application");
return EXIT_FAILURE;

}
struct android_app* android_app = (struct android_app*)param;
android_activity = android_app->activity;
AndroidFS_SetNativeActivity(android_activity);

Log::Init();

if (!fsInitAPI())
{
__android_log_print(ANDROID_LOG_ERROR, "The-Forge", "Error starting application");
return EXIT_FAILURE;
}
Log::Init();


// Set the callback to process system events
android_app->onAppCmd = handle_cmd;
Expand Down Expand Up @@ -330,6 +334,9 @@ int AndroidMain(void* param, IApp* app)
}
if (!windowReady || !isActive)
{
if (android_app->destroyRequested)
quit = true;

usleep(1);
continue;
}
Expand All @@ -347,7 +354,9 @@ int AndroidMain(void* param, IApp* app)
//used in automated tests only.
testingFrameCount++;
if (testingFrameCount >= testingDesiredFrameCount)
quit = true;
{
ANativeActivity_finish(android_app->activity);
}
#endif
if (android_app->destroyRequested)
quit = true;
Expand All @@ -360,7 +369,12 @@ int AndroidMain(void* param, IApp* app)
Log::Exit();
fsDeinitAPI();
MemAllocExit();


#ifdef AUTOMATED_TESTING
__android_log_print(ANDROID_LOG_INFO, "The-Forge", "Success terminating application");
exit(0);
#endif

return 0;
}
/************************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions Common_3/OS/Android/AndroidFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class AndroidBundleFileSystem: public FileSystem
const char* p = strcasestr(fileName, extension);
if (p)
{
Path* path = fsCreatePath(this, fileName);
Path* path = fsAppendPathComponent(directory, fileName);
processFile(path, userData);
fsFreePath(path);
}
Expand Down Expand Up @@ -427,7 +427,7 @@ Path* fsCopyUserDocumentsDirectoryPath()

Path* fsCopyLogFileDirectoryPath()
{
return fsCreatePath(fsGetSystemFileSystem(), pNativeActivity->internalDataPath);
return fsCreatePath(fsGetSystemFileSystem(), pNativeActivity->externalDataPath);
}

void fsShowOpenFileDialog(
Expand Down
21 changes: 17 additions & 4 deletions Common_3/OS/Android/AndroidLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "../Interfaces/ILog.h"
#include <assert.h>
#include "../Interfaces/IMemory.h"
#include <android/log.h>

void outputLogString(const char* pszStr)
{
Expand All @@ -41,13 +42,15 @@ void outputLogString(const char* pszStr)

void _OutputDebugStringV(const char* str, va_list args)
{
#ifdef _DEBUG
const unsigned BUFFER_SIZE = 4096;
#if defined(_DEBUG) || defined(AUTOMATED_TESTING)
const unsigned BUFFER_SIZE = 4096;
char buf[BUFFER_SIZE];

vsprintf_s(buf, BUFFER_SIZE, str, args);

printf("%s\n", buf);
// stdout doesn't work on android. we need to use ndk log functionality.
//printf("%s\n", buf);
__android_log_print(ANDROID_LOG_INFO, "The-Forge", buf);
#endif
}

Expand All @@ -70,7 +73,17 @@ void _FailedAssert(const char* file, int line, const char* statement)
assert(0);
}

void _PrintUnicode(const eastl::string& str, bool error) { outputLogString(str.c_str()); }
void _PrintUnicode(const eastl::string& str, bool error) {

if (error)
{
__android_log_print(ANDROID_LOG_ERROR, "The-Forge", str.c_str());
}
else
{
outputLogString(str.c_str());
}
}

void _PrintUnicodeLine(const eastl::string& str, bool error) { _PrintUnicode(str, error); }
#endif // ifdef __ANDROID__
8 changes: 4 additions & 4 deletions Common_3/OS/FileSystem/FileSystemInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ bool fsInitAPI(void)
Path* logFilePath = fsCopyLogFileDirectoryPath();
if (!logFilePath)
return false;
mmgr_setLogFileDirectory(fsGetPathAsNativeString(logFilePath));
mmgrSetLogFileDirectory(fsGetPathAsNativeString(logFilePath));
fsFreePath(logFilePath);

Path* executablePath = fsCopyExecutablePath();
if (!executablePath)
return false;

PathComponent executableName = fsGetPathFileName(executablePath);
mmgr_setExecutableName(executableName.buffer, executableName.length);
mmgrSetExecutableName(executableName.buffer, executableName.length);
fsFreePath(executablePath);
#endif

Expand Down Expand Up @@ -393,7 +393,7 @@ void fsGetPathComponents(const Path* path, PathComponent* directoryName, PathCom
const char* fileNameEnd = extensionEnd;
const char* fileNameStart = pathString;
const char* directoryNameEnd = NULL;
const char* directoryNameStart = NULL;
const char* directoryNameStart = pathString;

for (size_t i = path->mPathLength - 1; i > 0; i--)
{
Expand Down Expand Up @@ -427,7 +427,7 @@ void fsGetPathComponents(const Path* path, PathComponent* directoryName, PathCom
}
}

if (directoryName && directoryNameStart != NULL)
if (directoryName && directoryNameEnd != NULL)
{
directoryName->buffer = directoryNameStart;
directoryName->length = directoryNameEnd - directoryNameStart;
Expand Down
8 changes: 2 additions & 6 deletions Common_3/OS/FileSystem/FileSystemInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@
#ifndef FileSystemInternal_h
#define FileSystemInternal_h

#include <atomic>
#include <cstdio>
#include <cstring>

#include "../Interfaces/IFileSystem.h"
#include "../Core/Atomics.h"

// Include the functions to set the log file directory and executable name
// for the memory manager.
// We need to set these manually as the memory manager doesn't know when it is safe to call
// FileSystem functions.
void mmgr_setExecutableName(const char* name, size_t length);
void mmgr_setLogFileDirectory(const char* directory);
void mmgrSetExecutableName(const char* name, size_t length);
void mmgrSetLogFileDirectory(const char* directory);

// MARK: - FileSystem

Expand Down
1 change: 1 addition & 0 deletions Common_3/OS/Interfaces/IFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ typedef enum ResourceDirectory
RD_MIDDLEWARE_0,
RD_MIDDLEWARE_1,
RD_MIDDLEWARE_2,
RD_MIDDLEWARE_3,

____rd_lib_counter_end = ____rd_lib_counter_begin + 99 * 3,
RD_ROOT,
Expand Down
14 changes: 7 additions & 7 deletions Common_3/OS/MemoryTracking/MemoryTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
// Just include the cpp here so we don't have to add it to the all projects
#include "../../ThirdParty/OpenSource/FluidStudios/MemoryManager/mmgr.cpp"

void* conf_malloc_internal(size_t size, const char *f, int l, const char *sf) { return m_allocator(f, l, sf, m_alloc_malloc, 0, size); }
void* conf_malloc_internal(size_t size, const char *f, int l, const char *sf) { return mmgrAllocator(f, l, sf, m_alloc_malloc, 0, size); }

void* conf_memalign_internal(size_t align, size_t size, const char *f, int l, const char *sf) { return m_allocator(f, l, sf, m_alloc_memalign, align, size); }
void* conf_memalign_internal(size_t align, size_t size, const char *f, int l, const char *sf) { return mmgrAllocator(f, l, sf, m_alloc_memalign, align, size); }

void* conf_calloc_internal(size_t count, size_t size, const char *f, int l, const char *sf) { return m_allocator(f, l, sf, m_alloc_calloc, 0, size * count); }
void* conf_calloc_internal(size_t count, size_t size, const char *f, int l, const char *sf) { return mmgrAllocator(f, l, sf, m_alloc_calloc, 0, size * count); }

void* conf_realloc_internal(void* ptr, size_t size, const char *f, int l, const char *sf) { return m_reallocator(f, l, sf, m_alloc_realloc, size, ptr); }
void* conf_realloc_internal(void* ptr, size_t size, const char *f, int l, const char *sf) { return mmgrReallocator(f, l, sf, m_alloc_realloc, size, ptr); }

void conf_free_internal(void* ptr, const char *f, int l, const char *sf) { m_deallocator(f, l, sf, m_alloc_free, ptr); }
void conf_free_internal(void* ptr, const char *f, int l, const char *sf) { mmgrDeallocator(f, l, sf, m_alloc_free, ptr); }

#else

Expand All @@ -53,9 +53,9 @@ void MemAllocExit()
#include <stdlib.h>


void mmgr_setLogFileDirectory(const char* directory) {}
void mmgrSetLogFileDirectory(const char* directory) {}

void mmgr_setExecutableName(const char* name, size_t length) {}
void mmgrSetExecutableName(const char* name, size_t length) {}

#ifdef _MSC_VER
#include <memory.h>
Expand Down
14 changes: 7 additions & 7 deletions Common_3/Renderer/Direct3D12/Direct3D12Raytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,18 @@ void removeRaytracingShader(Raytracing* pRaytracing, RaytracingShader* pShader)

static const uint64_t gShaderIdentifierSize = D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES;

void FillShaderIdentifiers( const RaytracingShaderTableRecordDesc* pRecords, uint32_t shaderCount,
void FillShaderIdentifiers( const char *const * pRecords, uint32_t shaderCount,
ID3D12StateObjectProperties* pRtsoProps, uint64_t& maxShaderTableSize,
uint32_t& index, RaytracingShaderTable* pTable, Raytracing* pRaytracing)
{
for (uint32_t i = 0; i < shaderCount; ++i)
{
eastl::hash_set<uint32_t> addedTables;

const RaytracingShaderTableRecordDesc* pRecord = &pRecords[i];
const char* pRecordName = pRecords[i];
void* pIdentifier = NULL;
WCHAR* pName = (WCHAR*)conf_calloc(strlen(pRecord->pName) + 1, sizeof(WCHAR));
mbstowcs(pName, pRecord->pName, strlen(pRecord->pName));
WCHAR* pName = (WCHAR*)conf_calloc(strlen(pRecordName) + 1, sizeof(WCHAR));
mbstowcs(pName, pRecordName, strlen(pRecordName));

pIdentifier = pRtsoProps->GetShaderIdentifier(pName);

Expand Down Expand Up @@ -488,7 +488,7 @@ void FillShaderIdentifiers( const RaytracingShaderTableRecordDesc* pRecords, uin
}
}

void CalculateMaxShaderRecordSize(const RaytracingShaderTableRecordDesc* pRecords, uint32_t shaderCount, uint64_t& maxShaderTableSize)
void CalculateMaxShaderRecordSize(const char *const * pRecords, uint32_t shaderCount, uint64_t& maxShaderTableSize)
{
// #TODO
//for (uint32_t i = 0; i < shaderCount; ++i)
Expand Down Expand Up @@ -552,7 +552,7 @@ void addRaytracingShaderTable(Raytracing* pRaytracing, const RaytracingShaderTab
/************************************************************************/
// Calculate max size for each element in the shader table
/************************************************************************/
CalculateMaxShaderRecordSize(pDesc->pRayGenShader, 1, maxShaderTableSize);
CalculateMaxShaderRecordSize(&pDesc->pRayGenShader, 1, maxShaderTableSize);
CalculateMaxShaderRecordSize(pDesc->pMissShaders, pDesc->mMissShaderCount, maxShaderTableSize);
CalculateMaxShaderRecordSize(pDesc->pHitGroups, pDesc->mHitGroupCount, maxShaderTableSize);
/************************************************************************/
Expand All @@ -576,7 +576,7 @@ void addRaytracingShaderTable(Raytracing* pRaytracing, const RaytracingShaderTab
pDesc->pPipeline->pDxrPipeline->QueryInterface(IID_PPV_ARGS(&pRtsoProps));

uint32_t index = 0;
FillShaderIdentifiers( pDesc->pRayGenShader, 1, pRtsoProps,
FillShaderIdentifiers( &pDesc->pRayGenShader, 1, pRtsoProps,
maxShaderTableSize, index, pTable, pRaytracing);

pTable->mMissRecordSize = maxShaderTableSize * pDesc->mMissShaderCount;
Expand Down
29 changes: 16 additions & 13 deletions Common_3/Renderer/IRay.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ typedef struct RootSignatureDesc RootSignatureDesc;
typedef struct ShaderResource ShaderResource;
typedef struct DescriptorData DescriptorData;
typedef struct ID3D12Device5 ID3D12Device5;
typedef struct ParallelPrimitives ParallelPrimitives;
typedef struct SSVGFDenoiser SSVGFDenoiser;

//Supported by DXR. Metal ignores this.
typedef enum AccelerationStructureBuildFlags
Expand Down Expand Up @@ -153,23 +155,13 @@ typedef struct RaytracingHitGroup
const char* pHitGroupName;
} RaytracingHitGroup;

typedef struct RaytracingShaderTableRecordDesc
{
const char* pName;
#if defined(METAL)
bool mInvokeTraceRay;
uint32_t mHitShaderIndex;
uint32_t mMissShaderIndex;
#endif
} RaytracingShaderTableRecordDesc;

typedef struct RaytracingShaderTableDesc
{
Pipeline* pPipeline;
RootSignature* pEmptyRootSignature;
RaytracingShaderTableRecordDesc* pRayGenShader;
RaytracingShaderTableRecordDesc* pMissShaders;
RaytracingShaderTableRecordDesc* pHitGroups;
const char* pRayGenShader;
const char** pMissShaders;
const char** pHitGroups;
unsigned mMissShaderCount;
unsigned mHitGroupCount;
} RaytracingShaderTableDesc;
Expand Down Expand Up @@ -203,6 +195,10 @@ struct Raytracing
#endif
#ifdef METAL
MPSRayIntersector* pIntersector;

ParallelPrimitives *pParallelPrimitives;
id <MTLComputePipelineState> mClassificationPipeline;
id <MTLArgumentEncoder> mClassificationArgumentEncoder;
#endif

#ifdef VULKAN
Expand All @@ -225,3 +221,10 @@ API_INTERFACE void FORGE_CALLCONV removeRaytracingShaderTable(Raytracing* pRaytr

API_INTERFACE void FORGE_CALLCONV cmdBuildAccelerationStructure(Cmd* pCmd, Raytracing* pRaytracing, RaytracingBuildASDesc* pDesc);
API_INTERFACE void FORGE_CALLCONV cmdDispatchRays(Cmd* pCmd, Raytracing* pRaytracing, const RaytracingDispatchDesc* pDesc);

#ifdef METAL
API_INTERFACE void FORGE_CALLCONV addSSVGFDenoiser(Renderer* pRenderer, SSVGFDenoiser** ppDenoiser);
API_INTERFACE void FORGE_CALLCONV removeSSVGFDenoiser(SSVGFDenoiser* pDenoiser);
API_INTERFACE void FORGE_CALLCONV clearSSVGFDenoiserTemporalHistory(SSVGFDenoiser* pDenoiser);
API_INTERFACE Texture* FORGE_CALLCONV cmdSSVGFDenoise(Cmd* pCmd, SSVGFDenoiser* pDenoiser, Texture* pSourceTexture, Texture* pMotionVectorTexture, Texture* pDepthNormalTexture, Texture* pPreviousDepthNormalTexture);
#endif
5 changes: 5 additions & 0 deletions Common_3/Renderer/IRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ typedef struct Texture
/// Native handle of the underlying resource
id<MTLTexture> mtlTexture;
id<MTLTexture> __strong* pMtlUAVDescriptors;
id mpsTextureAllocator;
MTLPixelFormat mtlPixelFormat;
bool mIsCompressed;
#endif
Expand Down Expand Up @@ -1350,6 +1351,7 @@ typedef struct Shader
id<MTLFunction> mtlVertexShader;
id<MTLFunction> mtlFragmentShader;
id<MTLFunction> mtlComputeShader;
id<MTLLibrary> mtlLibrary;
char** pEntryNames;
uint32_t mNumThreadsPerGroup[3];
#endif
Expand Down Expand Up @@ -1800,6 +1802,9 @@ typedef struct GPUSettings
bool mMultiDrawIndirect;
bool mROVsSupported;
bool mPartialUpdateConstantBufferSupported;
#ifdef METAL
uint32_t mArgumentBufferMaxTextures;
#endif
} GPUSettings;

typedef struct Renderer
Expand Down
8 changes: 8 additions & 0 deletions Common_3/Renderer/Metal/MetalMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef RESOURCE_RESOURCE_H
#define RESOURCE_RESOURCE_H

#include <MetalPerformanceShaders/MetalPerformanceShaders.h>

#include "../../OS/Interfaces/ILog.h"
#include "../../OS/Interfaces/IMemory.h"

Expand Down Expand Up @@ -3729,6 +3731,12 @@ void destroyTexture(ResourceAllocator* allocator, Texture* pTexture)

RESOURCE_DEBUG_GLOBAL_MUTEX_LOCK

if (pTexture->mpsTextureAllocator != nil)
{
[(id<MPSSVGFTextureAllocator>)pTexture->mpsTextureAllocator returnTexture:pTexture->mtlTexture];
pTexture->mpsTextureAllocator = nil;
}

pTexture->mtlTexture = nil;

if (pTexture->pMtlAllocation)
Expand Down
Loading

0 comments on commit c908080

Please sign in to comment.