Skip to content

Commit

Permalink
Merge pull request #301 from ConfettiFX/confetti-dev
Browse files Browse the repository at this point in the history
Release 1.57 Visibility Buffer 2.0 Prototype | Visibility Buffer 1.0 One Draw call
  • Loading branch information
wolfgangfengel authored May 8, 2024
2 parents fc3cc62 + e7867de commit 1893c5f
Show file tree
Hide file tree
Showing 475 changed files with 80,837 additions and 9,460 deletions.
29 changes: 20 additions & 9 deletions Common_3/Application/Interfaces/IApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ class FORGE_API IApp
static const char** argv;
};

#if defined(TARGET_IOS)
#define SetContentScaleFactor(F) (mSettings.mContentScaleFactor = (F))
#else
#define SetContentScaleFactor(F)
#endif

#if defined(XBOX)
FORGE_API extern int DurangoMain(int argc, char** argv, IApp* app);
#define RUN_APPLICATION_MAIN(argc, argv, appInstance, customPtr) DurangoMain(argc, argv, &(appInstance))
Expand All @@ -180,15 +186,20 @@ FORGE_API extern int DurangoMain(int argc, char** argv, IApp* app);
FORGE_API extern int WindowsMain(int argc, char** argv, IApp* app);
#define RUN_APPLICATION_MAIN(argc, argv, appInstance, customPtr) WindowsMain(argc, argv, &(appInstance))

#define DEFINE_APPLICATION_MAIN(appClass) \
extern int WindowsMain(int argc, char** argv, IApp* app); \
\
int main(int argc, char** argv) \
{ \
IApp::argc = argc; \
IApp::argv = (const char**)argv; \
static appClass app = {}; \
return WindowsMain(argc, argv, &app); \
#define DEFINE_APPLICATION_MAIN(appClass) \
int WindowsMain(int argc, char** argv, IApp* app); \
extern "C" \
{ \
__declspec(dllexport) extern const UINT D3D12SDKVersion = D3D12_AGILITY_SDK_VERSION; \
__declspec(dllexport) extern const char* D3D12SDKPath = u8""; \
} \
\
int main(int argc, char** argv) \
{ \
IApp::argc = argc; \
IApp::argv = (const char**)argv; \
static appClass app = {}; \
return WindowsMain(argc, argv, &app); \
}
#elif defined(TARGET_IOS)
FORGE_API extern int iOSMain(int argc, char** argv, IApp* app);
Expand Down
12 changes: 12 additions & 0 deletions Common_3/Graphics/Direct3D12/Direct3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,17 @@ static void QueryRaytracingSupport(ID3D12Device* pDevice, GPUSettings* pGpuSetti
#endif
}

static void Query64BitAtomicsSupport(ID3D12Device* pDevice, GPUSettings* pGpuSettings)
{
ASSERT(pDevice);
D3D12_FEATURE_DATA_D3D12_OPTIONS9 opts9 = {};
HRESULT hres = pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS9, &opts9, sizeof(opts9));
if (SUCCEEDED(hres))
{
pGpuSettings->m64BitAtomicsSupported = opts9.AtomicInt64OnTypedResourceSupported;
}
}

