From d86e95859f3923e1094d2de769308d0e421d5e93 Mon Sep 17 00:00:00 2001 From: Wutipong Wongsakuldej Date: Mon, 13 May 2024 20:24:24 +0700 Subject: [PATCH] Update to The-Forge 1.57 --- CMakeLists.txt | 8 +- The-Forge | 2 +- src/DemoScene.cpp | 436 ++++++++++++++++++++-------------------------- src/MainApp.cpp | 164 ++++++++--------- 4 files changed, 267 insertions(+), 343 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c04f953..dba00fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,12 +263,12 @@ elseif (LINUX) ) endif() -target_compile_features(main PRIVATE cxx_std_20) -set_property(TARGET main PROPERTY CXX_STANDARD 20) +target_compile_features(main PRIVATE cxx_std_17) +set_property(TARGET main PROPERTY CXX_STANDARD 17) set_property(TARGET main PROPERTY CXX_STANDARD_REQUIRED ON) if (MSVC) - # set_property(TARGET main PROPERTY WIN32_EXECUTABLE ON) + add_compile_definitions(D3D12_AGILITY_SDK_VERSION 611) target_compile_options(main PRIVATE /Zc:__cplusplus) endif () @@ -299,7 +299,7 @@ add_custom_target(CopyGpuCfg ALL add_custom_target(CopyFonts ALL COMMAND ${CMAKE_COMMAND} -E make_directory "$/Fonts/TitilliumText/" - COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/The-Forge/Examples_3/Unit_Tests/UnitTestResources/Fonts/TitilliumText/TitilliumText-Bold.otf" "$/Fonts/TitilliumText/" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/The-Forge/Examples_3/Visibility_Buffer/Resources/Fonts/TitilliumText/TitilliumText-Bold.otf" "$/Fonts/TitilliumText/" ) if(WIN32) diff --git a/The-Forge b/The-Forge index fc3cc62..b6c97cd 160000 --- a/The-Forge +++ b/The-Forge @@ -1 +1 @@ -Subproject commit fc3cc62378e4aef17475771a1044d56f244851b3 +Subproject commit b6c97cdc1bef03d2b3a6b286c29b894be48fa9e0 diff --git a/src/DemoScene.cpp b/src/DemoScene.cpp index d05a876..55231eb 100644 --- a/src/DemoScene.cpp +++ b/src/DemoScene.cpp @@ -90,60 +90,54 @@ bool DemoScene::Init(Renderer *pRenderer) SyncToken token{}; uint64_t sphereDataSize = spherePoints * sizeof(float); - BufferLoadDesc sphereVbDesc{ - .ppBuffer = &pBufferSphereVertex, - .pData = sphereVertices, - .mDesc{ - .mSize = sphereDataSize, - .mMemoryUsage = RESOURCE_MEMORY_USAGE_GPU_ONLY, - .mDescriptors = DESCRIPTOR_TYPE_VERTEX_BUFFER, - }, - }; + BufferLoadDesc sphereVbDesc = {}; + sphereVbDesc.ppBuffer = &pBufferSphereVertex; + sphereVbDesc.pData = sphereVertices; + sphereVbDesc.mDesc = {}; + sphereVbDesc.mDesc.mSize = sphereDataSize; + sphereVbDesc.mDesc.mMemoryUsage = RESOURCE_MEMORY_USAGE_GPU_ONLY; + sphereVbDesc.mDesc.mDescriptors = DESCRIPTOR_TYPE_VERTEX_BUFFER; + addResource(&sphereVbDesc, &token); uint64_t quadDataSize = quadPoints * sizeof(float); - BufferLoadDesc quadVbDesc{ - .ppBuffer = &pBufferQuadVertex, - .pData = quadVertices, - .mDesc{ - .mSize = quadDataSize, - .mMemoryUsage = RESOURCE_MEMORY_USAGE_GPU_ONLY, - .mDescriptors = DESCRIPTOR_TYPE_VERTEX_BUFFER, - }, - }; + BufferLoadDesc quadVbDesc = {}; + quadVbDesc.ppBuffer = &pBufferQuadVertex; + quadVbDesc.pData = quadVertices; + quadVbDesc.mDesc = {}; + quadVbDesc.mDesc.mSize = quadDataSize; + quadVbDesc.mDesc.mMemoryUsage = RESOURCE_MEMORY_USAGE_GPU_ONLY; + quadVbDesc.mDesc.mDescriptors = DESCRIPTOR_TYPE_VERTEX_BUFFER; + addResource(&quadVbDesc, &token); - BufferLoadDesc quadIdDesc{ - .ppBuffer = &pBufferQuadIndex, - .pData = quadIndices, - .mDesc{ - .mSize = sizeof(uint16_t) * 6, - .mMemoryUsage = RESOURCE_MEMORY_USAGE_GPU_ONLY, - .mDescriptors = DESCRIPTOR_TYPE_INDEX_BUFFER, - }, - }; + BufferLoadDesc quadIdDesc = {}; + quadIdDesc.ppBuffer = &pBufferQuadIndex; + quadIdDesc.pData = quadIndices; + quadIdDesc.mDesc = {}; + quadIdDesc.mDesc.mSize = sizeof(uint16_t) * 6; + quadIdDesc.mDesc.mMemoryUsage = RESOURCE_MEMORY_USAGE_GPU_ONLY; + quadIdDesc.mDesc.mDescriptors = DESCRIPTOR_TYPE_INDEX_BUFFER; + addResource(&quadIdDesc, &token); - BufferLoadDesc ubDesc = { - .ppBuffer = &pBufferSphereUniform, - .mDesc{ - .mSize = sizeof(SphereUniform), - .mMemoryUsage = RESOURCE_MEMORY_USAGE_CPU_TO_GPU, - .mFlags = BUFFER_CREATION_FLAG_PERSISTENT_MAP_BIT, - .mDescriptors = DESCRIPTOR_TYPE_UNIFORM_BUFFER, - }, - }; + BufferLoadDesc ubDesc = {}; + ubDesc.ppBuffer = &pBufferSphereUniform; + ubDesc.mDesc = {}; + ubDesc.mDesc.mSize = sizeof(SphereUniform); + ubDesc.mDesc.mMemoryUsage = RESOURCE_MEMORY_USAGE_CPU_TO_GPU; + ubDesc.mDesc.mFlags = BUFFER_CREATION_FLAG_PERSISTENT_MAP_BIT; + ubDesc.mDesc.mDescriptors = DESCRIPTOR_TYPE_UNIFORM_BUFFER; addResource(&ubDesc, &token); - BufferLoadDesc quadUniformDesc = { - .ppBuffer = &pBufferQuadUniform, - .mDesc{ - .mSize = sizeof(QuadUniform), - .mMemoryUsage = RESOURCE_MEMORY_USAGE_CPU_TO_GPU, - .mFlags = BUFFER_CREATION_FLAG_PERSISTENT_MAP_BIT, - .mDescriptors = DESCRIPTOR_TYPE_UNIFORM_BUFFER, - }, - }; + BufferLoadDesc quadUniformDesc = {}; + quadUniformDesc.ppBuffer = &pBufferQuadUniform; + quadUniformDesc.mDesc ={}; + quadUniformDesc.mDesc.mSize = sizeof(QuadUniform); + quadUniformDesc.mDesc.mMemoryUsage = RESOURCE_MEMORY_USAGE_CPU_TO_GPU; + quadUniformDesc.mDesc.mFlags = BUFFER_CREATION_FLAG_PERSISTENT_MAP_BIT; + quadUniformDesc.mDesc.mDescriptors = DESCRIPTOR_TYPE_UNIFORM_BUFFER; + addResource(&quadUniformDesc, &token); for (size_t i = 0; i < MAX_SPHERE; i++) @@ -161,12 +155,12 @@ bool DemoScene::Init(Renderer *pRenderer) pCameraController = initFpsCameraController(camPos, lookAt); pCameraController->setMotionParameters(cmp); - SamplerDesc samplerDesc = { - .mMinFilter = FILTER_LINEAR, - .mMagFilter = FILTER_LINEAR, - .mAddressU = ADDRESS_MODE_CLAMP_TO_EDGE, - .mAddressV = ADDRESS_MODE_CLAMP_TO_EDGE, - }; + SamplerDesc samplerDesc = {}; + samplerDesc.mMinFilter = FILTER_LINEAR; + samplerDesc.mMagFilter = FILTER_LINEAR; + samplerDesc.mAddressU = ADDRESS_MODE_CLAMP_TO_EDGE; + samplerDesc.mAddressV = ADDRESS_MODE_CLAMP_TO_EDGE; + addSampler(pRenderer, &samplerDesc, &pSampler); typedef bool (*CameraInputHandler)(InputActionContext *ctx, DefaultInputActions::DefaultInputAction action); @@ -181,12 +175,15 @@ bool DemoScene::Init(Renderer *pRenderer) case DefaultInputActions::ROTATE_CAMERA: pCameraController->onRotate(delta); break; + case DefaultInputActions::TRANSLATE_CAMERA: pCameraController->onMove(delta); break; + case DefaultInputActions::TRANSLATE_CAMERA_VERTICAL: pCameraController->onMoveY(delta[0]); break; + default: break; } @@ -258,34 +255,33 @@ bool DemoScene::Load(ReloadDesc *pReloadDesc, Renderer *pRenderer, RenderTarget if (pReloadDesc->mType & (RELOAD_TYPE_RESIZE | RELOAD_TYPE_RENDERTARGET)) { - RenderTargetDesc desc{ - .mFlags = TEXTURE_CREATION_FLAG_ON_TILE | TEXTURE_CREATION_FLAG_VR_MULTIVIEW, - .mWidth = pRenderTarget->mWidth, - .mHeight = pRenderTarget->mHeight, - .mDepth = 1, - .mArraySize = 1, - .mSampleCount = SAMPLE_COUNT_1, - .mFormat = depthBufferFormat, - .mStartState = RESOURCE_STATE_DEPTH_WRITE, - .mClearValue = {}, - .mSampleQuality = 0, - }; + RenderTargetDesc desc{}; + desc.mFlags = TEXTURE_CREATION_FLAG_ON_TILE | TEXTURE_CREATION_FLAG_VR_MULTIVIEW; + desc.mWidth = pRenderTarget->mWidth; + desc.mHeight = pRenderTarget->mHeight; + desc.mDepth = 1; + desc.mArraySize = 1; + desc.mSampleCount = SAMPLE_COUNT_1; + desc.mFormat = depthBufferFormat; + desc.mStartState = RESOURCE_STATE_DEPTH_WRITE; + desc.mClearValue = {}; + desc.mSampleQuality = 0; + addRenderTarget(pRenderer, &desc, &pRTDepth); ASSERT(pRTDepth); - desc = { - .mFlags = TEXTURE_CREATION_FLAG_OWN_MEMORY_BIT, - .mWidth = SHADOW_MAP_SIZE, - .mHeight = SHADOW_MAP_SIZE, - .mDepth = 1, - .mArraySize = 1, - .mSampleCount = SAMPLE_COUNT_1, - .mFormat = depthBufferFormat, - .mStartState = RESOURCE_STATE_SHADER_RESOURCE, - .mClearValue = {}, - .mSampleQuality = 0, - .mDescriptors = DESCRIPTOR_TYPE_TEXTURE, - }; + desc = {}; + desc.mFlags = TEXTURE_CREATION_FLAG_OWN_MEMORY_BIT; + desc.mWidth = SHADOW_MAP_SIZE; + desc.mHeight = SHADOW_MAP_SIZE; + desc.mDepth = 1; + desc.mArraySize = 1; + desc.mSampleCount = SAMPLE_COUNT_1; + desc.mFormat = depthBufferFormat; + desc.mStartState = RESOURCE_STATE_SHADER_RESOURCE; + desc.mClearValue = {}; + desc.mSampleQuality = 0; + desc.mDescriptors = DESCRIPTOR_TYPE_TEXTURE; addRenderTarget(pRenderer, &desc, &pRTShadowMap); ASSERT(pRTShadowMap); @@ -294,141 +290,121 @@ bool DemoScene::Load(ReloadDesc *pReloadDesc, Renderer *pRenderer, RenderTarget if (pReloadDesc->mType & (RELOAD_TYPE_SHADER | RELOAD_TYPE_RENDERTARGET)) { // layout and pipeline for sphere draw - VertexLayout vertexLayout = { - .mBindings{ - { - .mStride = sizeof(float) * 6, - }, - }, - .mAttribs{ - { - .mSemantic = SEMANTIC_POSITION, - .mFormat = TinyImageFormat_R32G32B32_SFLOAT, - .mBinding = 0, - .mLocation = 0, - .mOffset = 0, - }, - { - .mSemantic = SEMANTIC_NORMAL, - .mFormat = TinyImageFormat_R32G32B32_SFLOAT, - .mBinding = 0, - .mLocation = 1, - .mOffset = 3 * sizeof(float), - }, - }, - .mBindingCount = 1, - .mAttribCount = 2, - }; + VertexLayout vertexLayout = {}; + vertexLayout.mBindingCount = 1; + vertexLayout.mBindings[0].mStride = sizeof(float) * 6; + + vertexLayout.mAttribCount = 2; + vertexLayout.mAttribs[0].mSemantic = SEMANTIC_POSITION; + vertexLayout.mAttribs[0].mFormat = TinyImageFormat_R32G32B32_SFLOAT; + vertexLayout.mAttribs[0].mBinding = 0; + vertexLayout.mAttribs[0].mLocation = 0; + vertexLayout.mAttribs[0].mOffset = 0; + + vertexLayout.mAttribs[1].mSemantic = SEMANTIC_NORMAL; + vertexLayout.mAttribs[1].mFormat = TinyImageFormat_R32G32B32_SFLOAT; + vertexLayout.mAttribs[1].mBinding = 0; + vertexLayout.mAttribs[1].mLocation = 1; + vertexLayout.mAttribs[1].mOffset = 3 * sizeof(float); + RasterizerStateDesc sphereRasterizerStateDesc = {}; sphereRasterizerStateDesc.mCullMode = CULL_MODE_NONE; - DepthStateDesc depthStateDesc{ - .mDepthTest = true, - .mDepthWrite = true, - .mDepthFunc = CMP_GEQUAL, - }; - - PipelineDesc desc = { - .mGraphicsDesc{ - .pShaderProgram = pShaderInstancing, - .pRootSignature = pRSInstancing, - .pVertexLayout = &vertexLayout, - .pDepthState = &depthStateDesc, - .pRasterizerState = &sphereRasterizerStateDesc, - .pColorFormats = &pRenderTarget->mFormat, - .mRenderTargetCount = 1, - .mSampleCount = pRenderTarget->mSampleCount, - .mSampleQuality = pRenderTarget->mSampleQuality, - .mDepthStencilFormat = depthBufferFormat, - .mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST, - .mVRFoveatedRendering = true, - }, - .mType = PIPELINE_TYPE_GRAPHICS, - }; + DepthStateDesc depthStateDesc = {}; + depthStateDesc.mDepthTest = true; + depthStateDesc.mDepthWrite = true; + depthStateDesc.mDepthFunc = CMP_GEQUAL; + + PipelineDesc desc = {}; + desc.mType = PIPELINE_TYPE_GRAPHICS; + + desc.mGraphicsDesc ={}; + desc.mGraphicsDesc.pShaderProgram = pShaderInstancing; + desc.mGraphicsDesc.pRootSignature = pRSInstancing; + desc.mGraphicsDesc.pVertexLayout = &vertexLayout; + desc.mGraphicsDesc.pDepthState = &depthStateDesc; + desc.mGraphicsDesc.pRasterizerState = &sphereRasterizerStateDesc; + desc.mGraphicsDesc.pColorFormats = &pRenderTarget->mFormat; + desc.mGraphicsDesc.mRenderTargetCount = 1; + desc.mGraphicsDesc.mSampleCount = pRenderTarget->mSampleCount; + desc.mGraphicsDesc.mSampleQuality = pRenderTarget->mSampleQuality; + desc.mGraphicsDesc.mDepthStencilFormat = depthBufferFormat; + desc.mGraphicsDesc.mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST; + desc.mGraphicsDesc.mVRFoveatedRendering = true; + + addPipeline(pRenderer, &desc, &pPipelineSphere); ASSERT(pPipelineSphere); - desc = { - .mGraphicsDesc{ - .pShaderProgram = pShaderInstancingShadow, - .pRootSignature = pRSInstancing, - .pVertexLayout = &vertexLayout, - .pDepthState = &depthStateDesc, - .pRasterizerState = &sphereRasterizerStateDesc, - .mSampleCount = pRenderTarget->mSampleCount, - .mSampleQuality = pRenderTarget->mSampleQuality, - .mDepthStencilFormat = depthBufferFormat, - .mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST, - .mVRFoveatedRendering = true, - }, - .mType = PIPELINE_TYPE_GRAPHICS, - }; - + desc = {}; + desc.mType = PIPELINE_TYPE_GRAPHICS; + desc.mGraphicsDesc = {}; + desc.mGraphicsDesc.pShaderProgram = pShaderInstancingShadow; + desc.mGraphicsDesc.pRootSignature = pRSInstancing; + desc.mGraphicsDesc.pVertexLayout = &vertexLayout; + desc.mGraphicsDesc.pDepthState = &depthStateDesc; + desc.mGraphicsDesc.pRasterizerState = &sphereRasterizerStateDesc; + desc.mGraphicsDesc.mSampleCount = pRenderTarget->mSampleCount; + desc.mGraphicsDesc.mSampleQuality = pRenderTarget->mSampleQuality; + desc.mGraphicsDesc.mDepthStencilFormat = depthBufferFormat; + desc.mGraphicsDesc.mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST; + desc.mGraphicsDesc.mVRFoveatedRendering = true; + addPipeline(pRenderer, &desc, &pPipelineSphereShadow); ASSERT(pPipelineSphereShadow); - desc = { - .mGraphicsDesc = - { - .pShaderProgram = pShaderSingle, - .pRootSignature = pRSSingle, - .pVertexLayout = &vertexLayout, - .pDepthState = &depthStateDesc, - .pRasterizerState = &sphereRasterizerStateDesc, - .pColorFormats = &pRenderTarget->mFormat, - .mRenderTargetCount = 1, - .mSampleCount = pRenderTarget->mSampleCount, - .mSampleQuality = pRenderTarget->mSampleQuality, - .mDepthStencilFormat = depthBufferFormat, - .mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST, - .mVRFoveatedRendering = true, - }, - .mType = PIPELINE_TYPE_GRAPHICS, - }; + desc = {}; + desc.mType = PIPELINE_TYPE_GRAPHICS; + desc.mGraphicsDesc ={}; + desc.mGraphicsDesc.pShaderProgram = pShaderSingle; + desc.mGraphicsDesc.pRootSignature = pRSSingle; + desc.mGraphicsDesc.pVertexLayout = &vertexLayout; + desc.mGraphicsDesc.pDepthState = &depthStateDesc; + desc.mGraphicsDesc.pRasterizerState = &sphereRasterizerStateDesc; + desc.mGraphicsDesc.pColorFormats = &pRenderTarget->mFormat; + desc.mGraphicsDesc.mRenderTargetCount = 1; + desc.mGraphicsDesc.mSampleCount = pRenderTarget->mSampleCount; + desc.mGraphicsDesc.mSampleQuality = pRenderTarget->mSampleQuality; + desc.mGraphicsDesc.mDepthStencilFormat = depthBufferFormat; + desc.mGraphicsDesc.mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST; + desc.mGraphicsDesc.mVRFoveatedRendering = true; addPipeline(pRenderer, &desc, &pPipelineQuad); ASSERT(pPipelineQuad); - desc = { - .mGraphicsDesc = - { - .pShaderProgram = pShaderSingleShadow, - .pRootSignature = pRSSingle, - .pVertexLayout = &vertexLayout, - .pDepthState = &depthStateDesc, - .pRasterizerState = &sphereRasterizerStateDesc, - .mSampleCount = pRenderTarget->mSampleCount, - .mSampleQuality = pRenderTarget->mSampleQuality, - .mDepthStencilFormat = depthBufferFormat, - .mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST, - .mVRFoveatedRendering = true, - }, - .mType = PIPELINE_TYPE_GRAPHICS, - }; + desc = {}; + desc.mType = PIPELINE_TYPE_GRAPHICS; + desc.mGraphicsDesc = {}; + desc.mGraphicsDesc.pShaderProgram = pShaderSingleShadow; + desc.mGraphicsDesc.pRootSignature = pRSSingle; + desc.mGraphicsDesc.pVertexLayout = &vertexLayout; + desc.mGraphicsDesc.pDepthState = &depthStateDesc; + desc.mGraphicsDesc.pRasterizerState = &sphereRasterizerStateDesc; + desc.mGraphicsDesc.mSampleCount = pRenderTarget->mSampleCount; + desc.mGraphicsDesc.mSampleQuality = pRenderTarget->mSampleQuality; + desc.mGraphicsDesc.mDepthStencilFormat = depthBufferFormat; + desc.mGraphicsDesc.mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST; + desc.mGraphicsDesc.mVRFoveatedRendering = true; addPipeline(pRenderer, &desc, &pPipelineQuadShadow); ASSERT(pPipelineQuadShadow); } - DescriptorData params = { - .pName = "uniformBlock", - .ppBuffers = &pBufferSphereUniform, - }; - + DescriptorData params = {}; + params.pName = "uniformBlock"; + params.ppBuffers = &pBufferSphereUniform; updateDescriptorSet(pRenderer, 0, pDSSphereUniform, 1, ¶ms); - params = { - .pName = "uniformBlock", - .ppBuffers = &pBufferQuadUniform, - }; + params = {}; + params.pName = "uniformBlock"; + params.ppBuffers = &pBufferQuadUniform; updateDescriptorSet(pRenderer, 0, pDSQuadUniform, 1, ¶ms); - params = { - .pName = "lightMap", - .ppTextures = &pRTShadowMap->pTexture, - }; + params = {}; + params.pName = "lightMap"; + params.ppTextures = &pRTShadowMap->pTexture; updateDescriptorSet(pRenderer, 0, pDSShadowMap, 1, ¶ms); return true; @@ -436,38 +412,23 @@ bool DemoScene::Load(ReloadDesc *pReloadDesc, Renderer *pRenderer, RenderTarget void DemoScene::AddSphereResources(Renderer *pRenderer) { - ShaderLoadDesc shaderDesc{ - .mStages{ - { - .pFileName = "sphere.vert", - }, - { - .pFileName = "basic.frag", - }, - }, - }; + ShaderLoadDesc shaderDesc{}; + shaderDesc.mStages[0].pFileName = "sphere.vert"; + shaderDesc.mStages[1].pFileName = "basic.frag"; addShader(pRenderer, &shaderDesc, &pShaderInstancing); ASSERT(pShaderInstancing); - shaderDesc = { - .mStages{ - { - .pFileName = "sphere_shadow.vert", - }, - { - .pFileName = "shadow.frag", - }, - }, - }; + shaderDesc = {}; + shaderDesc.mStages[0].pFileName = "sphere_shadow.vert"; + shaderDesc.mStages[1].pFileName = "shadow.frag"; addShader(pRenderer, &shaderDesc, &pShaderInstancingShadow); ASSERT(pShaderInstancingShadow); std::array shaders = {pShaderInstancing, pShaderInstancingShadow}; - RootSignatureDesc rootDesc{ - .ppShaders = shaders.data(), - .mShaderCount = shaders.size(), - }; + RootSignatureDesc rootDesc = {}; + rootDesc.ppShaders = shaders.data(); + rootDesc.mShaderCount = shaders.size(); addRootSignature(pRenderer, &rootDesc, &pRSInstancing); ASSERT(pRSInstancing); @@ -479,39 +440,22 @@ void DemoScene::AddSphereResources(Renderer *pRenderer) void DemoScene::AddQuadResources(Renderer *pRenderer) { - ShaderLoadDesc shaderDesc{ - .mStages{ - { - .pFileName = "quad.vert", - }, - { - .pFileName = "basic.frag", - }, - }, - }; - + ShaderLoadDesc shaderDesc{}; + shaderDesc.mStages[0].pFileName = "quad.vert"; + shaderDesc.mStages[1].pFileName = "basic.frag"; addShader(pRenderer, &shaderDesc, &pShaderSingle); ASSERT(pShaderSingle); - shaderDesc = { - .mStages{ - { - .pFileName = "quad_shadow.vert", - }, - { - .pFileName = "shadow.frag", - }, - }, - }; - + shaderDesc = {}; + shaderDesc.mStages[0].pFileName = "quad_shadow.vert"; + shaderDesc.mStages[1].pFileName = "shadow.frag"; addShader(pRenderer, &shaderDesc, &pShaderSingleShadow); ASSERT(pShaderSingleShadow); std::array shaders = {pShaderSingle, pShaderSingleShadow}; - RootSignatureDesc rootDesc{ - .ppShaders = shaders.data(), - .mShaderCount = shaders.size(), - }; + RootSignatureDesc rootDesc{}; + rootDesc.ppShaders = shaders.data(); + rootDesc.mShaderCount = shaders.size(); addRootSignature(pRenderer, &rootDesc, &pRSSingle); ASSERT(pRSSingle); @@ -614,10 +558,8 @@ void DemoScene::Draw(Cmd *pCmd, Renderer *pRenderer, RenderTarget *pRenderTarget } { - BindRenderTargetsDesc bindRenderTargets = { - .mDepthStencil = {pRTShadowMap, LOAD_ACTION_CLEAR}, - }; - + BindRenderTargetsDesc bindRenderTargets = {}; + bindRenderTargets.mDepthStencil = {pRTShadowMap, LOAD_ACTION_CLEAR}; cmdBindRenderTargets(pCmd, &bindRenderTargets); } cmdSetViewport(pCmd, 0.0f, 0.0f, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, 0.0f, 1.0f); @@ -642,14 +584,10 @@ void DemoScene::Draw(Cmd *pCmd, Renderer *pRenderer, RenderTarget *pRenderTarget cmdResourceBarrier(pCmd, 0, nullptr, 0, nullptr, 1, barriers); } - BindRenderTargetsDesc bindRenderTargets = { - .mRenderTargetCount = 1, - .mRenderTargets = - { - {pRenderTarget, LOAD_ACTION_CLEAR}, - }, - .mDepthStencil = {pRTDepth, LOAD_ACTION_CLEAR}, - }; + BindRenderTargetsDesc bindRenderTargets = {}; + bindRenderTargets.mRenderTargetCount = 1; + bindRenderTargets.mRenderTargets[0] = {pRenderTarget, LOAD_ACTION_CLEAR}; + bindRenderTargets.mDepthStencil = {pRTDepth, LOAD_ACTION_CLEAR}, cmdBindRenderTargets(pCmd, &bindRenderTargets); cmdSetViewport(pCmd, 0.0f, 0.0f, (float)pRenderTarget->mWidth, (float)pRenderTarget->mHeight, 0.0f, 1.0f); diff --git a/src/MainApp.cpp b/src/MainApp.cpp index e33f5e4..a81d185 100644 --- a/src/MainApp.cpp +++ b/src/MainApp.cpp @@ -66,10 +66,9 @@ bool MainApp::Init() fsSetPathForResourceDir(pSystemFileIO, RM_CONTENT, RD_SCRIPTS, "Scripts"); // window and renderer setup - RendererDesc settings{ - .mD3D11Supported = false, - .mGLESSupported = false, - }; + RendererDesc settings{}; + settings.mD3D11Supported = false; + settings.mGLESSupported = false; initRenderer(GetName(), &settings, &pRenderer); if (!pRenderer) @@ -77,18 +76,15 @@ bool MainApp::Init() return false; } - QueueDesc queueDesc = { - .mType = QUEUE_TYPE_GRAPHICS, - .mFlag = QUEUE_FLAG_INIT_MICROPROFILE, - }; + QueueDesc queueDesc = {}; + queueDesc.mType = QUEUE_TYPE_GRAPHICS; + queueDesc.mFlag = QUEUE_FLAG_INIT_MICROPROFILE; addQueue(pRenderer, &queueDesc, &pGraphicsQueue); - GpuCmdRingDesc cmdRingDesc = { - .pQueue = pGraphicsQueue, - .mPoolCount = gDataBufferCount, - .mCmdPerPoolCount = 1, - .mAddSyncPrimitives = true, - }; + GpuCmdRingDesc cmdRingDesc = {}; + cmdRingDesc.pQueue = pGraphicsQueue, cmdRingDesc.mPoolCount = gDataBufferCount, cmdRingDesc.mCmdPerPoolCount = 1, + cmdRingDesc.mAddSyncPrimitives = true, + addGpuCmdRing(pRenderer, &cmdRingDesc, &gGraphicsCmdRing); addSemaphore(pRenderer, &pImageAcquiredSemaphore); @@ -96,38 +92,34 @@ bool MainApp::Init() initResourceLoaderInterface(pRenderer); // Initialize micro profiler and its UI. - ProfilerDesc profiler = { - .pRenderer = pRenderer, - .mWidthUI = static_cast(mSettings.mWidth), - .mHeightUI = static_cast(mSettings.mHeight), - }; + ProfilerDesc profiler = {}; + profiler.pRenderer = pRenderer; + profiler.mWidthUI = static_cast(mSettings.mWidth); + profiler.mHeightUI = static_cast(mSettings.mHeight); + initProfiler(&profiler); // Gpu profiler can only be added after initProfile. gGpuProfileToken = addGpuProfiler(pRenderer, pGraphicsQueue, "Graphics"); // Load fonts - FontDesc font = { - .pFontPath = "TitilliumText/TitilliumText-Bold.otf", - }; - fntDefineFonts(&font, 1, &gFontID); + FontDesc font = {}; + font.pFontPath = "TitilliumText/TitilliumText-Bold.otf", fntDefineFonts(&font, 1, &gFontID); + + FontSystemDesc fontRenderDesc = {}; + fontRenderDesc.pRenderer = pRenderer; - FontSystemDesc fontRenderDesc = { - .pRenderer = pRenderer, - }; if (!initFontSystem(&fontRenderDesc)) { return false; } - UserInterfaceDesc uiRenderDesc = { - .pRenderer = pRenderer, - }; + UserInterfaceDesc uiRenderDesc = {}; + uiRenderDesc.pRenderer = pRenderer; initUserInterface(&uiRenderDesc); - UIComponentDesc guiDesc = { - .mStartPosition = vec2(mSettings.mWidth * 0.01f, mSettings.mHeight * 0.2f), - }; + UIComponentDesc guiDesc = {}; + guiDesc.mStartPosition = vec2(mSettings.mWidth * 0.01f, mSettings.mHeight * 0.2f); uiCreateComponent(GetName(), &guiDesc, &pGuiWindow); // Take a screenshot with a button. @@ -136,10 +128,10 @@ bool MainApp::Init() waitForAllResourceLoads(); - InputSystemDesc inputDesc{ - .pRenderer = pRenderer, - .pWindow = pWindow, - }; + InputSystemDesc inputDesc = {}; + inputDesc.pRenderer = pRenderer; + inputDesc.pWindow = pWindow; + if (!initInputSystem(&inputDesc)) { return false; @@ -186,18 +178,18 @@ bool MainApp::Load(ReloadDesc *pReloadDesc) { if (pReloadDesc->mType & (RELOAD_TYPE_RESIZE | RELOAD_TYPE_RENDERTARGET)) { - SwapChainDesc swapChainDesc = { - .mWindowHandle = pWindow->handle, - .ppPresentQueues = &pGraphicsQueue, - .mPresentQueueCount = 1, - .mImageCount = getRecommendedSwapchainImageCount(pRenderer, &pWindow->handle), - .mWidth = static_cast(mSettings.mWidth), - .mHeight = static_cast(mSettings.mHeight), - .mColorFormat = getSupportedSwapchainFormat(pRenderer, &swapChainDesc, COLOR_SPACE_SDR_SRGB), - .mFlags = SWAP_CHAIN_CREATION_FLAG_ENABLE_FOVEATED_RENDERING_VR, - .mEnableVsync = mSettings.mVSyncEnabled, - .mColorSpace = COLOR_SPACE_SDR_SRGB, - }; + SwapChainDesc swapChainDesc = {}; + swapChainDesc.mWindowHandle = pWindow->handle; + swapChainDesc.ppPresentQueues = &pGraphicsQueue; + swapChainDesc.mPresentQueueCount = 1; + swapChainDesc.mImageCount = getRecommendedSwapchainImageCount(pRenderer, &pWindow->handle); + swapChainDesc.mWidth = static_cast(mSettings.mWidth); + swapChainDesc.mHeight = static_cast(mSettings.mHeight); + swapChainDesc.mColorFormat = getSupportedSwapchainFormat(pRenderer, &swapChainDesc, COLOR_SPACE_SDR_SRGB); + swapChainDesc.mFlags = SWAP_CHAIN_CREATION_FLAG_ENABLE_FOVEATED_RENDERING_VR; + swapChainDesc.mEnableVsync = mSettings.mVSyncEnabled; + swapChainDesc.mColorSpace = COLOR_SPACE_SDR_SRGB; + addSwapChain(pRenderer, &swapChainDesc, &pSwapChain); if (pSwapChain == nullptr) @@ -206,20 +198,18 @@ bool MainApp::Load(ReloadDesc *pReloadDesc) } } - FontSystemLoadDesc fontLoad = { - .mLoadType = pReloadDesc->mType, - .mColorFormat = static_cast(pSwapChain->ppRenderTargets[0]->mFormat), - .mWidth = static_cast(mSettings.mWidth), - .mHeight = static_cast(mSettings.mHeight), - }; + FontSystemLoadDesc fontLoad = {}; + fontLoad.mLoadType = pReloadDesc->mType; + fontLoad.mColorFormat = static_cast(pSwapChain->ppRenderTargets[0]->mFormat); + fontLoad.mWidth = static_cast(mSettings.mWidth); + fontLoad.mHeight = static_cast(mSettings.mHeight); loadFontSystem(&fontLoad); - UserInterfaceLoadDesc uiLoad = { - .mLoadType = static_cast(pReloadDesc->mType), - .mColorFormat = static_cast(pSwapChain->ppRenderTargets[0]->mFormat), - .mWidth = static_cast(mSettings.mWidth), - .mHeight = static_cast(mSettings.mHeight), - }; + UserInterfaceLoadDesc uiLoad = {}; + uiLoad.mLoadType = static_cast(pReloadDesc->mType); + uiLoad.mColorFormat = static_cast(pSwapChain->ppRenderTargets[0]->mFormat); + uiLoad.mWidth = static_cast(mSettings.mWidth); + uiLoad.mHeight = static_cast(mSettings.mHeight); loadUserInterface(&uiLoad); initScreenshotInterface(pRenderer, pGraphicsQueue); @@ -301,20 +291,19 @@ void MainApp::Draw() cmdSetViewport(cmd, 0, 0, (float)pRenderTarget->mWidth, (float)pRenderTarget->mHeight, 0.0f, 1.0f); cmdSetScissor(cmd, 0, 0, pRenderTarget->mWidth, pRenderTarget->mHeight); - BindRenderTargetsDesc bindRenderTargets = { - .mRenderTargetCount = 1, - .mRenderTargets = {{pRenderTarget, LOAD_ACTION_LOAD}}, - }; + BindRenderTargetsDesc bindRenderTargets = {}; + bindRenderTargets.mRenderTargetCount = 1; + bindRenderTargets.mRenderTargets[0] = {pRenderTarget, LOAD_ACTION_LOAD}; cmdBindRenderTargets(cmd, &bindRenderTargets); cmdBeginGpuTimestampQuery(cmd, gGpuProfileToken, "Draw UI"); - FontDrawDesc gFrameTimeDraw{ - .mFontID = gFontID, - .mFontColor = 0xff00ffff, - .mFontSize = 18.0f, - }; + FontDrawDesc gFrameTimeDraw = {}; + gFrameTimeDraw.mFontID = gFontID; + gFrameTimeDraw.mFontColor = 0xff00ffff; + gFrameTimeDraw.mFontSize = 18.0f; + float2 txtSizePx = cmdDrawCpuProfile(cmd, float2(8.f, 15.f), &gFrameTimeDraw); cmdDrawGpuProfile(cmd, float2(8.f, txtSizePx.y + 75.f), gGpuProfileToken, &gFrameTimeDraw); @@ -333,9 +322,8 @@ void MainApp::Draw() cmdEndGpuFrameProfile(cmd, gGpuProfileToken); endCmd(cmd); - FlushResourceUpdateDesc flushUpdateDesc = { - .mNodeIndex = 0, - }; + FlushResourceUpdateDesc flushUpdateDesc = {}; + flushUpdateDesc.mNodeIndex = 0; flushResourceUpdates(&flushUpdateDesc); Semaphore *waitSemaphores[2] = { @@ -343,26 +331,24 @@ void MainApp::Draw() pImageAcquiredSemaphore, }; - QueueSubmitDesc submitDesc = { - .ppCmds = &cmd, - .pSignalFence = elem.pFence, - .ppWaitSemaphores = waitSemaphores, - .ppSignalSemaphores = &elem.pSemaphore, - .mCmdCount = 1, - .mWaitSemaphoreCount = 2, - .mSignalSemaphoreCount = 1, - }; + QueueSubmitDesc submitDesc = {}; + submitDesc.ppCmds = &cmd; + submitDesc.pSignalFence = elem.pFence; + submitDesc.ppWaitSemaphores = waitSemaphores; + submitDesc.ppSignalSemaphores = &elem.pSemaphore; + submitDesc.mCmdCount = 1; + submitDesc.mWaitSemaphoreCount = 2; + submitDesc.mSignalSemaphoreCount = 1; queueSubmit(pGraphicsQueue, &submitDesc); - QueuePresentDesc presentDesc = { - .pSwapChain = pSwapChain, - .ppWaitSemaphores = waitSemaphores, - .mWaitSemaphoreCount = 2, - .mIndex = static_cast(swapchainImageIndex), - .mSubmitDone = true, - }; + QueuePresentDesc presentDesc = {}; + presentDesc.pSwapChain = pSwapChain; + presentDesc.ppWaitSemaphores = waitSemaphores; + presentDesc.mWaitSemaphoreCount = 2; + presentDesc.mIndex = static_cast(swapchainImageIndex); + presentDesc.mSubmitDone = true; queuePresent(pGraphicsQueue, &presentDesc); - + flipProfiler(); }