### Initialize Diligent Engine with OpenXR Attributes (Vulkan Example) Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial28_HelloOpenXR/readme.md Set the pointer to the prepared OpenXRAttribs structure in the engine creation info and then create the Diligent Engine device and immediate context. This example uses the Vulkan factory. ```cpp EngineVkCreateInfo EngineCI; EngineCI.pXRAttribs = &XRAttribs; pFactoryVk->CreateDeviceAndContextsVk(EngineCI, &pDevice, &m_pImmediateContext); ``` -------------------------------- ### Project Setup and Source Files Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Samples/Asteroids/CMakeLists.txt Defines the minimum CMake version, project name, and lists all source files for the Asteroids project. ```cmake cmake_minimum_required (VERSION 3.10) project(Asteroids CXX) set(SOURCE src/asteroids_d3d11.cpp src/asteroids_d3d12.cpp src/asteroids_DE.cpp src/camera.cpp src/DDSTextureLoader.cpp src/mesh.cpp src/simplexnoise1234.c src/simulation.cpp src/texture.cpp src/WinWrapper.cpp ) ``` -------------------------------- ### Shader Compilation Setup Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Samples/Asteroids/CMakeLists.txt Configures the output directory for compiled shaders and creates it if it doesn't exist. ```cmake set(COMPILED_SHADERS_DIR ${CMAKE_CURRENT_BINARY_DIR}/CompiledShaders) file(MAKE_DIRECTORY "${COMPILED_SHADERS_DIR}") ``` -------------------------------- ### C++ Execute Ray Tracing Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial21_RayTracing/readme.md Start the ray tracing process using the TraceRays device context method with the defined attributes. ```cpp m_pImmediateContext->TraceRays(Attribs); ``` -------------------------------- ### Start Worker Threads Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial06_Multithreading/readme.md Main thread signals worker threads to start rendering their subsets. Ensure all threads are ready before proceeding. ```cpp m_NumThreadsCompleted.store(0); m_RenderSubsetSignal.Trigger(true); ``` -------------------------------- ### Metal RayQuery Wrapper Example (Objective-C/MetalSL) Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial22_HybridRendering/readme.md Illustrates how a Metal ray tracing wrapper emulates `RayQuery` functionality using `MTLAccelerationStructureInstanceDescriptor` to access instance data. ```metal const device MTLAccelerationStructureInstanceDescriptor* g_TLASInstances [[buffer(0)]] ... // in RayQuery structure uint CommittedInstanceIndex() { return g_TLASInstances[m_LastIntersection.instance_id].accelerationStructureIndex; } uint CommittedInstanceContributionToHitGroupIndex() { return g_TLASInstances[m_LastIntersection.instance_id].intersectionFunctionTableOffset; } float4x3 CommittedObjectToWorld4x3() { return g_TLASInstances[m_LastIntersection.instance_id].transformationMatrix; } ``` -------------------------------- ### Example Command Line for Screen Capture Source: https://github.com/diligentgraphics/diligentsamples/blob/master/README.md Use this command line to enable screen capture for recording multiple frames. It specifies the rendering mode, capture path, FPS, file name, dimensions, and image format. ```bash --mode d3d12 --capture_path . --capture_fps 15 --capture_name frame --width 640 --height 480 --capture_format png --capture_frames 50 ``` -------------------------------- ### Initial Resource State Transitions Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial19_RenderPasses/readme.md Transition all necessary resources to their correct states before starting a render pass. Use RESOURCE_STATE_TRANSITION_MODE_VERIFY for subsequent calls within the render pass. ```cpp StateTransitionDesc Barriers[] = { {m_pShaderConstantsCB, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_CONSTANT_BUFFER, true}, {m_CubeVertexBuffer, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_VERTEX_BUFFER, true}, {m_CubeIndexBuffer, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_INDEX_BUFFER, true}, {m_pLightsBuffer, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_VERTEX_BUFFER, true}, {m_CubeTextureSRV->GetTexture(), RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_SHADER_RESOURCE, true} // }; m_pImmediateContext->TransitionResourceStates(_countof(Barriers), Barriers); ``` -------------------------------- ### Build for visionOS Simulator with CMake Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial30_HelloVisionOS/readme.md Configures and builds the project for the visionOS simulator using CMake. Ensure Xcode 16+ and CMake 3.28+ are installed. ```bash cmake -S . -B build/visionOS -G Xcode \ -DCMAKE_SYSTEM_NAME=visionOS \ -DCMAKE_OSX_SYSROOT=xrsimulator \ -DCMAKE_BUILD_TYPE=Debug cmake --build build/visionOS --config Debug --target Tutorial30_HelloVisionOS \ -- CODE_SIGN_IDENTITY="" CODE_SIGNING_ALLOWED=NO ``` -------------------------------- ### Setup Metal Layer on macOS Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Samples/GLFWDemo/readme.md Configures a `CAMetalLayer` for a given NSWindow's content view on macOS. This allows Metal to render directly into the window. Ensure QuartzCore framework is available. ```cpp void* GetNSWindowView(GLFWwindow* wnd) { id Window = glfwGetCocoaWindow(wnd); id View = [Window contentView]; NSBundle* bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/QuartzCore.framework"]; if (!bundle) return nullptr; id Layer = [[bundle classNamed:@"CAMetalLayer"] layer]; if (!Layer) return nullptr; [View setLayer:Layer]; [View setWantsLayer:YES]; return View; } ``` -------------------------------- ### Bind Secondary Swap Chain Render Targets Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial15_MultipleWindows/readme.md Use `ISwapChain::GetCurrentBackBufferRTV()` and `ISwapChain::GetDepthBufferDSV()` to get texture views for rendering to a secondary swap chain's buffers. Ensure correct resource state transitions. ```cpp ITextureView* pRTV = pSwapChain->GetCurrentBackBufferRTV(); ITextureView* pDSV = pSwapChain->GetDepthBufferDSV(); m_pImmediateContext->SetRenderTargets(1, &pRTV, pDSV, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); ``` -------------------------------- ### Add Sample Application with Sources and Assets Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial03_Texturing-C/CMakeLists.txt Configures the build system to include the sample application, its source files, header files, shaders, and assets. ```cmake cmake_minimum_required (VERSION 3.10) project(Tutorial03_Texturing-C CXX) add_sample_app(Tutorial03_Texturing-C IDE_FOLDER DiligentSamples/Tutorials SOURCES src/Tutorial03_Texturing-C.cpp src/Tutorial03_Texturing.c INCLUDES src/Tutorial03_Texturing-C.hpp SHADERS assets/cube.vsh assets/cube.psh ASSETS assets/DGLogo.png ) ``` -------------------------------- ### Set up Project and Sources Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial25_StatePackager/CMakeLists.txt Configures the CMake project, defines source files, include directories, and shader assets. This sets up the basic structure for the application. ```cmake cmake_minimum_required (VERSION 3.10) project(Tutorial25_StatePackager CXX) set(SOURCE src/Tutorial25_StatePackager.cpp ) set(INCLUDE src/Tutorial25_StatePackager.hpp ) set(PSO_ARCHIVE ${CMAKE_CURRENT_SOURCE_DIR}/assets/StateArchive.bin) # NB: we must use the full path, otherwise the build system will not be able to properly detect # changes and PSO packaging custom command will run every time set_source_files_properties(${PSO_ARCHIVE} PROPERTIES GENERATED TRUE) set(SHADERS assets/screen_tri.vsh assets/g_buffer.psh assets/resolve.psh assets/path_trace.psh assets/RenderStates.json assets/structures.fxh assets/scene.fxh assets/hash.fxh ) set(ASSETS ${PSO_ARCHIVE}) add_sample_app("Tutorial25_StatePackager" IDE_FOLDER "DiligentSamples/Tutorials" SOURCES ${SOURCE} INCLUDES ${INCLUDE} SHADERS ${SHADERS} ASSETS ${ASSETS} ) ``` -------------------------------- ### Configure Project and Add Sample App Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial28_HelloOpenXR/CMakeLists.txt Sets the minimum CMake version, names the project, and defines the sample application with its sources, includes, and shaders. ```cmake cmake_minimum_required (VERSION 3.10) project(Tutorial28_HelloOpenXR CXX) add_sample_app(Tutorial28_HelloOpenXR IDE_FOLDER DiligentSamples/Tutorials SOURCES src/Tutorial28_HelloOpenXR.cpp ../Common/src/TexturedCube.cpp INCLUDES ../Common/src/TexturedCube.hpp SHADERS assets/cube.vsh assets/cube.psh assets/shader_constants.h ) ``` -------------------------------- ### Define Subpasses Array Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial19_RenderPasses/readme.md Declare an array to hold the subpass descriptions for the render pass. This example defines two subpasses. ```cpp constexpr Uint32 NumSubpasses = 2; SubpassDesc Subpasses[NumSubpasses]; ``` -------------------------------- ### Initialize Vertex Shader Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial02_Cube/readme.md Configure and create a vertex shader, specifying its type, entry point, name, and source file path. ```cpp ShaderCI.Desc.ShaderType = SHADER_TYPE_VERTEX; ShaderCI.EntryPoint = "main"; ShaderCI.Desc.Name = "Cube VS"; ShaderCI.FilePath = "cube.vsh"; pDevice->CreateShader(ShaderCI, &pVS); ``` -------------------------------- ### Cube Data Structure Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial20_MeshShader/readme.md Defines the structure for cube-specific data, primarily used for frustum culling. Only the sphere radius is relevant for this example. ```hlsl struct CubeData { float4 SphereRadius; ... }; cbuffer cbCubeData { CubeData g_CubeData; } ``` -------------------------------- ### Enumerate Graphics Adapters and Select Best Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial23_CommandQueues/readme.md Enumerates available graphics adapters and selects the one with the most command queues. This is a prerequisite for setting up multiple command queues. ```cpp std::vector Adapters; Uint32 NumAdapters = 0; pEngineFactory->EnumerateAdapters(EngineCI.GraphicsAPIVersion, NumAdapters, 0); if (NumAdapters > 0) { Adapters.resize(NumAdapters); pEngineFactory->EnumerateAdapters(EngineCI.GraphicsAPIVersion, NumAdapters, Adapters.data()); EngineCI.AdapterId = 0; Uint32 NumQueues = 0; for (Uint32 AdapterId = 0; AdapterId < NumAdapters; ++AdapterId) { GraphicsAdapterInfo& Adapter = Adapters[AdapterId]; if (Adapter.NumQueues > NumQueues) { EngineCI.AdapterId = AdapterId; NumQueues = Adapter.NumQueues; } } } ``` -------------------------------- ### Particle Collision Shader - Get Grid Location Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial14_ComputeShader/readme.md Calculates the grid location for a given particle based on its position and grid dimensions. ```hlsl int iParticleIdx = int(uiGlobalThreadIdx); ParticleAttribs Particle = g_Particles[iParticleIdx]; int2 i2GridPos = GetGridLocation(Particle.f2Pos, g_Constants.i2ParticleGridSize).xy; int GridWidth = g_Constants.i2ParticleGridSize.x; int GridHeight = g_Constants.i2ParticleGridSize.y; ``` -------------------------------- ### Link Libraries for OpenXR Tutorial Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial28_HelloOpenXR/CMakeLists.txt Links the required libraries for the Tutorial28_HelloOpenXR target, including OpenXR loader and other Diligent-related libraries. ```cmake target_link_libraries(Tutorial28_HelloOpenXR PRIVATE Diligent-Common Diligent-GraphicsTools Diligent-GraphicsAccessories Diligent-TextureLoader openxr_loader ) ``` -------------------------------- ### Get Primitive Vertex Indices Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial21_RayTracing/readme.md Retrieves the indices of the three vertices forming the current primitive using the PrimitiveIndex() function and a constant buffer. ```hlsl uint3 primitive = g_CubeAttribsCB.Primitives[PrimitiveIndex()].xyz; ``` -------------------------------- ### C++ Bind Shader Resources Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial21_RayTracing/readme.md Bind shader resources to the SRB by getting the variable by name for specific shader stages and setting the resource. ```cpp m_pRayTracingSRB->GetVariableByName(SHADER_TYPE_RAY_GEN, "g_ConstantsCB")->Set(m_ConstantsCB); m_pRayTracingSRB->GetVariableByName(SHADER_TYPE_RAY_CLOSEST_HIT, "g_ConstantsCB")->Set(m_ConstantsCB); ``` -------------------------------- ### Get Native Window Handles (macOS) Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Samples/GLFWDemo/readme.md Retrieves the native macOS window view for rendering. This is a prerequisite for setting up Metal rendering layers. ```cpp #if PLATFORM_MACOS MacOSNativeWindow Window{GetNSWindowView(m_Window)}; #endif ``` -------------------------------- ### Create Shader Binding Table Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial21_RayTracing/readme.md Initialize and create the Shader Binding Table (SBT) using the provided pipeline state. ```cpp ShaderBindingTableDesc SBTDesc; SBTDesc.Name = "SBT"; SBTDesc.pPSO = m_pRayTracingPSO; m_pDevice->CreateSBT(SBTDesc, &m_pSBT); ``` -------------------------------- ### Using Query Helpers for GPU Statistics Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial18_Queries/readme.md Demonstrates the usage of ScopedQueryHelper and DurationQueryHelper for collecting pipeline statistics, occlusion data, and command execution duration. Ensure query helpers are initialized and the immediate context is valid. ```cpp std::unique_ptr m_pPipelineStatsQuery; std::unique_ptr m_pOcclusionQuery; std::unique_ptr m_pDurationQuery; // ... m_pPipelineStatsQuery->Begin(m_pImmediateContext); m_pOcclusionQuery->Begin(m_pImmediateContext); m_pDurationQuery->Begin(m_pImmediateContext); m_pImmediateContext->DrawIndexed(DrawAttrs); m_pDurationQuery->End(m_pImmediateContext, m_RenderDuration); m_pOcclusionQuery->End(m_pImmediateContext, &m_OcclusionData, sizeof(m_OcclusionData)); m_pPipelineStatsQuery->End(m_pImmediateContext, &m_PipelineStatsData, sizeof(m_PipelineStatsData)); ``` -------------------------------- ### Get Primary Ray from G-Buffer Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial25_StatePackager/readme.md Reads the G-buffer to reconstruct attributes for the primary camera ray. Requires G-buffer data and pixel screen coordinates. ```hlsl HitInfo Hit0; RayInfo Ray0; GetPrimaryRay(uint2(PSIn.Pos.xy), Hit0, Ray0); ``` -------------------------------- ### Define add_sample_app CMake Macro Source: https://github.com/diligentgraphics/diligentsamples/blob/master/CMakeLists.txt This macro simplifies the creation of sample applications by abstracting common build configurations. It accepts application name, sources, includes, shaders, assets, and IDE folder as arguments. ```cmake function(add_sample_app APP_NAME) set(options) set(oneValueArgs IDE_FOLDER DXC_REQUIRED) set(multiValueArgs SOURCES INCLUDES SHADERS ASSETS) cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${oneValueArgs}" "${multiValueArgs}") if (arg_DXC_REQUIRED) set(DXC_REQUIRED ${arg_DXC_REQUIRED}) else() set(DXC_REQUIRED NO) endif() set_source_files_properties(${arg_SHADERS} PROPERTIES VS_TOOL_OVERRIDE "None") set(ALL_ASSETS ${arg_ASSETS} ${arg_SHADERS}) add_target_platform_app(${APP_NAME} "${arg_SOURCES}" "${arg_INCLUDES}" "${ALL_ASSETS}") set_source_files_properties(${ALL_ASSETS} PROPERTIES VS_DEPLOYMENT_LOCATION "." MACOSX_PACKAGE_LOCATION "Resources" ) if(PLATFORM_WIN32) set_target_properties(${APP_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets" ) copy_required_dlls(${APP_NAME} DXC_REQUIRED ${DXC_REQUIRED}) append_sample_base_win32_source(${APP_NAME}) elseif(PLATFORM_UNIVERSAL_WINDOWS) append_sample_base_uwp_source(${APP_NAME}) package_required_dlls(${APP_NAME} DXC_REQUIRED ${DXC_REQUIRED}) endif() target_include_directories(${APP_NAME} PRIVATE src ) target_link_libraries(${APP_NAME} PRIVATE # On Linux we must have Diligent-NativeAppBase go first, otherwise the linker # will fail to resolve Diligent::CreateApplication() function. Diligent-NativeAppBase Diligent-BuildSettings Diligent-SampleBase ) set_common_target_properties(${APP_NAME}) if(MSVC) # Disable MSVC-specific warnings # - w4201: nonstandard extension used: nameless struct/union target_compile_options(${APP_NAME} PRIVATE /wd4201) endif() if(arg_IDE_FOLDER) set_target_properties(${APP_NAME} PROPERTIES FOLDER ${arg_IDE_FOLDER} ) endif() source_group("src" FILES ${arg_SOURCES} ${arg_INCLUDES}) source_group("assets" FILES ${ALL_ASSETS}) target_sources(${APP_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/readme.md") set_source_files_properties( "${CMAKE_CURRENT_SOURCE_DIR}/readme.md" PROPERTIES HEADER_FILE_ONLY TRUE ) if(PLATFORM_WIN32 OR PLATFORM_LINUX) # Copy assets to target folder add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/assets" "$<$" ) endif() if(PLATFORM_MACOS AND VULKAN_LIB_PATH) # Configure rpath so that executables can find vulkan library set_target_properties(${APP_NAME} PROPERTIES BUILD_RPATH "${VULKAN_LIB_PATH}" ) endif() if(PLATFORM_WEB) set(RESOURCE_PATH "${PROJECT_SOURCE_DIR}/assets/") target_link_options(${APP_NAME} PRIVATE "SHELL: -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4GB --preload-file ${RESOURCE_PATH}@") if (${APP_NAME} STREQUAL "GLTFViewer") set(EXCLUDE_DIRECTORIES ".git" "BarbieDodgePickup" "IridescentDishWithOlives" ) foreach(EXCLUDE_DIR IN LISTS EXCLUDE_DIRECTORIES) target_link_options(${APP_NAME} PRIVATE "SHELL: --exclude-file=${PROJECT_SOURCE_DIR}/assets/models/${EXCLUDE_DIR}") endforeach() endif() append_sample_base_emscripten_source(${APP_NAME}) endif() if(DILIGENT_INSTALL_SAMPLES) # Install instructions file(RELATIVE_PATH TUTORIAL_REL_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") install(TARGETS ${APP_NAME} DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$" ) if(PLATFORM_LINUX OR PLATFORM_WIN32) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets/" DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$" ) endif() if(PLATFORM_WIN32) get_supported_backends(BACKEND_LIBRARIES) install(TARGETS ${BACKEND_LIBRARIES} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$" LIBRARY DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$" ARCHIVE DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$" ) # Dawn uses DXC, so we need to copy the DXC dlls even if DXC_REQUIRED is not set # to get consistent shader compilation results if(((DXC_REQUIRED AND D3D12_SUPPORTED) OR WEBGPU_SUPPORTED) AND DXC_COMPILER_PATH AND DXIL_SIGNER_PATH) install(FILES "${DXC_COMPILER_PATH}" "${DXIL_SIGNER_PATH}" DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$" ) endif() endif() endif() endfunction() ``` -------------------------------- ### Compute Ray Origin and Direction in HLSL Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial25_StatePackager/readme.md Calculates the starting and ending points of a ray in world space using screen coordinates and the inverse view-projection matrix. ```hlsl float3 f3RayStart = ScreenToWorld(PSIn.Pos.xy, 0.0, g_Constants.f2ScreenSize, g_Constants.ViewProjInvMat); float3 f3RayEnd = ScreenToWorld(PSIn.Pos.xy, 1.0, g_Constants.f2ScreenSize, g_Constants.ViewProjInvMat); RayInfo Ray; Ray.Origin = f3RayStart; Ray.Dir = normalize(f3RayEnd - f3RayStart); ``` -------------------------------- ### Prepare OpenXR Attributes for Diligent Engine Initialization Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial28_HelloOpenXR/readme.md Prepare the OpenXRAttribs structure by copying OpenXR instance and system ID, and setting the instance procedure address function. This is required before initializing Diligent Engine for OpenXR. ```cpp OpenXRAttribs XRAttribs; memcpy(&XRAttribs.Instance, &m_xrInstance, sizeof(m_xrInstance)); memcpy(&XRAttribs.SystemId, &m_xrSystemId, sizeof(m_xrSystemId)); XRAttribs.GetInstanceProcAddr = xrGetInstanceProcAddr; ``` -------------------------------- ### Worker Thread Wait for Signal Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial06_Multithreading/readme.md Worker threads wait for a signal from the main thread to start rendering. A negative signal value indicates an exit command. ```cpp int SignaledValue = pThis->m_RenderSubsetSignal.Wait(true, pThis->m_NumWorkerThreads); if (SignaledValue < 0) return; ``` -------------------------------- ### Initialize and Intersect Scene Boxes in HLSL Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial25_StatePackager/readme.md Initializes box properties and calls the intersection function for scene geometry. This example shows setting up a right wall. ```hlsl float RoomSize = 10.0; float WallThick = 0.05; BoxInfo Box; Box.Type = HIT_TYPE_LAMBERTIAN; Box.Emittance = float3(0.0, 0.0, 0.0); float3 Green = float3(0.1, 0.6, 0.1); float3 Red = float3(0.6, 0.1, 0.1); float3 Grey = float3(0.5, 0.5, 0.5); // Right wall Box.Center = float3(RoomSize * 0.5 + WallThick * 0.5, 0.0, 0.0); Box.Size = float3(WallThick, RoomSize * 0.5, RoomSize * 0.5); Box.Albedo = Green; IntersectAABB(Ray, Box, Hit); ``` -------------------------------- ### Explicit Resource State Transitions for Buffers Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial06_Multithreading/readme.md C++ code demonstrating how to explicitly transition vertex and index buffers to their required states using `IDeviceContext::TransitionResourceStates`. RESOURCE_STATE_UNKNOWN can be used to let the engine determine the current state. ```cpp StateTransitionDesc Barriers[2]; Barriers[0].pBuffer = m_CubeVertexBuffer; Barriers[0].OldState = RESOURCE_STATE_UNKNOWN; // Use the internal buffer state Barriers[0].NewState = RESOURCE_STATE_VERTEX_BUFFER; Barriers[0].UpdateResourceState = true; Barriers[1].pBuffer = m_CubeIndexBuffer; Barriers[1].OldState = RESOURCE_STATE_UNKNOWN; // Use the internal buffer state Barriers[1].NewState = RESOURCE_STATE_INDEX_BUFFER; Barriers[1].UpdateResourceState = true; m_pImmediateContext->TransitionResourceStates(2, Barriers); ``` -------------------------------- ### Begin Render Pass with Clear Values Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial19_RenderPasses/readme.md Initialize a render pass and specify clear values for attachments with ATTACHMENT_LOAD_OP_CLEAR. Ensure RESOURCE_STATE_TRANSITION_MODE_TRANSITION is used. ```cpp BeginRenderPassAttribs RPBeginInfo; RPBeginInfo.pRenderPass = m_pRenderPass; RPBeginInfo.pFramebuffer = pFramebuffer; OptimizedClearValue ClearValues[4]; // Color ClearValues[0].Color[0] = 0.f; ClearValues[0].Color[1] = 0.f; ClearValues[0].Color[2] = 0.f; ClearValues[0].Color[3] = 0.f; // Depth Z ClearValues[1].Color[0] = 1.f; ClearValues[1].Color[1] = 1.f; ClearValues[1].Color[2] = 1.f; ClearValues[1].Color[3] = 1.f; // Depth buffer ClearValues[2].DepthStencil.Depth = 1.f; // Final color buffer ClearValues[3].Color[0] = 0.0625f; ClearValues[3].Color[1] = 0.0625f; ClearValues[3].Color[2] = 0.0625f; ClearValues[3].Color[3] = 0.f; RPBeginInfo.pClearValues = ClearValues; RPBeginInfo.ClearValueCount = _countof(ClearValues); RPBeginInfo.StateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_TRANSITION; m_pImmediateContext->BeginRenderPass(RPBeginInfo); ``` -------------------------------- ### Particle Collision Shader - Read First Particle Index Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial14_ComputeShader/readme.md Reads the index of the first particle in a given grid bin. This is the starting point for iterating through particles in that bin. ```hlsl int AnotherParticleIdx = g_ParticleListHead[x + y * GridWidth].FirstParticleIdx; ``` -------------------------------- ### Create Render State Notation Parser Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial26_StateCache/readme.md Initialize the Render State Notation Parser, enabling state reloading for dynamic updates. ```cpp RenderStateNotationParserCreateInfo ParserCI; // Enable state reloading in the parser ParserCI.EnableReload = true; CreateRenderStateNotationParser(ParserCI, &m_pRSNParser); ``` -------------------------------- ### Get Shader Resource View from Texture Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial03_Texturing/readme.md Retrieves the default shader resource view (SRV) from a loaded texture. This SRV is used to bind the texture to a shader variable. ```cpp // Get shader resource view from the texture m_TextureSRV = Tex->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE); ``` -------------------------------- ### Vertex Shader for Terrain Block Offset Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial08_Tessellation/readme.md Calculates the offset for the current terrain block based on its instance ID. This shader is a pass-through when tessellation is enabled, primarily used for setup. ```hlsl #include "structures.fxh" cbuffer VSConstants { GlobalConstants g_Constants; }; struct TerrainVSIn { uint BlockID : SV_VertexID; }; void TerrainVS(in TerrainVSIn VSIn, out TerrainVSOut VSOut) { uint BlockHorzOrder = VSIn.BlockID % g_Constants.NumHorzBlocks; uint BlockVertOrder = VSIn.BlockID / g_Constants.NumHorzBlocks; float2 BlockOffset = float2( float(BlockHorzOrder) / g_Constants.fNumHorzBlocks, float(BlockVertOrder) / g_Constants.fNumVertBlocks ); VSOut.BlockOffset = BlockOffset; } ``` -------------------------------- ### Define UWP Source and Include Files Source: https://github.com/diligentgraphics/diligentsamples/blob/master/SampleBase/CMakeLists.txt Sets source, include, and include directories for Universal Windows Platform (UWP) builds, handling Windows Runtime type limitations. ```cmake function(append_sample_base_uwp_source TARGET_NAME) get_target_property(SAMPLE_BASE_SOURCE_DIR Diligent-SampleBase SOURCE_DIR) set(SAMPLE_BASE_UWP_SOURCE ${SAMPLE_BASE_SOURCE_DIR}/src/UWP/ImguiUWPEventHelper.cpp ${SAMPLE_BASE_SOURCE_DIR}/src/UWP/SampleAppUWP.cpp ${SAMPLE_BASE_SOURCE_DIR}/src/UWP/InputControllerEventHandlerUWP.cpp ${SAMPLE_BASE_SOURCE_DIR}/src/SampleApp.cpp ) set(SAMPLE_BASE_UWP_INCLUDE ${SAMPLE_BASE_SOURCE_DIR}/src/UWP/ImguiUWPEventHelper.h ${SAMPLE_BASE_SOURCE_DIR}/src/UWP/InputControllerEventHandlerUWP.h ${SAMPLE_BASE_SOURCE_DIR}/include/SampleApp.hpp ${SAMPLE_BASE_SOURCE_DIR}/include/UWP/InputControllerUWP.hpp ) set(SAMPLE_BASE_UWP_INCLUDE_DIR ${SAMPLE_BASE_SOURCE_DIR}/src/UWP ) target_sources(${TARGET_NAME} PRIVATE ${SAMPLE_BASE_UWP_SOURCE} ${SAMPLE_BASE_UWP_INCLUDE}) source_group("src\SampleBase" FILES ${SAMPLE_BASE_UWP_SOURCE}) source_group("include\SampleBase" FILES ${SAMPLE_BASE_UWP_INCLUDE}) target_include_directories(${TARGET_NAME} PRIVATE ${SAMPLE_BASE_UWP_INCLUDE_DIR}) endfunction() ``` -------------------------------- ### Get Native Window Handles (Windows) Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Samples/GLFWDemo/readme.md Retrieves the native Win32 window handle from a GLFW window. This is necessary for creating swapchains or interacting with the windowing system directly on Windows. ```cpp #if PLATFORM_WIN32 Win32NativeWindow Window{glfwGetWin32Window(m_Window)}; #endif ``` -------------------------------- ### Texture Array Loading and Initialization Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial05_TextureArray/readme.md Loads individual textures, prepares texture description and subresource data for a texture array, and creates the texture array resource. ```cpp std::vector> TexLoaders(NumTextures); // Load textures for (int tex = 0; tex < NumTextures; ++tex) { // Create loader for the current texture std::stringstream FileNameSS; FileNameSS << "DGLogo" << tex << ".png"; const std::string FileName = FileNameSS.str(); TextureLoadInfo LoadInfo; LoadInfo.IsSRGB = true; CreateTextureLoaderFromFile(FileName.c_str(), IMAGE_FILE_FORMAT_UNKNOWN, LoadInfo, &TexLoaders[tex]); } TextureDesc TexArrDesc = TexLoaders[0]->GetTextureDesc(); TexArrDesc.ArraySize = NumTextures; TexArrDesc.Type = RESOURCE_DIM_TEX_2D_ARRAY; TexArrDesc.Usage = USAGE_DEFAULT; TexArrDesc.BindFlags = BIND_SHADER_RESOURCE; // Prepare initialization data std::vector SubresData(TexArrDesc.ArraySize * TexArrDesc.MipLevels); for (Uint32 slice = 0; slice < TexArrDesc.ArraySize; ++slice) { for (Uint32 mip = 0; mip < TexArrDesc.MipLevels; ++mip) { SubresData[slice * TexArrDesc.MipLevels + mip] = TexLoaders[slice]->GetSubresourceData(mip, 0); } } TextureData InitData{SubresData.data(), TexArrDesc.MipLevels * TexArrDesc.ArraySize}; // Create the texture array RefCntAutoPtr pTexArray; m_pDevice->CreateTexture(TexArrDesc, &InitData, &pTexArray); // Get shader resource view from the texture array m_TextureSRV = pTexArray->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE); ``` -------------------------------- ### Get Native Window Handles (Linux) Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Samples/GLFWDemo/readme.md Retrieves the native X11 window ID and display pointer from a GLFW window on Linux. This is required for integrating with Vulkan or other X11-based graphics APIs. ```cpp #if PLATFORM_LINUX LinuxNativeWindow Window; Window.WindowId = glfwGetX11Window(m_Window); Window.pDisplay = glfwGetX11Display(); #endif ``` -------------------------------- ### Initialize Shaders for Post-Processing Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial12_RenderTarget/readme.md Creates vertex and pixel shaders for a post-processing effect. Ensure shader file paths are correct and the device is properly initialized. ```cpp ShaderCreateInfo CreationAttribs; CreationAttribs.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL; CreationAttribs.UseCombinedTextureSamplers = true; BasicShaderSourceStreamFactory BasicSSSFactory; CreationAttribs.pShaderSourceStreamFactory = pShaderSourceFactory; RefCntAutoPtr pRTVS; { CreationAttribs.Desc.ShaderType = SHADER_TYPE_VERTEX; CreationAttribs.EntryPoint = "main"; CreationAttribs.Desc.Name = "Render Target VS"; CreationAttribs.FilePath = "rendertarget.vsh"; pDevice->CreateShader(CreationAttribs, &pRTVS); } RefCntAutoPtr pRTPS; { CreationAttribs.Desc.ShaderType = SHADER_TYPE_PIXEL; CreationAttribs.EntryPoint = "main"; CreationAttribs.Desc.Name = "Render Target PS"; CreationAttribs.FilePath = "rendertarget.psh"; pDevice->CreateShader(CreationAttribs, &pRTPS); } ``` -------------------------------- ### Configure Color G-Buffer Attachment Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial19_RenderPasses/readme.md Set up the first attachment for the color G-Buffer. Specifies format, initial/final states, and load/store operations. Use CLEAR load and DISCARD store to optimize when previous content is not needed. ```cpp Attachments[0].Format = TEX_FORMAT_RGBA8_UNORM; Attachments[0].InitialState = RESOURCE_STATE_RENDER_TARGET; Attachments[0].FinalState = RESOURCE_STATE_INPUT_ATTACHMENT; Attachments[0].LoadOp = ATTACHMENT_LOAD_OP_CLEAR; Attachments[0].StoreOp = ATTACHMENT_STORE_OP_DISCARD; ``` -------------------------------- ### Synchronize Compute and Graphics Passes with Fences Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial23_CommandQueues/readme.md Explicitly synchronize read and write access to textures between compute and graphics queues using fences. Ensure the compute context waits for the graphics pass to complete before starting, and signal completion afterwards for the graphics pass to wait. ```cpp // Make compute context wait for the previous graphics pass m_ComputeCtx->DeviceWaitForFence(m_GraphicsCtxFence, m_GraphicsCtxFenceValue); m_Terrain.Update(m_ComputeCtx); // Notify that compute pass is complete m_ComputeCtx->EnqueueSignal(m_ComputeCtxFence, ++m_ComputeCtxFenceValue); // Submit commands to the GPU m_ComputeCtx->Flush(); // Make graphics pass wait for the compute pass to complete m_pImmediateContext->DeviceWaitForFence(m_ComputeCtxFence, m_ComputeCtxFenceValue); ``` -------------------------------- ### Initialize GLFW Window Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Samples/GLFWDemo/readme.md Initializes GLFW and creates a window without a client API, suitable for headless rendering or custom API integration. Ensure GLFW is initialized before creating a window. ```cpp glfwInit(); gglfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); m_Window = glfwCreateWindow(Width, Height, Title, nullptr, nullptr); ``` -------------------------------- ### DRSN Pipeline State Definition Example Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial25_StatePackager/readme.md This JSON snippet demonstrates how a Graphics Pipeline State Object (PSO) is defined using Diligent Render State Notation (DRSN). It includes resource layout, primitive topology, rasterizer, and depth-stencil states, along with shader definitions. ```json "Pipelines": [ { "PSODesc": { "Name": "G-Buffer PSO", "ResourceLayout": { "Variables": [ { "Name": "cbConstants", "ShaderStages": "PIXEL", "Type": "STATIC" } ] } }, "GraphicsPipeline": { "PrimitiveTopology": "TRIANGLE_LIST", "RasterizerDesc": { "CullMode": "NONE" }, "DepthStencilDesc": { "DepthEnable": false } }, "pVS": { "Desc": { "Name": "Screen Triangle VS" }, "FilePath": "screen_tri.vsh", "EntryPoint": "main" }, "pPS": { "Desc": { "Name": "G-Buffer PS" }, "FilePath": "g_buffer.psh", "EntryPoint": "main" } } ] ``` -------------------------------- ### Enumerate and Allocate Swapchain Images Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial28_HelloOpenXR/readme.md First, query the number of swapchain images available. Then, allocate memory for the swapchain image data using AllocateOpenXRSwapchainImageData based on the device type and image count. Finally, retrieve the actual swapchain image data. ```cpp // Get the number of images in the swapchain. uint32_t SwapchainImageCount = 0; xrEnumerateSwapchainImages(xrSwapchain, 0, &SwapchainImageCount, nullptr); // Allocate the memory for the swapchain image data. RefCntAutoPtr pSwapchainImageData; AllocateOpenXRSwapchainImageData(m_DeviceType, SwapchainImageCount, &pSwapchainImageData); // Get the swapchain image data. xrEnumerateSwapchainImages(xrSwapchain, SwapchainImageCount, &SwapchainImageCount, pSwapchainImageData->GetDataPtr()); ``` -------------------------------- ### Populate G-Buffer Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial25_StatePackager/readme.md Sets up render targets and commits shader resources to populate the G-buffer. Use this to prepare the scene geometry and material data. ```cpp ITextureView* ppRTVs[] = { m_GBuffer.pAlbedo->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET), m_GBuffer.pNormal->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET), m_GBuffer.pEmittance->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET), m_GBuffer.pDepth->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET) }; m_pImmediateContext->SetRenderTargets(_countof(ppRTVs), ppRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); m_pImmediateContext->CommitShaderResources(m_pGBufferSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); m_pImmediateContext->SetPipelineState(m_pGBufferPSO); m_pImmediateContext->Draw({3, DRAW_FLAG_VERIFY_ALL}); ``` -------------------------------- ### Create Render State Archive using Command Line Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial25_StatePackager/readme.md Use the Diligent-RenderStatePackager.exe to create a binary archive of render states from JSON input and specified asset directories. Supports multiple graphics API targets. ```bash Diligent-RenderStatePackager.exe -i RenderStates.json -r assets -s assets -o assets/StateArchive.bin --dx11 --dx12 --opengl --vulkan --metal_macos --metal_ios --print_contents ``` -------------------------------- ### Create Swap Chain for Preview Renderer Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial30_HelloVisionOS/readme.md Initializes the Diligent Engine Metal device, immediate context, and creates a swap chain for the preview renderer using a CAMetalLayer-backed UIView. This is standard for iOS/macOS Metal applications. ```cpp Tutorial30_RenderEngine& Engine = Tutorial30_RenderEngine::Get(); IEngineFactoryMtl* pFactoryMtl = static_cast(Engine.GetEngineFactory()); SwapChainDesc SCDesc; SCDesc.ColorBufferFormat = TEX_FORMAT_BGRA8_UNORM_SRGB; SCDesc.DepthBufferFormat = TEX_FORMAT_D32_FLOAT; SCDesc.Width = WidthPx; SCDesc.Height = HeightPx; NativeWindow Window{pCAMetalLayer}; pFactoryMtl->CreateSwapChainMtl(Engine.GetDevice(), Engine.GetImmediateContext(), SCDesc, Window, &m_pSwapChain); ``` -------------------------------- ### Create OpenXR Session with Graphics Binding Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial28_HelloOpenXR/readme.md Obtain the graphics binding required for creating an OpenXR session using GetOpenXRGraphicsBinding. Then, populate XrSessionCreateInfo with the graphics binding, session flags, and system ID before creating the session. ```cpp RefCntAutoPtr pGraphicsBinding; GetOpenXRGraphicsBinding(m_Device, m_pImmediateContext, &pGraphicsBinding); XrSessionCreateInfo SessionCI{XR_TYPE_SESSION_CREATE_INFO}; SessionCI.next = pGraphicsBinding->GetConstDataPtr(); SessionCI.createFlags = 0; SessionCI.systemId = m_xrSystemId; xrCreateSession(m_xrInstance, &SessionCI, &m_xrSession); ``` -------------------------------- ### Create Render State Notation Loader Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial26_StateCache/readme.md Initialize the Render State Notation Loader, which combines the render state cache and the state notation parser to create actual state objects. ```cpp RenderStateNotationLoaderCreateInfo LoaderCI; LoaderCI.pDevice = m_pDevice; LoaderCI.pParser = m_pRSNParser; LoaderCI.pStateCache = m_pStateCache; LoaderCI.pStreamFactory = pShaderSourceFactory; CreateRenderStateNotationLoader(LoaderCI, &m_pRSNLoader); ``` -------------------------------- ### Shader Creation Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial01_HelloTriangle/readme.md Create shader objects by populating the ShaderCreateInfo structure. Specify the source language, entry point, name, and source code for each shader. ```cpp ShaderCreateInfo ShaderCI; ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL; ShaderCI.UseCombinedTextureSamplers = true; // Create a vertex shader RefCntAutoPtr pVS; { ShaderCI.Desc.ShaderType = SHADER_TYPE_VERTEX; ShaderCI.EntryPoint = "main"; ShaderCI.Desc.Name = "Triangle vertex shader"; ShaderCI.Source = VSSource; pDevice->CreateShader(ShaderCI, &pVS); } // Create a pixel shader RefCntAutoPtr pPS; { ShaderCI.Desc.ShaderType = SHADER_TYPE_PIXEL; ShaderCI.EntryPoint = "main"; ShaderCI.Desc.Name = "Triangle pixel shader"; ShaderCI.Source = PSSource; pDevice->CreateShader(ShaderCI, &pPS); } ``` -------------------------------- ### Set Vertex and Index Buffers for Instancing Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial04_Instancing/readme.md Binds vertex and instance buffers to the pipeline. Ensure both per-vertex and per-instance data buffers are correctly set before initiating rendering commands. ```cpp Uint32 offsets[] = {0, 0}; IBuffer* pBuffs[] = {m_CubeVertexBuffer, m_InstanceBuffer}; m_pImmediateContext->SetVertexBuffers(0, _countof(pBuffs), pBuffs, offsets, RESOURCE_STATE_TRANSITION_MODE_TRANSITION, SET_VERTEX_BUFFERS_FLAG_RESET); ``` ```cpp m_pImmediateContext->SetIndexBuffer(m_CubeIndexBuffer, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); ``` -------------------------------- ### Initialize Graphics Pipeline State for Cube Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial02_Cube/readme.md Configure render target and depth-stencil formats, and enable depth testing for the graphics pipeline. ```cpp PSOCreateInfo.GraphicsPipeline.NumRenderTargets = 1; PSOCreateInfo.GraphicsPipeline.RTVFormats[0] = pSwapChain->GetDesc().ColorBufferFormat; PSOCreateInfo.GraphicsPipeline.DSVFormat = pSwapChain->GetDesc().DepthBufferFormat; PSOCreateInfo.GraphicsPipeline.DepthStencilDesc.DepthEnable = True; ``` -------------------------------- ### Executable and Source Files Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial00_HelloWin32/CMakeLists.txt Defines the source files for the executable and creates the executable target. The WIN32 flag ensures it's a Windows GUI application. ```cmake set(SOURCE src/Tutorial00_HelloWin32.cpp ) add_executable(Tutorial00_HelloWin32 WIN32 ${SOURCE}) ``` -------------------------------- ### Configure PipelineStateUnpackInfo Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial25_StatePackager/readme.md Populate the PipelineStateUnpackInfo struct with necessary details like the render device, pipeline type, and name before unpacking a pipeline state. ```cpp PipelineStateUnpackInfo UnpackInfo; UnpackInfo.pDevice = m_pDevice; UnpackInfo.PipelineType = PIPELINE_TYPE_GRAPHICS; UnpackInfo.Name = "Resolve PSO"; ``` -------------------------------- ### Create Dearchiver Object Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial25_StatePackager/readme.md Instantiate an IDearchiver object using the engine factory to prepare for unpacking pipeline states from an archive. ```cpp RefCntAutoPtr pDearchiver; DearchiverCreateInfo DearchiverCI{}; m_pEngineFactory->CreateDearchiver(DearchiverCI, &pDearchiver); ``` -------------------------------- ### Create Ray Tracing Pipeline State Object Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial21_RayTracing/readme.md Call CreateRayTracingPipelineState on the device to create the ray tracing PSO using the configured pipeline state create info. ```cpp m_pDevice->CreateRayTracingPipelineState(PSOCreateInfo, &m_pRayTracingPSO); ``` -------------------------------- ### Basic CMake Configuration Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial00_HelloWin32/CMakeLists.txt Sets the minimum CMake version and project name. This is standard boilerplate for CMake projects. ```cmake cmake_minimum_required (VERSION 3.10) project(Tutorial00_HelloWin32 CXX) ``` -------------------------------- ### Platform-Specific Library and Include Settings Source: https://github.com/diligentgraphics/diligentsamples/blob/master/UnityPlugin/UnityEmulator/CMakeLists.txt Configures target libraries and include directories for the UnityEmulator based on the detected platform (Universal Windows, Android, or macOS). ```cmake if(PLATFORM_UNIVERSAL_WINDOWS) target_link_libraries(UnityEmulator PRIVATE dxguid.lib) elseif(PLATFORM_ANDROID) target_link_libraries(UnityEmulator PRIVATE NDKHelper GLESv3 android PUBLIC native_app_glue) target_include_directories(UnityEmulator PRIVATE ${ANDROID_NDK}/sources/android/cpufeatures ) elseif(PLATFORM_MACOS) target_include_directories(UnityEmulator PUBLIC src/MacOS ) endif() source_group("src" FILES ${SOURCE}) source_group("include" FILES ${INCLUDE}) set_target_properties(UnityEmulator PROPERTIES FOLDER DiligentSamples/UnityPlugin ) ``` -------------------------------- ### Create Top-Level Acceleration Structure (TLAS) Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial21_RayTracing/readme.md Initializes and creates a TLAS with a specified name, maximum instance count, and build flags. Use this to represent the entire scene. ```cpp TopLevelASDesc TLASDesc; TLASDesc.Name = "TLAS"; TLASDesc.MaxInstanceCount = NumInstances; TLASDesc.Flags = RAYTRACING_BUILD_AS_ALLOW_UPDATE | RAYTRACING_BUILD_AS_PREFER_FAST_TRACE; m_pDevice->CreateTLAS(TLASDesc, &m_pTLAS); ``` -------------------------------- ### Parse Render State Notation File Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial26_StateCache/readme.md Load the DRSN file that describes pipeline states used in the tutorial at run time. ```cpp m_pRSNParser->ParseFile("RenderStates.json", pShaderSourceFactory); ``` -------------------------------- ### Create Shader Resource Binding Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial03_Texturing/readme.md Create a shader resource binding object from the pipeline state. The second parameter initializes static resource variables. ```cpp m_pPSO->CreateShaderResourceBinding(&m_SRB, true); ``` -------------------------------- ### Prepare SSR Resources Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial27_PostProcessing/readme.md Prepares resources for the Screen Space Reflections (SSR) pass. This involves setting up frame descriptors and initializing the PostFXContext and ScreenSpaceReflection objects. ```hlsl { PostFXContext::FrameDesc FrameDesc; FrameDesc.Width = m_pSwapChain->GetDesc().Width; FrameDesc.Height = m_pSwapChain->GetDesc().Height; FrameDesc.Index = m_CurrentFrameNumber; m_PostFXContext->PrepareResources(FrameDesc); m_ScreenSpaceReflection->PrepareResources(m_pDevice, m_PostFXContext.get()); } ``` -------------------------------- ### Create General Fences for Queue Synchronization Source: https://github.com/diligentgraphics/diligentsamples/blob/master/Tutorials/Tutorial23_CommandQueues/readme.md Creates 'GENERAL' type fences, which allow GPU-side synchronization between command queues. Each fence is given a descriptive name. ```cpp FenceDesc FenceCI; FenceCI.Type = FENCE_TYPE_GENERAL; FenceCI.Name = "Graphics context fence"; m_pDevice->CreateFence(FenceCI, &m_GraphicsCtxFence); FenceCI.Name = "Compute context fence"; m_pDevice->CreateFence(FenceCI, &m_ComputeCtxFence); ```