void QueryGPUSettings(ID3D12Device* pDevice, const GpuDesc* pGpuDesc, GPUSettings* pSettings)
{
GPUSettings& gpuSettings = *pSettings;
Expand Down Expand Up @@ -2048,6 +2059,7 @@ void QueryGPUSettings(ID3D12Device* pDevice, const GpuDesc* pGpuDesc, GPUSetting
gpuSettings.mMaxBoundTextures = UINT32_MAX;

QueryRaytracingSupport(pDevice, pSettings);
Query64BitAtomicsSupport(pDevice, pSettings);
}

static void InitializeBufferDesc(Renderer* pRenderer, const BufferDesc* pDesc, D3D12_RESOURCE_DESC* desc)
Expand Down
2 changes: 1 addition & 1 deletion Common_3/Graphics/Direct3D12/Direct3D12Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
#ifdef XBOX
#include "../../../Xbox/Common_3/Graphics/Direct3D12/Direct3D12X.h"
#else
#include <d3d12.h>
#include <dxgi1_6.h>
#include <dxgidebug.h>

#include "../ThirdParty/OpenSource/Direct3d12Agility/include/d3d12.h"
#include "../ThirdParty/OpenSource/DirectXShaderCompiler/inc/dxcapi.h"
#endif

Expand Down
2 changes: 0 additions & 2 deletions Common_3/Graphics/Direct3D12/Direct3D12Raytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include "../../../Xbox/Common_3/Graphics/Direct3D12/Direct3D12X.h"
#else
#define IID_ARGS IID_PPV_ARGS
#include <d3d12.h>
#include <d3dcompiler.h>
#endif

// OS
Expand Down
6 changes: 4 additions & 2 deletions Common_3/Graphics/Direct3D12/Direct3D12ShaderReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
#if defined(XBOX)
#include "../../../Xbox/Common_3/Graphics/Direct3D12/Direct3D12X.h"
#else
#include <d3d12shader.h>

#include "../ThirdParty/OpenSource/Direct3d12Agility/include/d3d12shader.h"
#include "../ThirdParty/OpenSource/DirectXShaderCompiler/inc/dxcapi.h"
#endif

Expand Down Expand Up @@ -297,6 +296,9 @@ void d3d12_createShaderReflection(ID3D12ShaderReflection* d3d12reflection, Shade
}

fill_shader_resources(d3d12reflection, shaderDesc, shaderStage, pCurrentName, reflection);

reflection.mCbvHeapIndexing = d3d12reflection->GetRequiresFlags() & D3D_SHADER_REQUIRES_RESOURCE_DESCRIPTOR_HEAP_INDEXING;
reflection.mSamplerHeapIndexing = d3d12reflection->GetRequiresFlags() & D3D_SHADER_REQUIRES_SAMPLER_DESCRIPTOR_HEAP_INDEXING;
}

// template<typename RefInterface = ID3D12LibraryReflection>
Expand Down
13 changes: 10 additions & 3 deletions Common_3/Graphics/Interfaces/IGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,9 +1197,7 @@ typedef struct DEFINE_ALIGNED(Texture, 64)
id<MTLTexture> __strong* pUAVDescriptors;
id<MTLTexture> pStencilTexture;
};
id mpsTextureAllocator;
uint32_t pPixelFormat;
uint32_t mRT : 1;
id mpsTextureAllocator;
};
#endif
#if defined(DIRECT3D11)
Expand Down Expand Up @@ -1890,6 +1888,13 @@ typedef struct MarkerDesc
#define GPU_MARKER_VALUE(markerBuffer, offset) (*((uint32_t*)markerBuffer->pCpuMappedAddress) + ((offset) / GPU_MARKER_SIZE))
#endif

#if !defined(GFX_ESRAM_ALLOCATIONS)
#define ESRAM_BEGIN_ALLOC(...)
#define ESRAM_CURRENT_OFFSET(...) 0u
#define ESRAM_END_ALLOC(...)
#define ESRAM_RESET_ALLOCS(...)
#endif

typedef struct DEFINE_ALIGNED(Cmd, 64)
{
#if defined(USE_MULTIPLE_RENDER_APIS)
Expand Down Expand Up @@ -2956,6 +2961,7 @@ typedef struct GPUSettings
uint32_t mRayQuerySupported : 1;
uint32_t mSoftwareVRSSupported : 1;
uint32_t mPrimitiveIdSupported : 1;
uint32_t m64BitAtomicsSupported : 1;
#if defined(DIRECT3D11) || defined(DIRECT3D12)
D3D_FEATURE_LEVEL mFeatureLevel;
#endif
Expand Down Expand Up @@ -3171,6 +3177,7 @@ typedef struct GpuInfo
uint32_t mAccelerationStructureExtension : 1;
uint32_t mRayTracingPipelineExtension : 1;
uint32_t mRayQueryExtension : 1;
uint32_t mShaderAtomicInt64Extension : 1;
uint32_t mBufferDeviceAddressFeature : 1;
uint32_t mShaderFloatControlsExtension : 1;
uint32_t mSpirv14Extension : 1;
Expand Down
5 changes: 5 additions & 0 deletions Common_3/Graphics/Interfaces/IShaderReflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ struct ShaderReflection

// number of tessellation control point
uint32_t mNumControlPoint;

#if defined(DIRECT3D12)
bool mCbvHeapIndexing;
bool mSamplerHeapIndexing;
#endif
};

struct PipelineReflection
Expand Down
76 changes: 55 additions & 21 deletions Common_3/Graphics/Metal/MetalRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static inline MemoryType util_to_memory_type(ResourceMemoryUsage usage)
void util_set_heaps_graphics(Cmd* pCmd);
void util_set_heaps_compute(Cmd* pCmd);

void initialize_texture_desc(Renderer* pRenderer, const TextureDesc* pDesc, const bool isRT, uint32_t pixelFormat,
void initialize_texture_desc(Renderer* pRenderer, const TextureDesc* pDesc, const bool isRT, MTLPixelFormat pixelFormat,
MTLTextureDescriptor* textureDesc);
void add_texture(Renderer* pRenderer, const TextureDesc* pDesc, Texture** ppTexture, const bool isRT);

Expand Down Expand Up @@ -710,6 +710,23 @@ void mtl_addDescriptorSet(Renderer* pRenderer, const DescriptorSetDesc* pDesc, D
ShaderStage shaderStages =
(pRootSignature->mPipelineType == PIPELINE_TYPE_COMPUTE ? SHADER_STAGE_COMP : (SHADER_STAGE_VERT | SHADER_STAGE_FRAG));

#ifdef ENABLE_GRAPHICS_DEBUG
// to circumvent a metal validation bug which overwrites the arguments array, we make a local copy
NSMutableArray<MTLArgumentDescriptor*>* descriptorsCopy = [[NSMutableArray alloc] init];
for (MTLArgumentDescriptor* myArrayElement in descriptors)
{
MTLArgumentDescriptor* argDescriptor = [MTLArgumentDescriptor argumentDescriptor];
argDescriptor.access = myArrayElement.access;
argDescriptor.arrayLength = myArrayElement.arrayLength;
argDescriptor.constantBlockAlignment = myArrayElement.constantBlockAlignment;
argDescriptor.dataType = myArrayElement.dataType;
argDescriptor.index = myArrayElement.index;
argDescriptor.textureType = myArrayElement.textureType;
[descriptorsCopy addObject:argDescriptor];
}
descriptors = descriptorsCopy;
#endif

// create encoder
pDescriptorSet->mArgumentEncoder = [pRenderer->pDevice newArgumentEncoderWithArguments:descriptors];
ASSERT(pDescriptorSet->mArgumentEncoder);
Expand Down Expand Up @@ -1040,7 +1057,8 @@ void mtl_updateDescriptorSet(Renderer* pRenderer, uint32_t index, DescriptorSet*
untracked = texture->pTexture;
}

if (texture->mRT || texture->mUav || !texture->pAllocation)
bool isRT = texture->pTexture.usage & MTLTextureUsageRenderTarget;
if (isRT || texture->mUav || !texture->pAllocation)
{
TrackUntrackedResource(pDescriptorSet, index, pDesc->mUsage, untracked);
}
Expand Down Expand Up @@ -2184,6 +2202,12 @@ static void QueryGPUSettings(GpuInfo* gpuInfo, GPUSettings* pOutSettings)
}
#endif

pOutSettings->m64BitAtomicsSupported = [gpuInfo->pGPU supportsFamily:MTLGPUFamilyApple9];
if ([gpuInfo->pGPU supportsFamily:MTLGPUFamilyApple8] && [gpuInfo->pGPU supportsFamily:MTLGPUFamilyMac2])
{
pOutSettings->m64BitAtomicsSupported = true;
}

// Get the supported counter set.
// We only support timestamps at stage boundary..
gpuInfo->pCounterSetTimestamp = util_get_counterset(gpu);
Expand Down Expand Up @@ -2289,11 +2313,6 @@ void mtl_initRendererContext(const char* appName, const RendererContextDesc* pDe
pContext->mGpus[i].mSettings.mGpuVendorPreset.mGpuName);
}

if (IOS14_RUNTIME)
{
pContext->mMtl.mExtendedEncoderDebugReport = true;
}

*ppContext = pContext;
}

Expand Down Expand Up @@ -2406,6 +2425,15 @@ void mtl_initRenderer(const char* appName, const RendererDesc* settings, Rendere
// Renderer is good! Assign it to result!
*(ppRenderer) = pRenderer;
}

if (IOS14_RUNTIME)
{
#if defined(ENABLE_GRAPHICS_DEBUG)
pRenderer->pContext->mMtl.mExtendedEncoderDebugReport = true;
#else
pRenderer->pContext->mMtl.mExtendedEncoderDebugReport = settings->mEnableGpuBasedValidation;
#endif
}
}

void mtl_exitRenderer(Renderer* pRenderer)
Expand Down Expand Up @@ -2836,7 +2864,7 @@ void mtl_getTextureSizeAlign(Renderer* pRenderer, const TextureDesc* pDesc, Reso
ASSERT(pRenderer);
ASSERT(pDesc);
ASSERT(pOut);
const uint32_t pixelFormat = (uint32_t)TinyImageFormat_ToMTLPixelFormat(pDesc->mFormat);
const MTLPixelFormat pixelFormat = (MTLPixelFormat)TinyImageFormat_ToMTLPixelFormat(pDesc->mFormat);

MTLTextureDescriptor* textureDesc = [[MTLTextureDescriptor alloc] init];
initialize_texture_desc(pRenderer, pDesc, false, pixelFormat, textureDesc);
Expand Down Expand Up @@ -4124,11 +4152,12 @@ void mtl_cmdBindRenderTargets(Cmd* pCmd, const BindRenderTargetsDesc* pDesc)
renderPassDesc.depthAttachment.slice = desc->mArraySlice;
}
#ifndef TARGET_IOS
bool isStencilEnabled = desc->pDepthStencil->pTexture->pPixelFormat == MTLPixelFormatDepth24Unorm_Stencil8;
bool isStencilEnabled = desc->pDepthStencil->pTexture->pTexture.pixelFormat == MTLPixelFormatDepth24Unorm_Stencil8;
#else
bool isStencilEnabled = false;
#endif
isStencilEnabled = isStencilEnabled || desc->pDepthStencil->pTexture->pPixelFormat == MTLPixelFormatDepth32Float_Stencil8;
isStencilEnabled =
isStencilEnabled || desc->pDepthStencil->pTexture->pTexture.pixelFormat == MTLPixelFormatDepth32Float_Stencil8;
if (isStencilEnabled)
{
renderPassDesc.stencilAttachment.texture = desc->pDepthStencil->pTexture->pTexture;
Expand Down Expand Up @@ -4368,7 +4397,14 @@ void mtl_cmdBindPipeline(Cmd* pCmd, Pipeline* pPipeline)
util_set_debug_group(pCmd);
if (pCmd->mDebugMarker[0])
{
pCmd->pRenderEncoder.label = [NSString stringWithUTF8String:pCmd->mDebugMarker];
if (pCmd->pRenderEncoder)
{
pCmd->pRenderEncoder.label = [NSString stringWithUTF8String:pCmd->mDebugMarker];
}
if (pCmd->pComputeEncoder)
{
pCmd->pComputeEncoder.label = [NSString stringWithUTF8String:pCmd->mDebugMarker];
}
}
#endif

Expand Down Expand Up @@ -5903,7 +5939,7 @@ void util_unset_debug_group(Cmd* pCmd)
return (MTLCounterResultTimestamp*)(data.bytes);
}

void initialize_texture_desc(Renderer* pRenderer, const TextureDesc* pDesc, const bool isRT, uint32_t pixelFormat,
void initialize_texture_desc(Renderer* pRenderer, const TextureDesc* pDesc, const bool isRT, MTLPixelFormat pixelFormat,
MTLTextureDescriptor* textureDesc)
{
const MemoryType memoryType = isRT ? MEMORY_TYPE_GPU_ONLY_COLOR_RTS : MEMORY_TYPE_GPU_ONLY;
Expand All @@ -5913,7 +5949,7 @@ void initialize_texture_desc(Renderer* pRenderer, const TextureDesc* pDesc, cons
if (!(pDesc->mFlags & (TEXTURE_CREATION_FLAG_FORCE_2D | TEXTURE_CREATION_FLAG_FORCE_3D)) && pDesc->mHeight == 1)
mipLevels = 1;

textureDesc.pixelFormat = (MTLPixelFormat)pixelFormat;
textureDesc.pixelFormat = pixelFormat;
textureDesc.width = pDesc->mWidth;
textureDesc.height = pDesc->mHeight;
textureDesc.depth = pDesc->mDepth;
Expand Down Expand Up @@ -6043,13 +6079,13 @@ void add_texture(Renderer* pRenderer, const TextureDesc* pDesc, Texture** ppText
if (pDesc->mDescriptors & DESCRIPTOR_TYPE_RW_TEXTURE)
pTexture->pUAVDescriptors = (id<MTLTexture> __strong*)mem;

pTexture->pPixelFormat = (uint32_t)TinyImageFormat_ToMTLPixelFormat(pDesc->mFormat);
MTLPixelFormat pixelFormat = (MTLPixelFormat)TinyImageFormat_ToMTLPixelFormat(pDesc->mFormat);

if (pDesc->mFormat == TinyImageFormat_D24_UNORM_S8_UINT &&
!(pRenderer->pGpu->mCapBits.mFormatCaps[pDesc->mFormat] & FORMAT_CAP_RENDER_TARGET))
{
internal_log(eWARNING, "Format D24S8 is not supported on this device. Using D32S8 instead", "addTexture");
pTexture->pPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
pixelFormat = MTLPixelFormatDepth32Float_Stencil8;
((TextureDesc*)pDesc)->mFormat = TinyImageFormat_D32_SFLOAT_S8_UINT;
}

Expand Down Expand Up @@ -6090,7 +6126,7 @@ void add_texture(Renderer* pRenderer, const TextureDesc* pDesc, Texture** ppText

// Create a MTLTextureDescriptor that matches our requirements.
MTLTextureDescriptor* textureDesc = [[MTLTextureDescriptor alloc] init];
initialize_texture_desc(pRenderer, pDesc, isRT, pTexture->pPixelFormat, textureDesc);
initialize_texture_desc(pRenderer, pDesc, isRT, pixelFormat, textureDesc);

// For memoryless textures, we dont need any backing memory
#if defined(ENABLE_MEMORYLESS_TEXTURES)
Expand Down Expand Up @@ -6149,10 +6185,9 @@ void add_texture(Renderer* pRenderer, const TextureDesc* pDesc, Texture** ppText
if (TinyImageFormat_IsDepthAndStencil(pDesc->mFormat))
{
#ifndef TARGET_IOS
pTexture->pStencilTexture =
[pTexture->pTexture newTextureViewWithPixelFormat:(pTexture->pPixelFormat == MTLPixelFormatDepth32Float_Stencil8
? MTLPixelFormatX32_Stencil8
: MTLPixelFormatX24_Stencil8)];
pTexture->pStencilTexture = [pTexture->pTexture
newTextureViewWithPixelFormat:(pixelFormat == MTLPixelFormatDepth32Float_Stencil8 ? MTLPixelFormatX32_Stencil8
: MTLPixelFormatX24_Stencil8)];
#else
pTexture->pStencilTexture = [pTexture->pTexture newTextureViewWithPixelFormat:MTLPixelFormatX32_Stencil8];
#endif
Expand Down Expand Up @@ -6188,7 +6223,6 @@ void add_texture(Renderer* pRenderer, const TextureDesc* pDesc, Texture** ppText
}
}

pTexture->mRT = isRT;
pTexture->mNodeIndex = pDesc->mNodeIndex;
pTexture->mUav = pDesc->mDescriptors & DESCRIPTOR_TYPE_RW_TEXTURE;
pTexture->mMipLevels = pDesc->mMipLevels;
Expand Down
Loading

0 comments on commit 1893c5f

Please sign in to comment.