diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 2327f45..774975c 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -29,9 +29,9 @@ on: env: product_ver_major: 0 product_ver_minor: 7 - product_ver_patch: 0 + product_ver_patch: 1 product_ver_build: ${{ github.run_number }} - tracy_release_version: "0.8.2.1" + tracy_release_version: "0.9" jobs: build-asteroids: @@ -41,60 +41,60 @@ jobs: fail-fast: false matrix: include: - - os: windows-2019 + - os: windows-latest os_name: Windows name: "Win64_DX_Release" - config_preset: "VS2019-Win64-DX-Default" - build_preset: "VS2019-Win64-DX-Release" + config_preset: "VS2022-Win64-DX-Default" + build_preset: "VS2022-Win64-DX-Release" add_tracy_app: false - - os: windows-2019 + - os: windows-latest os_name: Windows name: "Win64_VK_Release" - config_preset: "VS2019-Win64-VK-Default" - build_preset: "VS2019-Win64-VK-Release" + config_preset: "VS2022-Win64-VK-Default" + build_preset: "VS2022-Win64-VK-Release" add_tracy_app: false - - os: windows-2019 + - os: windows-latest os_name: Windows name: "Win64_DX_Profile" - config_preset: "VS2019-Win64-DX-Profile" - build_preset: "VS2019-Win64-DX-Profile" + config_preset: "VS2022-Win64-DX-Profile" + build_preset: "VS2022-Win64-DX-Profile" add_tracy_app: true - - os: windows-2019 + - os: windows-latest os_name: Windows name: "Win64_VK_Profile" - config_preset: "VS2019-Win64-VK-Profile" - build_preset: "VS2019-Win64-VK-Profile" + config_preset: "VS2022-Win64-VK-Profile" + build_preset: "VS2022-Win64-VK-Profile" add_tracy_app: true - - os: windows-2019 + - os: windows-latest os_name: Windows name: "Win32_DX_Release" - config_preset: "VS2019-Win32-DX-Default" - build_preset: "VS2019-Win32-DX-Release" + config_preset: "VS2022-Win32-DX-Default" + build_preset: "VS2022-Win32-DX-Release" add_tracy_app: false - - os: windows-2019 + - os: windows-latest os_name: Windows name: "Win32_VK_Release" - config_preset: "VS2019-Win32-VK-Default" - build_preset: "VS2019-Win32-VK-Release" + config_preset: "VS2022-Win32-VK-Default" + build_preset: "VS2022-Win32-VK-Release" add_tracy_app: false - - os: windows-2019 + - os: windows-latest os_name: Windows name: "Win32_DX_Profile" - config_preset: "VS2019-Win32-DX-Profile" - build_preset: "VS2019-Win32-DX-Profile" + config_preset: "VS2022-Win32-DX-Profile" + build_preset: "VS2022-Win32-DX-Profile" add_tracy_app: true - - os: windows-2019 + - os: windows-latest os_name: Windows name: "Win32_VK_Profile" - config_preset: "VS2019-Win32-VK-Profile" - build_preset: "VS2019-Win32-VK-Profile" + config_preset: "VS2022-Win32-VK-Profile" + build_preset: "VS2022-Win32-VK-Profile" add_tracy_app: true - os: ubuntu-latest @@ -141,14 +141,18 @@ jobs: runs-on: ${{ matrix.os }} + env: + INSTALL_DIR: Build/Output/${{ matrix.config_preset }}/Install + BUILD_LOG_FILE: Build/Output/${{ matrix.config_preset }}/Install/Build.log + steps: - name: Install Linux prerequisites if: ${{ matrix.os == 'ubuntu-latest' }} - run: sudo apt install xcb libx11-dev libx11-xcb-dev libxcb-randr0-dev p7zip + run: sudo apt install xcb libx11-dev libx11-xcb-dev libxcb-sync-dev libxcb-randr0-dev p7zip - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Initialize Externals Cache id: cache-externals @@ -163,19 +167,18 @@ jobs: shell: bash run: | set -o pipefail - mkdir -p "Build/Output/${{ matrix.config_preset }}/Install" - cmake --preset ${{ matrix.config_preset }} -DASTEROIDS_VERSION_MAJOR=${{ env.product_ver_major }} -DASTEROIDS_VERSION_MINOR=${{ env.product_ver_minor }} -DASTEROIDS_VERSION_PATCH=${{ env.product_ver_patch }} -DASTEROIDS_VERSION_BUILD=${{ env.product_ver_build }} 2>&1 | tee Build/Output/${{ matrix.config_preset }}/Install/Build.log + mkdir -p "$INSTALL_DIR" + cmake --preset ${{ matrix.config_preset }} -DASTEROIDS_VERSION_MAJOR=${{ env.product_ver_major }} -DASTEROIDS_VERSION_MINOR=${{ env.product_ver_minor }} -DASTEROIDS_VERSION_PATCH=${{ env.product_ver_patch }} -DASTEROIDS_VERSION_BUILD=${{ env.product_ver_build }} 2>&1 | tee $BUILD_LOG_FILE - name: CMake Build Preset ${{ matrix.build_preset }} shell: bash run: | set -o pipefail - cmake --build --preset ${{ matrix.build_preset }} --target install --parallel 4 2>&1 | tee -a Build/Output/${{ matrix.config_preset }}/Install/Build.log + cmake --build --preset ${{ matrix.build_preset }} --target install --parallel 4 2>&1 | tee -a $BUILD_LOG_FILE - name: Add README and BUILD files shell: bash run: | - INSTALL_DIR=Build/Output/${{ matrix.config_preset }}/Install cp README.md $INSTALL_DIR/README.md echo Methane Asteroids v.${{ env.product_ver_major }}.${{ env.product_ver_minor }}.${{ env.product_ver_patch }}.${{ env.product_ver_build }} https://github.com/${{ github.repository }} > $INSTALL_DIR/Build-Info.txt echo - Git repository: ${{ github.repositoryUrl }}, branch: ${{ github.ref_name }}, commit SHA: ${{ github.sha }} >> $INSTALL_DIR/Build-Info.txt @@ -186,26 +189,26 @@ jobs: - name: Add Windows System Information to BUILD file if: ${{ matrix.os_name == 'Windows' }} - run: systeminfo >> Build\Output\${{ matrix.config_preset }}\Install\Build-Info.txt + run: systeminfo >> ${{ env.INSTALL_DIR }}\Build-Info.txt - name: Add Unix System Information to BUILD file if: ${{ matrix.os_name != 'Windows' }} - run: uname -a >>Build/Output/${{ matrix.config_preset }}/Install/Build-Info.txt + run: uname -a >>$INSTALL_DIR/Build-Info.txt - name: Download Tracy release if: ${{ matrix.add_tracy_app }} shell: bash run: | curl -sSLo Tracy.7z https://github.com/MethanePowered/Tracy/releases/download/v${{ env.tracy_release_version }}/Tracy-${{ matrix.os_name }}-v${{ env.tracy_release_version }}.7z - 7z x Tracy.7z -oBuild/Output/${{ matrix.config_preset }}/Install/Apps + 7z x Tracy.7z -o$INSTALL_DIR/Apps - name: Archive Build Artifacts shell: bash - working-directory: Build/Output/${{ matrix.config_preset }}/Install/ + working-directory: ${{ env.INSTALL_DIR }} run: 7z a -t7z -mx=9 MethaneAsteroids_${{ matrix.name }}.7z -r- ./*.* Apps/* - name: Upload Archived Build Artifacts uses: actions/upload-artifact@v3 with: name: MethaneAsteroids_${{ matrix.name }}_${{ env.product_ver_major }}.${{ env.product_ver_minor }}.${{ env.product_ver_patch }}.${{ env.product_ver_build }} - path: Build/Output/${{ matrix.config_preset }}/Install/MethaneAsteroids_${{ matrix.name }}.7z + path: ${{ env.INSTALL_DIR }}/MethaneAsteroids_${{ matrix.name }}.7z diff --git a/.gitpod.dockerfile b/.gitpod.dockerfile index e08e0f0..efa0497 100644 --- a/.gitpod.dockerfile +++ b/.gitpod.dockerfile @@ -3,7 +3,14 @@ FROM gitpod/workspace-full-vnc # Install Linux dependencies USER root RUN apt-get update \ - && apt-get -y install xcb libx11-dev libx11-xcb-dev libxcb-randr0-dev \ + && apt-get -y install wget build-essential ninja-build xcb libx11-dev libx11-xcb-dev libxcb-sync-dev libxcb-randr0-dev \ + && wget https://github.com/Kitware/CMake/releases/download/v3.25.2/cmake-3.25.2-linux-x86_64.sh \ + -q -O /tmp/cmake-install.sh \ + && chmod u+x /tmp/cmake-install.sh \ + && mkdir /opt/cmake-3.25.2 \ + && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.25.2 \ + && rm /tmp/cmake-install.sh \ + && ln -s /opt/cmake-3.25.2/bin/* /usr/local/bin \ && apt-get clean && rm -rf /var/cache/apt/* && rm -rf /var/lib/apt/lists/* && rm -rf /tmp/* USER gitpod diff --git a/App/AsteroidsApp.cpp b/App/AsteroidsApp.cpp index 2d1d19d..45c3065 100644 --- a/App/AsteroidsApp.cpp +++ b/App/AsteroidsApp.cpp @@ -60,13 +60,6 @@ static const std::array g_mutable_paramet { 50000U, 1000U, 50U, 0.17F }, // 9 } }; -static constexpr Graphics::RenderPass::Access g_default_screen_pass_access = []() -{ - using namespace magic_enum::bitwise_operators; - return Graphics::RenderPass::Access::ShaderResources | - Graphics::RenderPass::Access::Samplers; -}(); - [[nodiscard]] inline uint32_t GetDefaultComplexity() { @@ -89,63 +82,69 @@ inline const MutableParameters& GetMutableParameters() return GetMutableParameters(GetDefaultComplexity()); } -static const std::map g_asteroids_action_by_keyboard_state{ - { { pal::Keyboard::Key::P }, AsteroidsAppAction::SwitchParallelRendering }, - { { pal::Keyboard::Key::L }, AsteroidsAppAction::SwitchMeshLodsColoring }, - { { pal::Keyboard::Key::Apostrophe }, AsteroidsAppAction::IncreaseMeshLodComplexity }, - { { pal::Keyboard::Key::Semicolon }, AsteroidsAppAction::DecreaseMeshLodComplexity }, - { { pal::Keyboard::Key::RightBracket }, AsteroidsAppAction::IncreaseComplexity }, - { { pal::Keyboard::Key::LeftBracket }, AsteroidsAppAction::DecreaseComplexity }, - { { pal::Keyboard::Key::Num0 }, AsteroidsAppAction::SetComplexity0 }, - { { pal::Keyboard::Key::Num1 }, AsteroidsAppAction::SetComplexity1 }, - { { pal::Keyboard::Key::Num2 }, AsteroidsAppAction::SetComplexity2 }, - { { pal::Keyboard::Key::Num3 }, AsteroidsAppAction::SetComplexity3 }, - { { pal::Keyboard::Key::Num4 }, AsteroidsAppAction::SetComplexity4 }, - { { pal::Keyboard::Key::Num5 }, AsteroidsAppAction::SetComplexity5 }, - { { pal::Keyboard::Key::Num6 }, AsteroidsAppAction::SetComplexity6 }, - { { pal::Keyboard::Key::Num7 }, AsteroidsAppAction::SetComplexity7 }, - { { pal::Keyboard::Key::Num8 }, AsteroidsAppAction::SetComplexity8 }, - { { pal::Keyboard::Key::Num9 }, AsteroidsAppAction::SetComplexity9 }, +static const std::map g_asteroids_action_by_keyboard_state{ + { { pin::Keyboard::Key::P }, AsteroidsAppAction::SwitchParallelRendering }, + { { pin::Keyboard::Key::L }, AsteroidsAppAction::SwitchMeshLodsColoring }, + { { pin::Keyboard::Key::Apostrophe }, AsteroidsAppAction::IncreaseMeshLodComplexity }, + { { pin::Keyboard::Key::Semicolon }, AsteroidsAppAction::DecreaseMeshLodComplexity }, + { { pin::Keyboard::Key::RightBracket }, AsteroidsAppAction::IncreaseComplexity }, + { { pin::Keyboard::Key::LeftBracket }, AsteroidsAppAction::DecreaseComplexity }, + { { pin::Keyboard::Key::Num0 }, AsteroidsAppAction::SetComplexity0 }, + { { pin::Keyboard::Key::Num1 }, AsteroidsAppAction::SetComplexity1 }, + { { pin::Keyboard::Key::Num2 }, AsteroidsAppAction::SetComplexity2 }, + { { pin::Keyboard::Key::Num3 }, AsteroidsAppAction::SetComplexity3 }, + { { pin::Keyboard::Key::Num4 }, AsteroidsAppAction::SetComplexity4 }, + { { pin::Keyboard::Key::Num5 }, AsteroidsAppAction::SetComplexity5 }, + { { pin::Keyboard::Key::Num6 }, AsteroidsAppAction::SetComplexity6 }, + { { pin::Keyboard::Key::Num7 }, AsteroidsAppAction::SetComplexity7 }, + { { pin::Keyboard::Key::Num8 }, AsteroidsAppAction::SetComplexity8 }, + { { pin::Keyboard::Key::Num9 }, AsteroidsAppAction::SetComplexity9 }, }; void AsteroidsFrame::ReleaseScreenPassAttachmentTextures() { META_FUNCTION_TASK(); - asteroids_pass_ptr->ReleaseAttachmentTextures(); + asteroids_pass.ReleaseAttachmentTextures(); AppFrame::ReleaseScreenPassAttachmentTextures(); } AsteroidsApp::AsteroidsApp() : UserInterfaceApp( - Graphics::AppSettings - { // ========================= - Platform::IApp::Settings { // platform_app: - "Methane Asteroids", // - name - { 0.8, 0.8 }, // - size - { 640U, 480U }, // - min_size - false, // - is_full_screen - &Data::IconProvider::Get(), // - icon_resources_ptr - }, // ========================= - Graphics::IApp::Settings { // graphics_app: - g_default_screen_pass_access, // - screen_pass_access - true, // - animations_enabled - true, // - show_hud_in_window_title - 0 // - default_device_index - }, // ========================= - Graphics::RenderContext::Settings { // render_context: - Graphics::FrameSize(), // - frame_size - Graphics::PixelFormat::BGRA8Unorm, // - color_format - Graphics::PixelFormat::Depth32Float, // - depth_stencil_format - std::nullopt, // - clear_color - gfx::DepthStencil(0.F, {}), // - clear_depth_stencil - 3U, // - frame_buffers_count - false, // - vsync_enabled - false, // - is_full_screen - gfx::Context::Options::None, // - options_mask - 1000U, // - unsync_max_fps (MacOS only) - } // ========================= + Graphics::CombinedAppSettings + { // ========================= + Platform::IApp::Settings { // platform_app: + "Methane Asteroids", // - name + { 0.8, 0.8 }, // - size + { 640U, 480U }, // - min_size + false, // - is_full_screen + &Data::IconProvider::Get(), // - icon_resources_ptr + }, // ========================= + Graphics::IApp::Settings { // graphics_app: + rhi::RenderPassAccessMask{ // - screen_pass_access + rhi::RenderPassAccess::ShaderResources, + rhi::RenderPassAccess::Samplers + }, + true, // - animations_enabled + true, // - show_hud_in_window_title + 0 // - default_device_index + }, // ========================= + rhi::RenderContext::Settings { // render_context: + gfx::FrameSize(), // - frame_size + gfx::PixelFormat::BGRA8Unorm, // - color_format + gfx::PixelFormat::Depth32Float, // - depth_stencil_format + std::nullopt, // - clear_color + gfx::DepthStencilValues(0.F, {}), // - clear_depth_stencil + 3U, // - frame_buffers_count + false, // - vsync_enabled + false, // - is_full_screen + {}, // - options_mask + 1000U, // - unsync_max_fps (MacOS only) + } // ========================= + }, + UserInterface::IApp::Settings + { + UserInterface::HeadsUpDisplayMode::UserInterface }, - { HeadsUpDisplayMode::UserInterface }, "Methane Asteroids sample is demonstrating parallel rendering\nof massive asteroids field dynamic simulation.") , m_view_camera(GetAnimations(), gfx::ActionCamera::Pivot::Aim) , m_light_camera(m_view_camera, GetAnimations(), gfx::ActionCamera::Pivot::Aim) @@ -187,8 +186,8 @@ AsteroidsApp::AsteroidsApp() std::make_shared(*this, g_asteroids_action_by_keyboard_state), std::make_shared(m_view_camera, "VIEW CAMERA"), std::make_shared(m_light_camera, "LIGHT SOURCE", - gfx::AppCameraController::ActionByMouseButton { { pal::Mouse::Button::Right, gfx::ActionCamera::MouseAction::Rotate } }, - gfx::AppCameraController::ActionByKeyboardState { { { pal::Keyboard::Key::LeftControl, pal::Keyboard::Key::L }, gfx::ActionCamera::KeyboardAction::Reset } }, + gfx::AppCameraController::ActionByMouseButton { { pin::Mouse::Button::Right, gfx::ActionCamera::MouseAction::Rotate } }, + gfx::AppCameraController::ActionByKeyboardState { { { pin::Keyboard::Key::LeftControl, pin::Keyboard::Key::L }, gfx::ActionCamera::KeyboardAction::Reset } }, gfx::AppCameraController::ActionByKeyboardKey { }), }); @@ -234,28 +233,28 @@ void AsteroidsApp::Init() META_SCOPE_TIMER("AsteroidsApp::Init"); // Create initial render-pass pattern for asteroids rendering - gfx::RenderPattern::Settings asteroids_render_pattern_settings = GetScreenRenderPatternSettings(); - asteroids_render_pattern_settings.color_attachments[0].load_action = gfx::RenderPass::Attachment::LoadAction::DontCare; - asteroids_render_pattern_settings.depth_attachment->load_action = gfx::RenderPass::Attachment::LoadAction::Clear; - asteroids_render_pattern_settings.depth_attachment->store_action = gfx::RenderPass::Attachment::StoreAction::Store; + rhi::RenderPattern::Settings asteroids_render_pattern_settings = GetScreenRenderPatternSettings(); + asteroids_render_pattern_settings.color_attachments[0].load_action = rhi::RenderPass::Attachment::LoadAction::DontCare; + asteroids_render_pattern_settings.depth_attachment->load_action = rhi::RenderPass::Attachment::LoadAction::Clear; + asteroids_render_pattern_settings.depth_attachment->store_action = rhi::RenderPass::Attachment::StoreAction::Store; asteroids_render_pattern_settings.is_final_pass = false; - m_asteroids_render_pattern_ptr = gfx::RenderPattern::Create(GetRenderContext(), asteroids_render_pattern_settings); + m_asteroids_render_pattern = rhi::RenderPattern(GetRenderContext(), asteroids_render_pattern_settings); // Modify settings of the final screen render-pass pattern so that color and depth attachments are reused from initial asteroids render pass - gfx::RenderPattern::Settings& screen_render_pattern_settings = GetScreenRenderPatternSettings(); - screen_render_pattern_settings.color_attachments[0].load_action = gfx::RenderPass::Attachment::LoadAction::Load; - screen_render_pattern_settings.depth_attachment->load_action = gfx::RenderPass::Attachment::LoadAction::Load; + rhi::RenderPattern::Settings& screen_render_pattern_settings = GetScreenRenderPatternSettings(); + screen_render_pattern_settings.color_attachments[0].load_action = rhi::RenderPass::Attachment::LoadAction::Load; + screen_render_pattern_settings.depth_attachment->load_action = rhi::RenderPass::Attachment::LoadAction::Load; // Screen render pattern and screen passes for all frames are initialized here based on modified settings UserInterfaceApp::Init(); - const gfx::RenderContext& context = GetRenderContext(); - gfx::CommandQueue& render_cmd_queue = context.GetRenderCommandKit().GetQueue(); - const gfx::RenderContext::Settings& context_settings = context.GetSettings(); + const rhi::RenderContext& context = GetRenderContext(); + rhi::CommandQueue render_cmd_queue = context.GetRenderCommandKit().GetQueue(); + const rhi::RenderContext::Settings& context_settings = context.GetSettings(); m_view_camera.Resize(context_settings.frame_size); // Load cube-map texture images for Sky-box - const Ptr sky_box_texture_ptr = GetImageLoader().LoadImagesToTextureCube(render_cmd_queue, + const rhi::Texture sky_box_texture = GetImageLoader().LoadImagesToTextureCube(render_cmd_queue, gfx::ImageLoader::CubeFaceResources { "Galaxy/PositiveX.jpg", @@ -265,22 +264,21 @@ void AsteroidsApp::Init() "Galaxy/PositiveZ.jpg", "Galaxy/NegativeZ.jpg" }, - gfx::ImageLoader::Options::Mipmapped, + { gfx::ImageOption::Mipmapped }, "Sky-Box Texture" ); // Create sky-box - using namespace magic_enum::bitwise_operators; - m_sky_box_ptr = std::make_shared(render_cmd_queue, *m_asteroids_render_pattern_ptr, *sky_box_texture_ptr, + m_sky_box = gfx::SkyBox(render_cmd_queue, m_asteroids_render_pattern, sky_box_texture, gfx::SkyBox::Settings { m_view_camera, m_scene_scale * 100.F, - gfx::SkyBox::Options::DepthEnabled | gfx::SkyBox::Options::DepthReversed + { gfx::SkyBox::Option::DepthEnabled, gfx::SkyBox::Option::DepthReversed } }); // Create planet - m_planet_ptr = std::make_shared(render_cmd_queue, *m_asteroids_render_pattern_ptr, GetImageLoader(), + m_planet_ptr = std::make_shared(render_cmd_queue, m_asteroids_render_pattern, GetImageLoader(), Planet::Settings { m_view_camera, @@ -290,25 +288,25 @@ void AsteroidsApp::Init() m_scene_scale * 3.F, // scale 0.1F, // spin_velocity_rps true, // depth_reversed - gfx::ImageLoader::Options::Mipmapped | // image_options - gfx::ImageLoader::Options::SrgbColorSpace, + { gfx::ImageOption::Mipmapped, // image_options + gfx::ImageOption::SrgbColorSpace }, // -1.F, // lod_bias } ); // Create asteroids array m_asteroids_array_ptr = m_asteroids_array_state_ptr - ? std::make_unique(render_cmd_queue, *m_asteroids_render_pattern_ptr, m_asteroids_array_settings, *m_asteroids_array_state_ptr) - : std::make_unique(render_cmd_queue, *m_asteroids_render_pattern_ptr, m_asteroids_array_settings); + ? std::make_unique(render_cmd_queue, m_asteroids_render_pattern, m_asteroids_array_settings, *m_asteroids_array_state_ptr) + : std::make_unique(render_cmd_queue, m_asteroids_render_pattern, m_asteroids_array_settings); const auto constants_data_size = static_cast(sizeof(hlslpp::SceneConstants)); const auto scene_uniforms_data_size = static_cast(sizeof(hlslpp::SceneUniforms)); const Data::Size asteroid_uniforms_data_size = m_asteroids_array_ptr->GetUniformsBufferSize(); // Create constants buffer for frame rendering - m_const_buffer_ptr = gfx::Buffer::CreateConstantBuffer(context, constants_data_size); - m_const_buffer_ptr->SetName("Constants Buffer"); - m_const_buffer_ptr->SetData( + m_const_buffer = context.CreateBuffer(rhi::BufferSettings::ForConstantBuffer(constants_data_size)); + m_const_buffer.SetName("Constants Buffer"); + m_const_buffer.SetData( { { reinterpret_cast(&m_scene_constants), sizeof(m_scene_constants) } }, // NOSONAR render_cmd_queue ); @@ -317,61 +315,61 @@ void AsteroidsApp::Init() for(AsteroidsFrame& frame : GetFrames()) { // Create asteroids render pass - frame.asteroids_pass_ptr = gfx::RenderPass::Create(*m_asteroids_render_pattern_ptr, frame.screen_pass_ptr->GetSettings()); + frame.asteroids_pass = rhi::RenderPass(m_asteroids_render_pattern, frame.screen_pass.GetSettings()); // Create parallel command list for asteroids rendering - frame.parallel_cmd_list_ptr = gfx::ParallelRenderCommandList::Create(context.GetRenderCommandKit().GetQueue(), *frame.asteroids_pass_ptr); - frame.parallel_cmd_list_ptr->SetParallelCommandListsCount(std::thread::hardware_concurrency()); - frame.parallel_cmd_list_ptr->SetName(IndexedName("Parallel Rendering", frame.index)); - frame.parallel_cmd_list_ptr->SetValidationEnabled(false); + frame.parallel_cmd_list = rhi::ParallelRenderCommandList(context.GetRenderCommandKit().GetQueue(), frame.asteroids_pass); + frame.parallel_cmd_list.SetParallelCommandListsCount(std::thread::hardware_concurrency()); + frame.parallel_cmd_list.SetName(IndexedName("Parallel Rendering", frame.index)); + frame.parallel_cmd_list.SetValidationEnabled(false); // Create serial command list for asteroids rendering - frame.serial_cmd_list_ptr = gfx::RenderCommandList::Create(context.GetRenderCommandKit().GetQueue(), *frame.asteroids_pass_ptr); - frame.serial_cmd_list_ptr->SetName(IndexedName("Serial Rendering", frame.index)); - frame.serial_cmd_list_ptr->SetValidationEnabled(false); + frame.serial_cmd_list = rhi::RenderCommandList(context.GetRenderCommandKit().GetQueue(), frame.asteroids_pass); + frame.serial_cmd_list.SetName(IndexedName("Serial Rendering", frame.index)); + frame.serial_cmd_list.SetValidationEnabled(false); // Create final command list for sky-box and planet rendering - frame.final_cmd_list_ptr = gfx::RenderCommandList::Create(context.GetRenderCommandKit().GetQueue(), *frame.screen_pass_ptr); - frame.final_cmd_list_ptr->SetName(IndexedName("Final Rendering", frame.index)); - frame.final_cmd_list_ptr->SetValidationEnabled(false); + frame.final_cmd_list = rhi::RenderCommandList(context.GetRenderCommandKit().GetQueue(), frame.screen_pass); + frame.final_cmd_list.SetName(IndexedName("Final Rendering", frame.index)); + frame.final_cmd_list.SetValidationEnabled(false); // Rendering command lists sequence - frame.execute_cmd_list_set_ptr = CreateExecuteCommandListSet(frame); + frame.execute_cmd_list_set = CreateExecuteCommandListSet(frame); // Create uniforms buffer with volatile parameters for the whole scene rendering - frame.scene_uniforms_buffer_ptr = gfx::Buffer::CreateConstantBuffer(context, scene_uniforms_data_size, false, true); - frame.scene_uniforms_buffer_ptr->SetName(IndexedName("Scene Uniforms Buffer", frame.index)); + frame.scene_uniforms_buffer = context.CreateBuffer(rhi::BufferSettings::ForConstantBuffer(scene_uniforms_data_size, false, true)); + frame.scene_uniforms_buffer.SetName(IndexedName("Scene Uniforms Buffer", frame.index)); // Create uniforms buffer for Sky-Box rendering - frame.sky_box.uniforms_buffer_ptr = gfx::Buffer::CreateConstantBuffer(context, sizeof(gfx::SkyBox::Uniforms), false, true); - frame.sky_box.uniforms_buffer_ptr->SetName(IndexedName("Sky-box Uniforms Buffer", frame.index)); + frame.sky_box.uniforms_buffer = context.CreateBuffer(rhi::BufferSettings::ForConstantBuffer(gfx::SkyBox::GetUniformsSize(), false, true)); + frame.sky_box.uniforms_buffer.SetName(IndexedName("Sky-box Uniforms Buffer", frame.index)); // Create uniforms buffer for Planet rendering - frame.planet.uniforms_buffer_ptr = gfx::Buffer::CreateConstantBuffer(context, sizeof(hlslpp::PlanetUniforms), false, true); - frame.planet.uniforms_buffer_ptr->SetName(IndexedName("Planet Uniforms Buffer", frame.index)); + frame.planet.uniforms_buffer = context.CreateBuffer(rhi::BufferSettings::ForConstantBuffer(sizeof(hlslpp::PlanetUniforms), false, true)); + frame.planet.uniforms_buffer.SetName(IndexedName("Planet Uniforms Buffer", frame.index)); // Create uniforms buffer for Asteroids array rendering - frame.asteroids.uniforms_buffer_ptr = gfx::Buffer::CreateConstantBuffer(context, asteroid_uniforms_data_size, true, true); - frame.asteroids.uniforms_buffer_ptr->SetName(IndexedName("Asteroids Array Uniforms Buffer", frame.index)); + frame.asteroids.uniforms_buffer = context.CreateBuffer(rhi::BufferSettings::ForConstantBuffer(asteroid_uniforms_data_size, true, true)); + frame.asteroids.uniforms_buffer.SetName(IndexedName("Asteroids Array Uniforms Buffer", frame.index)); // Resource bindings for Sky-Box rendering - frame.sky_box.program_bindings_ptr = m_sky_box_ptr->CreateProgramBindings(frame.sky_box.uniforms_buffer_ptr, frame.index); - frame.sky_box.program_bindings_ptr->SetName(IndexedName("Space Sky-Box Bindings {}", frame.index)); + frame.sky_box.program_bindings = m_sky_box.CreateProgramBindings(frame.sky_box.uniforms_buffer, frame.index); + frame.sky_box.program_bindings.SetName(IndexedName("Space Sky-Box Bindings {}", frame.index)); // Resource bindings for Planet rendering - frame.planet.program_bindings_ptr = m_planet_ptr->CreateProgramBindings(m_const_buffer_ptr, frame.planet.uniforms_buffer_ptr, frame.index); - frame.planet.program_bindings_ptr->SetName(IndexedName("Planet Bindings {}", frame.index)); + frame.planet.program_bindings = m_planet_ptr->CreateProgramBindings(m_const_buffer, frame.planet.uniforms_buffer, frame.index); + frame.planet.program_bindings.SetName(IndexedName("Planet Bindings {}", frame.index)); // Resource bindings for Asteroids rendering - frame.asteroids.program_bindings_per_instance = m_asteroids_array_ptr->CreateProgramBindings(m_const_buffer_ptr, - frame.scene_uniforms_buffer_ptr, - frame.asteroids.uniforms_buffer_ptr, + frame.asteroids.program_bindings_per_instance = m_asteroids_array_ptr->CreateProgramBindings(m_const_buffer, + frame.scene_uniforms_buffer, + frame.asteroids.uniforms_buffer, frame.index); } // Update initial resource states before asteroids drawing without applying barriers on GPU (automatic state propagation from Common state works), // which is required for correct automatic resource barriers to be set after asteroids drawing, on planet drawing - m_asteroids_array_ptr->CreateBeginningResourceBarriers(m_const_buffer_ptr.get())->ApplyTransitions(); + m_asteroids_array_ptr->CreateBeginningResourceBarriers(&m_const_buffer).ApplyTransitions(); CompleteInitialization(); META_LOG(GetParametersString()); @@ -388,15 +386,14 @@ bool AsteroidsApp::Resize(const gfx::FrameSize& frame_size, bool is_minimized) // Update frame buffer and depth textures in initial & final render passes for (const AsteroidsFrame& frame : GetFrames()) { - META_CHECK_ARG_NOT_NULL(frame.asteroids_pass_ptr); - gfx::RenderPass::Settings asteroids_pass_settings{ + rhi::RenderPassSettings asteroids_pass_settings{ { - gfx::Texture::View(*frame.screen_texture_ptr), - gfx::Texture::View(GetDepthTexture()) + rhi::TextureView(frame.screen_texture.GetInterface()), + rhi::TextureView(GetDepthTexture().GetInterface()) }, frame_size }; - frame.asteroids_pass_ptr->Update(asteroids_pass_settings); + frame.asteroids_pass.Update(asteroids_pass_settings); } m_view_camera.Resize(frame_size); @@ -417,7 +414,7 @@ bool AsteroidsApp::Update() m_scene_uniforms.eye_position = m_view_camera.GetOrientation().eye; m_scene_uniforms.light_position = m_light_camera.GetOrientation().eye; - m_sky_box_ptr->Update(); + m_sky_box.Update(); return true; } @@ -438,36 +435,36 @@ bool AsteroidsApp::Render() // Upload uniform buffers to GPU const AsteroidsFrame& frame = GetCurrentFrame(); - gfx::CommandQueue& render_cmd_queue = GetRenderContext().GetRenderCommandKit().GetQueue(); - frame.scene_uniforms_buffer_ptr->SetData(m_scene_uniforms_subresources, render_cmd_queue); + rhi::CommandQueue render_cmd_queue = GetRenderContext().GetRenderCommandKit().GetQueue(); + frame.scene_uniforms_buffer.SetData(m_scene_uniforms_subresources, render_cmd_queue); // Asteroids rendering in parallel or in main thread if (m_is_parallel_rendering_enabled) { - GetAsteroidsArray().DrawParallel(*frame.parallel_cmd_list_ptr, frame.asteroids, GetViewState()); - frame.parallel_cmd_list_ptr->Commit(); + GetAsteroidsArray().DrawParallel(frame.parallel_cmd_list, frame.asteroids, GetViewState()); + frame.parallel_cmd_list.Commit(); } else { - GetAsteroidsArray().Draw(*frame.serial_cmd_list_ptr, frame.asteroids, GetViewState()); - frame.serial_cmd_list_ptr->Commit(); + GetAsteroidsArray().Draw(frame.serial_cmd_list, frame.asteroids, GetViewState()); + frame.serial_cmd_list.Commit(); } // Draw planet and sky-box after asteroids to minimize pixel overdraw - m_planet_ptr->Draw(*frame.final_cmd_list_ptr, frame.planet, GetViewState()); - m_sky_box_ptr->Draw(*frame.final_cmd_list_ptr, frame.sky_box, GetViewState()); + m_planet_ptr->Draw(frame.final_cmd_list, frame.planet, GetViewState()); + m_sky_box.Draw(frame.final_cmd_list, frame.sky_box, GetViewState()); - RenderOverlay(*frame.final_cmd_list_ptr); - frame.final_cmd_list_ptr->Commit(); + RenderOverlay(frame.final_cmd_list); + frame.final_cmd_list.Commit(); // Execute rendering commands and present frame to screen - render_cmd_queue.Execute(*frame.execute_cmd_list_set_ptr); + render_cmd_queue.Execute(frame.execute_cmd_list_set); GetRenderContext().Present(); return true; } -void AsteroidsApp::OnContextReleased(gfx::Context& context) +void AsteroidsApp::OnContextReleased(rhi::IContext& context) { META_FUNCTION_TASK(); META_SCOPE_TIMERS_FLUSH(); @@ -477,11 +474,11 @@ void AsteroidsApp::OnContextReleased(gfx::Context& context) m_asteroids_array_state_ptr = m_asteroids_array_ptr->GetState(); } - m_sky_box_ptr.reset(); m_planet_ptr.reset(); m_asteroids_array_ptr.reset(); - m_const_buffer_ptr.reset(); - m_asteroids_render_pattern_ptr.reset(); + m_sky_box = {}; + m_const_buffer = {}; + m_asteroids_render_pattern = {}; UserInterfaceApp::OnContextReleased(context); } @@ -494,7 +491,7 @@ void AsteroidsApp::SetAsteroidsComplexity(uint32_t asteroids_complexity) if (m_asteroids_complexity == asteroids_complexity) return; - if (IsRenderContextInitialized()) + if (GetRenderContext().IsInitialized()) { WaitForRenderComplete(); } @@ -511,8 +508,10 @@ void AsteroidsApp::SetAsteroidsComplexity(uint32_t asteroids_complexity) m_asteroids_array_ptr.reset(); m_asteroids_array_state_ptr.reset(); - if (IsRenderContextInitialized()) + if (GetRenderContext().IsInitialized()) + { GetRenderContext().Reset(); + } UpdateParametersText(); } @@ -527,7 +526,7 @@ void AsteroidsApp::SetParallelRenderingEnabled(bool is_parallel_rendering_enable m_is_parallel_rendering_enabled = is_parallel_rendering_enabled; for(AsteroidsFrame& frame : GetFrames()) { - frame.execute_cmd_list_set_ptr = CreateExecuteCommandListSet(frame); + frame.execute_cmd_list_set = CreateExecuteCommandListSet(frame); } UpdateParametersText(); @@ -561,13 +560,13 @@ std::string AsteroidsApp::GetParametersString() return ss.str(); } -Ptr AsteroidsApp::CreateExecuteCommandListSet(const AsteroidsFrame& frame) const +rhi::CommandListSet AsteroidsApp::CreateExecuteCommandListSet(const AsteroidsFrame& frame) const { - return gfx::CommandListSet::Create({ + return rhi::CommandListSet({ m_is_parallel_rendering_enabled - ? static_cast(*frame.parallel_cmd_list_ptr) - : static_cast(*frame.serial_cmd_list_ptr), - *frame.final_cmd_list_ptr + ? static_cast(frame.parallel_cmd_list.GetInterface()) + : static_cast(frame.serial_cmd_list.GetInterface()), + frame.final_cmd_list.GetInterface() }, frame.index); } diff --git a/App/AsteroidsApp.h b/App/AsteroidsApp.h index d9278ea..1b24e57 100644 --- a/App/AsteroidsApp.h +++ b/App/AsteroidsApp.h @@ -41,19 +41,20 @@ namespace Methane::Samples { namespace gfx = Graphics; -namespace pal = Platform; +namespace rhi = Graphics::Rhi; +namespace pin = Platform::Input; struct AsteroidsFrame final : gfx::AppFrame { - Ptr asteroids_pass_ptr; - Ptr parallel_cmd_list_ptr; - Ptr serial_cmd_list_ptr; - Ptr final_cmd_list_ptr; - Ptr execute_cmd_list_set_ptr; - Ptr scene_uniforms_buffer_ptr; - gfx::MeshBufferBindings sky_box; - gfx::MeshBufferBindings planet; - gfx::InstancedMeshBufferBindings asteroids; + rhi::RenderPass asteroids_pass; + rhi::ParallelRenderCommandList parallel_cmd_list; + rhi::RenderCommandList serial_cmd_list; + rhi::RenderCommandList final_cmd_list; + rhi::CommandListSet execute_cmd_list_set; + rhi::Buffer scene_uniforms_buffer; + gfx::MeshBufferBindings sky_box; + gfx::MeshBufferBindings planet; + gfx::InstancedMeshBufferBindings asteroids; using gfx::AppFrame::AppFrame; @@ -62,7 +63,8 @@ struct AsteroidsFrame final : gfx::AppFrame }; using UserInterfaceApp = UserInterface::App; -class AsteroidsApp final : public UserInterfaceApp // NOSONAR +class AsteroidsApp final + : public UserInterfaceApp { public: AsteroidsApp(); @@ -87,11 +89,11 @@ class AsteroidsApp final : public UserInterfaceApp // NOSONAR protected: // IContextCallback overrides - void OnContextReleased(gfx::Context& context) override; + void OnContextReleased(rhi::IContext& context) override; private: bool Animate(double elapsed_seconds, double delta_seconds) const; - Ptr CreateExecuteCommandListSet(const AsteroidsFrame& frame) const; + rhi::CommandListSet CreateExecuteCommandListSet(const AsteroidsFrame& frame) const; gfx::ActionCamera m_view_camera; gfx::ActionCamera m_light_camera; @@ -106,13 +108,13 @@ class AsteroidsApp final : public UserInterfaceApp // NOSONAR uint32_t m_asteroids_complexity = 0U; bool m_is_parallel_rendering_enabled = true; hlslpp::SceneUniforms m_scene_uniforms{ }; - gfx::Resource::SubResources m_scene_uniforms_subresources{ + rhi::SubResources m_scene_uniforms_subresources{ { reinterpret_cast(&m_scene_uniforms), sizeof(hlslpp::SceneUniforms) } // NOSONAR }; - Ptr m_asteroids_render_pattern_ptr; - Ptr m_const_buffer_ptr; - Ptr m_sky_box_ptr; + rhi::RenderPattern m_asteroids_render_pattern; + rhi::Buffer m_const_buffer; + gfx::SkyBox m_sky_box; Ptr m_planet_ptr; Ptr m_asteroids_array_ptr; Ptr m_asteroids_array_state_ptr; diff --git a/App/AsteroidsAppController.cpp b/App/AsteroidsAppController.cpp index 9b2007a..b45ac53 100644 --- a/App/AsteroidsAppController.cpp +++ b/App/AsteroidsAppController.cpp @@ -32,23 +32,23 @@ namespace Methane::Samples AsteroidsAppController::AsteroidsAppController(AsteroidsApp& asteroids_app, const ActionByKeyboardState& action_by_keyboard_state) : Controller("ASTEROIDS SETTINGS") - , Platform::Keyboard::ActionControllerBase(action_by_keyboard_state, {}) + , pin::Keyboard::ActionControllerBase(action_by_keyboard_state, {}) , m_asteroids_app(asteroids_app) { META_FUNCTION_TASK(); } -void AsteroidsAppController::OnKeyboardChanged(Platform::Keyboard::Key key, Platform::Keyboard::KeyState key_state, - const Platform::Keyboard::StateChange& state_change) +void AsteroidsAppController::OnKeyboardChanged(pin::Keyboard::Key key, + pin::Keyboard::KeyState key_state, + const pin::Keyboard::StateChange& state_change) { META_FUNCTION_TASK(); - Platform::Keyboard::ActionControllerBase::OnKeyboardChanged(key, key_state, state_change); + pin::Keyboard::ActionControllerBase::OnKeyboardChanged(key, key_state, state_change); } void AsteroidsAppController::OnKeyboardStateAction(AsteroidsAppAction action) { META_FUNCTION_TASK(); - const uint32_t asteroids_complexity = m_asteroids_app.GetAsteroidsComplexity(); switch(action) { diff --git a/App/AsteroidsAppController.h b/App/AsteroidsAppController.h index 69a31ca..e488bca 100644 --- a/App/AsteroidsAppController.h +++ b/App/AsteroidsAppController.h @@ -24,7 +24,7 @@ Asteroids application controller. #pragma once #include -#include +#include namespace Methane::Samples { @@ -52,20 +52,22 @@ enum class AsteroidsAppAction SetComplexity9, }; +namespace pin = Platform::Input; + class AsteroidsAppController final - : public Platform::Input::Controller - , public Platform::Keyboard::ActionControllerBase + : public pin::Controller + , public pin::Keyboard::ActionControllerBase { public: AsteroidsAppController(AsteroidsApp& asteroids_app, const ActionByKeyboardState& action_by_keyboard_state); // Input::Controller implementation - void OnKeyboardChanged(Platform::Keyboard::Key, Platform::Keyboard::KeyState, const Platform::Keyboard::StateChange& state_change) override; + void OnKeyboardChanged(pin::Keyboard::Key, pin::Keyboard::KeyState, const pin::Keyboard::StateChange& state_change) override; HelpLines GetHelp() const override; protected: // Keyboard::ActionControllerBase interface - void OnKeyboardKeyAction(AsteroidsAppAction, Platform::Keyboard::KeyState) override { /* not handled in this controller */ } + void OnKeyboardKeyAction(AsteroidsAppAction, pin::Keyboard::KeyState) override { /* not handled in this controller */ } void OnKeyboardStateAction(AsteroidsAppAction action) override; std::string GetKeyboardActionName(AsteroidsAppAction action) const override; diff --git a/Build/README.md b/Build/README.md index 92b591c..193ae71 100644 --- a/Build/README.md +++ b/Build/README.md @@ -27,7 +27,7 @@ - GCC 9 or later - X11, XCB, LCov (optional for code coverage) libraries ```console - sudo apt-get update && sudo apt-get install build-essential git cmake lcov xcb libx11-dev libx11-xcb-dev libxcb-randr0-dev + sudo apt-get update && sudo apt-get install build-essential git cmake lcov xcb libx11-dev libx11-xcb-dev libxcb-sync-dev libxcb-randr0-dev ``` - **MacOS** - MacOS 10.15 "Catalina" or later @@ -211,11 +211,9 @@ Configure preset names `[ConfigPresetName]` can be listed with `cmake --list-pre | iOS [-Sim] | - | MTL | - | - | | tvOS [-Sim] | - | MTL | - | - | -Build preset names `[BuildPresetName]` can be listed with `cmake --list-presets build` and are constructed according to the same schema, -but `Default` suffix should be replaced with `Debug` or `Release` configuration name. Only compatible configure and build presets -can be used together either with the same name, or with `Debug` or `Release` instead of `Default`. `Ninja` presets should be used from +Build preset names `[BuildPresetName]` can be listed with `cmake --list-presets build` and are constructed according to the same schema, but `Default` suffix should be replaced with `Debug` or `Release` configuration name. Only compatible configure and build presets can be used together either with the same name, or with `Debug` or `Release` instead of `Default`. `Ninja` presets should be used from "x64/x86 Native Tools Command Prompt for VS2019" command line environment on Windows or directly from Visual Studio. -[Azure Pipelines](https://dev.azure.com/MethanePowered/MethaneKit/_build?view=runs) CI builds are configured with these CMake presets. +[GitHub Actions](https://github.com/MethanePowered/MethaneKit/actions) CI builds are configured with these CMake presets. CMake presets can be also used in [VS2019 and VS Code](https://devblogs.microsoft.com/cppblog/cmake-presets-integration-in-visual-studio-and-visual-studio-code/) to reproduce CI builds on the development system with a few configuration options in IDE UI. diff --git a/Build/Unix/Build.sh b/Build/Unix/Build.sh index e27ce05..6d5cd89 100755 --- a/Build/Unix/Build.sh +++ b/Build/Unix/Build.sh @@ -126,7 +126,8 @@ CMAKE_FLAGS="$CMAKE_FLAGS \ -DMETHANE_VERSION_MINOR=$BUILD_VERSION_MINOR \ -DMETHANE_GFX_VULKAN_ENABLED:BOOL=$VULKAN_BUILD_FLAG \ -DMETHANE_SHADERS_CODEVIEW_ENABLED:BOOL=ON \ - -DMETHANE_SHADERS_VALIDATION_ENABLED:BOOL=ON \ + -DMETHANE_RHI_PIMPL_INLINE_ENABLED:BOOL=ON \ + -DMETHANE_PRECOMPILED_HEADERS_ENABLED:BOOL=ON \ -DMETHANE_RUN_TESTS_DURING_BUILD:BOOL=OFF \ -DMETHANE_COMMAND_DEBUG_GROUPS_ENABLED:BOOL=ON \ -DMETHANE_LOGGING_ENABLED:BOOL=OFF \ diff --git a/Build/Windows/Build.bat b/Build/Windows/Build.bat index 4843045..fba5446 100644 --- a/Build/Windows/Build.bat +++ b/Build/Windows/Build.bat @@ -73,7 +73,8 @@ SET CMAKE_FLAGS= ^ -DASTEROIDS_VERSION_MINOR=%BUILD_VERSION_MINOR% ^ -DMETHANE_GFX_VULKAN_ENABLED:BOOL=%VULKAN_API_ENABLED% ^ -DMETHANE_SHADERS_CODEVIEW_ENABLED:BOOL=ON ^ - -DMETHANE_SHADERS_VALIDATION_ENABLED:BOOL=ON ^ + -DMETHANE_RHI_PIMPL_INLINE_ENABLED:BOOL=ON ^ + -DMETHANE_PRECOMPILED_HEADERS_ENABLED:BOOL=ON ^ -DMETHANE_RUN_TESTS_DURING_BUILD:BOOL=OFF ^ -DMETHANE_COMMAND_DEBUG_GROUPS_ENABLED:BOOL=ON ^ -DMETHANE_LOGGING_ENABLED:BOOL=OFF ^ diff --git a/CMakeLists.txt b/CMakeLists.txt index 65ea48a..ed0d2a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.18.0) # Methane version, build & product info set(ASTEROIDS_VERSION_MAJOR 0 CACHE STRING "Asteroids major version") set(ASTEROIDS_VERSION_MINOR 7 CACHE STRING "Asteroids minor version") -set(ASTEROIDS_VERSION_PATCH 0 CACHE STRING "Asteroids patch version") +set(ASTEROIDS_VERSION_PATCH 1 CACHE STRING "Asteroids patch version") set(ASTEROIDS_VERSION_BUILD 0 CACHE STRING "Asteroids build version") project(METHANE_ASTEROIDS diff --git a/CMakePresets.json b/CMakePresets.json index 53f43c1..16d3b20 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -20,6 +20,14 @@ "type": "BOOL", "value": "OFF" }, + "METHANE_RHI_PIMPL_INLINE_ENABLED": { + "type": "BOOL", + "value": "ON" + }, + "METHANE_PRECOMPILED_HEADERS_ENABLED": { + "type": "BOOL", + "value": "ON" + }, "METHANE_APPS_BUILD_ENABLED": { "type": "BOOL", "value": "OFF" @@ -48,10 +56,6 @@ "type": "BOOL", "value": "ON" }, - "METHANE_SHADERS_VALIDATION_ENABLED": { - "type": "BOOL", - "value": "ON" - }, "METHANE_OPEN_IMAGE_IO_ENABLED": { "type": "BOOL", "value": "OFF" @@ -70,7 +74,7 @@ }, "METHANE_ITT_INSTRUMENTATION_ENABLED": { "type": "BOOL", - "value": "ON" + "value": "OFF" }, "METHANE_ITT_METADATA_ENABLED": { "type": "BOOL", @@ -100,6 +104,10 @@ "inherits": "Ninja-Default", "hidden": true, "cacheVariables": { + "METHANE_RHI_PIMPL_INLINE_ENABLED": { + "type": "BOOL", + "value": "ON" + }, "METHANE_SHADERS_CODEVIEW_ENABLED": { "type": "BOOL", "value": "ON" @@ -122,7 +130,7 @@ }, "METHANE_ITT_METADATA_ENABLED": { "type": "BOOL", - "value": "ON" + "value": "OFF" }, "METHANE_GPU_INSTRUMENTATION_ENABLED": { "type": "BOOL", @@ -142,8 +150,18 @@ "name": "Ninja-Scan", "description": "Static scanning Ninja Multi configuration for builds under Sonar Cloud code analyzer", "inherits": "Ninja-Default", + "generator": "Ninja", "hidden": true, "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "METHANE_RHI_PIMPL_INLINE_ENABLED": { + "type": "BOOL", + "value": "OFF" + }, + "METHANE_PRECOMPILED_HEADERS_ENABLED": { + "type": "BOOL", + "value": "OFF" + }, "METHANE_CODE_COVERAGE_ENABLED": { "type": "BOOL", "value": "ON" @@ -155,6 +173,10 @@ "METHANE_UNITY_BUILD_ENABLED": { "type": "BOOL", "value": "OFF" + }, + "CMAKE_EXPORT_COMPILE_COMMANDS": { + "type": "BOOL", + "value": "ON" } } }, @@ -181,6 +203,17 @@ } } }, + { + "name": "Ninja-Scan-Vulkan", + "inherits": "Ninja-Scan", + "hidden": true, + "cacheVariables": { + "METHANE_GFX_VULKAN_ENABLED": { + "type": "BOOL", + "value": "ON" + } + } + }, { "name": "Ninja-Win-Default", @@ -220,7 +253,11 @@ "inherits": "Ninja-Default", "hidden": true, "cacheVariables": { - "CMAKE_OSX_ARCHITECTURES": "arm64;x86_64" + "CMAKE_OSX_ARCHITECTURES": "arm64;x86_64", + "METHANE_PRECOMPILED_HEADERS_ENABLED": { + "type": "BOOL", + "value": "OFF" + } }, "condition": { "type": "equals", @@ -272,6 +309,24 @@ "Ninja-Win-Default" ] }, + { + "name": "Ninja-Win-DX-Scan", + "displayName": "Scan - Ninja Multi-Config - Windows (DirectX)", + "description": "Scanning configuration using Ninja Multi-Config generator for Windows (DirectX)", + "inherits": [ + "Ninja-Scan", + "Ninja-Win-Default" + ] + }, + { + "name": "Ninja-Win-VK-Scan", + "displayName": "Scan - Ninja Multi-Config - Windows (Vulkan)", + "description": "Scanning configuration using Ninja Multi-Config generator for Windows (Vulkan)", + "inherits": [ + "Ninja-Scan-Vulkan", + "Ninja-Win-Default" + ] + }, { "name": "VS2019-Win64-DX-Default", @@ -397,9 +452,14 @@ "description": "Scanning configuration using Visual Studio 2019 generator for Windows x64 (Vulkan)", "generator": "Visual Studio 16 2019", "inherits": [ - "Ninja-Default-Vulkan", "VS2019-Win64-DX-Scan" - ] + ], + "cacheVariables": { + "METHANE_GFX_VULKAN_ENABLED": { + "type": "BOOL", + "value": "ON" + } + } }, { "name": "VS2019-Win32-VK-Scan", @@ -407,9 +467,14 @@ "description": "Scanning configuration using Visual Studio 2019 generator for Windows x86 (Vulkan)", "generator": "Visual Studio 16 2019", "inherits": [ - "Ninja-Default-Vulkan", "VS2019-Win32-DX-Scan" - ] + ], + "cacheVariables": { + "METHANE_GFX_VULKAN_ENABLED": { + "type": "BOOL", + "value": "ON" + } + } }, { @@ -507,6 +572,57 @@ ] }, + { + "name": "VS2022-Win64-DX-Scan", + "displayName": "Scan - VS2022 - Windows x64 (DirectX)", + "description": "Scanning configuration using Visual Studio 2019 generator for Windows x64 (DirectX)", + "generator": "Visual Studio 17 2022", + "inherits": [ + "Ninja-Scan", + "VS2022-Win64-DX-Default" + ] + }, + { + "name": "VS2022-Win32-DX-Scan", + "displayName": "Scan - VS2022 - Windows x86 (DirectX)", + "description": "Scanning configuration using Visual Studio 2019 generator for Windows x86 (DirectX)", + "generator": "Visual Studio 17 2022", + "inherits": [ + "Ninja-Scan", + "VS2022-Win32-DX-Default" + ] + }, + { + "name": "VS2022-Win64-VK-Scan", + "displayName": "Scan - VS2022 - Windows x64 (Vulkan)", + "description": "Scanning configuration using Visual Studio 2019 generator for Windows x64 (Vulkan)", + "generator": "Visual Studio 17 2022", + "inherits": [ + "VS2022-Win64-DX-Scan" + ], + "cacheVariables": { + "METHANE_GFX_VULKAN_ENABLED": { + "type": "BOOL", + "value": "ON" + } + } + }, + { + "name": "VS2022-Win32-VK-Scan", + "displayName": "Scan - VS2022 - Windows x86 (Vulkan)", + "description": "Scanning configuration using Visual Studio 2019 generator for Windows x86 (Vulkan)", + "generator": "Visual Studio 17 2022", + "inherits": [ + "VS2022-Win32-DX-Scan" + ], + "cacheVariables": { + "METHANE_GFX_VULKAN_ENABLED": { + "type": "BOOL", + "value": "ON" + } + } + }, + { "name": "Ninja-Lin-VK-Default", "displayName": "Default - Ninja Multi-Config - Linux (Vulkan)", @@ -524,6 +640,15 @@ "Ninja-Lin-Default" ] }, + { + "name": "Ninja-Lin-VK-Scan", + "displayName": "Scan - Ninja Multi-Config - Linux (Vulkan)", + "description": "Scanning configuration using Ninja Multi-Config generator for Linux (Vulkan)", + "inherits": [ + "Ninja-Scan", + "Ninja-Lin-Default" + ] + }, { "name": "Make-Lin-VK-Release", @@ -590,6 +715,21 @@ "inherits": [ "Ninja-Profile", "Ninja-Mac-Default" + ], + "cacheVariables": { + "METHANE_PRECOMPILED_HEADERS_ENABLED": { + "type": "BOOL", + "value": "OFF" + } + } + }, + { + "name": "Ninja-Mac-MTL-Scan", + "displayName": "Scan - Ninja Multi-Config - MacOS (Metal)", + "description": "Scanning configuration using Ninja Multi-Config generator for MacOS (Metal)", + "inherits": [ + "Ninja-Scan", + "Ninja-Mac-Default" ] }, @@ -619,7 +759,13 @@ "inherits": [ "Ninja-Scan", "Ninja-Mac-Default" - ] + ], + "cacheVariables": { + "METHANE_PRECOMPILED_HEADERS_ENABLED": { + "type": "BOOL", + "value": "OFF" + } + } }, { @@ -764,6 +910,14 @@ "configurePreset": "Ninja-Win-DX-Profile", "configuration": "RelWithDebInfo" }, + { + "name": "Ninja-Win-DX-Scan", + "displayName": "Scan - Ninja Multi-Config - Windows (DirectX)", + "description": "Scanning build with Ninja Multi-Config for Windows (DirectX)", + "inherits": [ "Windows-Build" ], + "configurePreset": "Ninja-Win-DX-Scan", + "configuration": "Debug" + }, { "name": "Ninja-Win-VK-Debug", @@ -789,6 +943,14 @@ "configurePreset": "Ninja-Win-VK-Profile", "configuration": "RelWithDebInfo" }, + { + "name": "Ninja-Win-VK-Scan", + "displayName": "Scan - Ninja Multi-Config - Windows (Vulkan)", + "description": "Scanning build with Ninja Multi-Config for Windows (Vulkan)", + "inherits": [ "Windows-Build" ], + "configurePreset": "Ninja-Win-VK-Scan", + "configuration": "Debug" + }, { "name": "VS2019-Win64-DX-Debug", @@ -856,6 +1018,23 @@ "configuration": "Debug" }, + { + "name": "VS2022-Win64-DX-Scan", + "displayName": "Scan - VS2022 - Windows x64 (DirectX)", + "description": "Scanning build with Visual Studio 2022 for Windows x64 (DirectX)", + "inherits": [ "Windows-Build" ], + "configurePreset": "VS2022-Win64-DX-Scan", + "configuration": "Debug" + }, + { + "name": "VS2022-Win32-DX-Scan", + "displayName": "Scan - VS2022 - Windows x86 (DirectX)", + "description": "Scanning build with Visual Studio 2022 for Windows x86 (DirectX)", + "inherits": [ "Windows-Build" ], + "configurePreset": "VS2022-Win32-DX-Scan", + "configuration": "Debug" + }, + { "name": "VS2019-Win64-VK-Debug", "displayName": "Debug - VS2019 - Windows x64 (Vulkan)", @@ -1044,6 +1223,14 @@ "configurePreset": "Ninja-Lin-VK-Profile", "configuration": "RelWithDebInfo" }, + { + "name": "Ninja-Lin-VK-Scan", + "displayName": "Scan - Ninja Multi-Config - Linux (Vulkan)", + "description": "Scanning build with Ninja Multi-Config for Linux (Vulkan)", + "inherits": [ "Linux-Build" ], + "configurePreset": "Ninja-Lin-VK-Scan", + "configuration": "Debug" + }, { "name": "Make-Lin-VK-Debug", @@ -1099,6 +1286,14 @@ "configurePreset": "Ninja-Mac-MTL-Profile", "configuration": "RelWithDebInfo" }, + { + "name": "Ninja-Mac-MTL-Scan", + "displayName": "Scan - Ninja Multi-Config - MacOS (Metal)", + "description": "Scanning build with Ninja Multi-Config for MacOS (Metal)", + "inherits": [ "MacOS-Build" ], + "configurePreset": "Ninja-Mac-MTL-Scan", + "configuration": "Debug" + }, { "name": "Xcode-Mac-MTL-Debug", diff --git a/Externals/CPM.cmake b/Externals/CPM.cmake index 6073550..bf701b8 100644 --- a/Externals/CPM.cmake +++ b/Externals/CPM.cmake @@ -1,8 +1,6 @@ -set(CPM_DOWNLOAD_VERSION 0.35.1) +set(CPM_DOWNLOAD_VERSION 0.37.0) if(CPM_SOURCE_CACHE) - # Expand relative path. This is important if the provided path contains a tilde (~) - get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE) set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") elseif(DEFINED ENV{CPM_SOURCE_CACHE}) set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") @@ -10,12 +8,25 @@ else() set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") endif() -if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +function(download_cpm) message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") file(DOWNLOAD - https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake - ${CPM_DOWNLOAD_LOCATION} - ) + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} + ) +endfunction() + +if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) + download_cpm() +else() + # resume download if it previously failed + file(READ ${CPM_DOWNLOAD_LOCATION} check) + if("${check}" STREQUAL "") + download_cpm() + endif() endif() include(${CPM_DOWNLOAD_LOCATION}) diff --git a/Externals/MethaneKit.cmake b/Externals/MethaneKit.cmake index 3737ed2..3973c83 100644 --- a/Externals/MethaneKit.cmake +++ b/Externals/MethaneKit.cmake @@ -1,7 +1,7 @@ CPMAddPackage( NAME MethaneKit GITHUB_REPOSITORY MethanePowered/MethaneKit - VERSION ${ASTEROIDS_VERSION_MAJOR}.${ASTEROIDS_VERSION_MINOR}.${ASTEROIDS_VERSION_PATCH}.1 + VERSION ${ASTEROIDS_VERSION_MAJOR}.${ASTEROIDS_VERSION_MINOR}.${ASTEROIDS_VERSION_PATCH} OPTIONS "METHANE_APPS_BUILD_ENABLED OFF" "METHANE_TESTS_BUILD_ENABLED OFF" diff --git a/Externals/README.md b/Externals/README.md index b3ca73e..595f480 100644 --- a/Externals/README.md +++ b/Externals/README.md @@ -12,7 +12,7 @@ to support parallel cmake configurations processing. | Libraries | Version | Linkage | License | Description | |------------------------------------------------------------|---------|-------------|-------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------| -| [MethaneKit](https://github.com/MethanePowered/MethaneKit) | 0.6.5 | Static | [Apache 2.0](https://github.com/MethanePowered/MethaneKit/blob/master/LICENSE) | Modern 3D graphics made simple with C++17 cross-platform framework and rendering abstraction API on top of DirectX 12, Metal & Vulkan. | +| [MethaneKit](https://github.com/MethanePowered/MethaneKit) | 0.7.1 | Static | [Apache 2.0](https://github.com/MethanePowered/MethaneKit/blob/master/LICENSE) | Modern 3D graphics made simple with C++17 cross-platform framework and rendering abstraction API on top of DirectX 12, Metal & Vulkan. | | [Perlin Noise](https://github.com/stegu/perlin-noise/) | 1.0 | Static | [Public Domain](https://github.com/stegu/perlin-noise/blob/master/LICENSE.md) | Simplex and Perlin noise implementation by Stefan Gustavson. | | [HLSL++](https://github.com/redorav/hlslpp) | 3.2 | Header-only | [MIT](https://github.com/MethanePowered/HLSLpp/blob/master/LICENSE) | Math library using hlsl syntax with SSE/NEON support. | | [Tracy](https://github.com/wolfpld/tracy) | 0.8.2.1 | Static | [BSD 3.0](https://github.com/wolfpld/tracy/blob/master/LICENSE) | A real time, nanosecond resolution, remote telemetry, hybrid frame and sampling profiler for games and other applications. | @@ -24,7 +24,7 @@ to support parallel cmake configurations processing. | Libraries | Version | Usage | License | Description | |-------------------------------------------------------------------------------|-----------|--------------------------|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------| -| [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) | 0.35.1 | CMake | [MIT](https://github.com/cpm-cmake/CPM.cmake/blob/master/LICENSE) | CMake's missing package manager. | +| [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) | 0.37.0 | CMake | [MIT](https://github.com/cpm-cmake/CPM.cmake/blob/master/LICENSE) | CMake's missing package manager. | | [CMRC](https://github.com/vector-of-bool/cmrc) | n/a | CMake | [MIT](https://github.com/vector-of-bool/cmrc/blob/master/LICENSE.txt) | A Resource Compiler in a Single CMake script. | | [iOS-Toolchain.cmake](https://github.com/leetal/ios-cmake) | 4.3.0 | CMake | [BSD 3.0](https://github.com/leetal/ios-cmake/blob/master/LICENSE.md) | A CMake toolchain file for iOS, macOS, watchOS & tvOS C/C++/Obj-C++ development. | | [DirectX Shader Compiler](https://github.com/microsoft/DirectXShaderCompiler) | 1.6.2104 | HLSL Compiler to SPIRV | [LLVM Release](https://github.com/microsoft/DirectXShaderCompiler/blob/main/LICENSE.TXT) | Open-source HLSL Shader Compiler which is based on LLVM/Clang. | diff --git a/Modules/Simulation/Asteroid.cpp b/Modules/Simulation/Asteroid.cpp index bf3688e..0fbe1d6 100644 --- a/Modules/Simulation/Asteroid.cpp +++ b/Modules/Simulation/Asteroid.cpp @@ -23,11 +23,14 @@ Random generated asteroid model with mesh and texture ready for rendering #include "Asteroid.h" -#include +#include #include #include +#include + #include +#include namespace Methane::Samples { @@ -101,24 +104,31 @@ void Asteroid::Mesh::Randomize(uint32_t random_seed) ComputeAverageNormals(); } -Asteroid::Asteroid(gfx::CommandQueue& render_cmd_queue) +Asteroid::Asteroid(const rhi::RenderContext& render_context, const rhi::CommandQueue& render_cmd_queue) : BaseBuffers(render_cmd_queue, Mesh(3, true), "Asteroid") { META_FUNCTION_TASK(); - SetTexture(GenerateTextureArray(render_cmd_queue, gfx::Dimensions(256, 256), 1, true, TextureNoiseParameters())); + SetTexture(GenerateTextureArray(render_context, render_cmd_queue, + gfx::Dimensions(256, 256), 1, true, + TextureNoiseParameters())); } -Ptr Asteroid::GenerateTextureArray(gfx::CommandQueue& render_cmd_queue, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped, - const TextureNoiseParameters& noise_parameters) +rhi::Texture Asteroid::GenerateTextureArray(const rhi::RenderContext& render_context, + const rhi::CommandQueue& render_cmd_queue, + const gfx::Dimensions& dimensions, + uint32_t array_size, bool mipmapped, + const TextureNoiseParameters& noise_parameters) { META_FUNCTION_TASK(); - const gfx::Resource::SubResources sub_resources = GenerateTextureArraySubresources(dimensions, array_size, noise_parameters); - Ptr texture_array_ptr = gfx::Texture::CreateImage(render_cmd_queue.GetContext(), dimensions, array_size, gfx::PixelFormat::RGBA8Unorm, mipmapped); - texture_array_ptr->SetData(sub_resources, render_cmd_queue); - return texture_array_ptr; + const rhi::SubResources sub_resources = GenerateTextureArraySubResources(dimensions, array_size, noise_parameters); + rhi::Texture texture_array = render_context.CreateTexture( + rhi::TextureSettings::ForImage(dimensions, array_size, gfx::PixelFormat::RGBA8Unorm, mipmapped)); + texture_array.SetData(sub_resources, render_cmd_queue); + return texture_array; } -gfx::Resource::SubResources Asteroid::GenerateTextureArraySubresources(const gfx::Dimensions& dimensions, uint32_t array_size, const TextureNoiseParameters& noise_parameters) +rhi::SubResources Asteroid::GenerateTextureArraySubResources(const gfx::Dimensions& dimensions, uint32_t array_size, + const TextureNoiseParameters& noise_parameters) { META_FUNCTION_TASK(); const gfx::PixelFormat pixel_format = gfx::PixelFormat::RGBA8Unorm; @@ -126,7 +136,7 @@ gfx::Resource::SubResources Asteroid::GenerateTextureArraySubresources(const gfx const uint32_t pixels_count = dimensions.GetPixelsCount(); const uint32_t row_stride = pixel_size * dimensions.GetWidth(); - gfx::Resource::SubResources sub_resources; + rhi::SubResources sub_resources; sub_resources.reserve(array_size); std::mt19937 rng(noise_parameters.random_seed); // NOSONAR - using pseudorandom generator is safe here @@ -141,7 +151,7 @@ gfx::Resource::SubResources Asteroid::GenerateTextureArraySubresources(const gfx noise_parameters.scale, noise_parameters.strength); - sub_resources.emplace_back(std::move(sub_resource_data), gfx::Resource::SubResource::Index{ 0, array_index }); + sub_resources.emplace_back(std::move(sub_resource_data), rhi::SubResource::Index{ 0, array_index }); } return sub_resources; diff --git a/Modules/Simulation/Asteroid.h b/Modules/Simulation/Asteroid.h index fe415f8..05637fa 100644 --- a/Modules/Simulation/Asteroid.h +++ b/Modules/Simulation/Asteroid.h @@ -23,9 +23,10 @@ Random generated asteroid model with mesh and texture ready for rendering. #pragma once -#include +#include #include #include +#include namespace hlslpp // NOSONAR { @@ -40,8 +41,10 @@ namespace Methane::Samples { namespace gfx = Graphics; +namespace rhi = Graphics::Rhi; -class Asteroid final : public gfx::TexturedMeshBuffers +class Asteroid final + : public gfx::TexturedMeshBuffers { public: using BaseBuffers = gfx::TexturedMeshBuffers; @@ -101,12 +104,16 @@ class Asteroid final : public gfx::TexturedMeshBuffers float strength = 1.5F; }; - explicit Asteroid(gfx::CommandQueue& render_cmd_queue); + explicit Asteroid(const rhi::RenderContext& render_context, const rhi::CommandQueue& render_cmd_queue); - static Ptr GenerateTextureArray(gfx::CommandQueue& render_cmd_queue, const gfx::Dimensions& dimensions, - uint32_t array_size, bool mipmapped, const TextureNoiseParameters& noise_parameters); - static gfx::Resource::SubResources GenerateTextureArraySubresources(const gfx::Dimensions& dimensions, uint32_t array_size, - const TextureNoiseParameters& noise_parameters); + static rhi::Texture GenerateTextureArray(const rhi::RenderContext& render_context, + const rhi::CommandQueue& render_cmd_queue, + const gfx::Dimensions& dimensions, + uint32_t array_size, bool mipmapped, + const TextureNoiseParameters& noise_parameters); + static rhi::SubResources GenerateTextureArraySubResources(const gfx::Dimensions& dimensions, + uint32_t array_size, + const TextureNoiseParameters& noise_parameters); static constexpr size_t color_schema_size = 6U; static Colors GetAsteroidRockColors(uint32_t deep_color_index, uint32_t shallow_color_index); diff --git a/Modules/Simulation/AsteroidsArray.cpp b/Modules/Simulation/AsteroidsArray.cpp index 52da174..a5fc17f 100644 --- a/Modules/Simulation/AsteroidsArray.cpp +++ b/Modules/Simulation/AsteroidsArray.cpp @@ -24,6 +24,12 @@ Random generated asteroids array with uber mesh and textures ready for rendering #include "AsteroidsArray.h" #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -59,7 +65,7 @@ AsteroidsArray::UberMesh::UberMesh(tf::Executor& parallel_executor, uint32_t ins m_depth_ranges.reserve(static_cast(m_instance_count) * m_subdivisions_count); std::mt19937 rng(random_seed); // NOSONAR - using pseudorandom generator is safe here - TracyLockable(std::mutex, data_mutex) + TracyLockable(std::mutex, data_mutex); for (uint32_t subdivision_index = 0; subdivision_index < m_subdivisions_count; ++subdivision_index) { @@ -106,7 +112,6 @@ const Asteroid::Mesh::DepthRange& AsteroidsArray::UberMesh::GetSubsetDepthRange( { META_FUNCTION_TASK(); META_CHECK_ARG_LESS(subset_index, GetSubsetCount()); - assert(subset_index < m_depth_ranges.size()); return m_depth_ranges[subset_index]; } @@ -126,7 +131,7 @@ AsteroidsArray::ContentState::ContentState(tf::Executor& parallel_executor, cons texture_array_subresources.resize(settings.textures_count); tf::Taskflow task_flow; task_flow.for_each(texture_array_subresources.begin(), texture_array_subresources.end(), - [&rng, &noise_persistence_distribution, &noise_scale_distribution, &settings](gfx::Resource::SubResources& sub_resources) + [&rng, &noise_persistence_distribution, &noise_scale_distribution, &settings](rhi::SubResources& sub_resources) { Asteroid::TextureNoiseParameters noise_parameters{ static_cast(rng()), //NOSONAR @@ -134,7 +139,7 @@ AsteroidsArray::ContentState::ContentState(tf::Executor& parallel_executor, cons noise_scale_distribution(rng), 1.5F }; - sub_resources = Asteroid::GenerateTextureArraySubresources(settings.texture_dimensions, 3, noise_parameters); + sub_resources = Asteroid::GenerateTextureArraySubResources(settings.texture_dimensions, 3, noise_parameters); } ); parallel_executor.run(task_flow).get(); @@ -201,16 +206,22 @@ AsteroidsArray::ContentState::ContentState(tf::Executor& parallel_executor, cons } } -AsteroidsArray::AsteroidsArray(gfx::CommandQueue& render_cmd_queue, gfx::RenderPattern& render_pattern, const Settings& settings) - : AsteroidsArray(render_cmd_queue, render_pattern, settings, *std::make_shared(render_pattern.GetRenderContext().GetParallelExecutor(), settings)) +AsteroidsArray::AsteroidsArray(const rhi::CommandQueue& render_cmd_queue, + const rhi::RenderPattern& render_pattern, + const Settings& settings) + : AsteroidsArray(render_cmd_queue, render_pattern, settings, + *std::make_shared(render_pattern.GetRenderContext().GetParallelExecutor(), settings)) { META_FUNCTION_TASK(); } -AsteroidsArray::AsteroidsArray(gfx::CommandQueue& render_cmd_queue, gfx::RenderPattern& render_pattern, const Settings& settings, ContentState& state) +AsteroidsArray::AsteroidsArray(const rhi::CommandQueue& render_cmd_queue, + const rhi::RenderPattern& render_pattern, + const Settings& settings, + ContentState& state) : BaseBuffers(render_cmd_queue, state.uber_mesh, "Asteroids Array") , m_settings(settings) - , m_render_cmd_queue_ptr(std::dynamic_pointer_cast(render_cmd_queue.GetPtr())) + , m_render_cmd_queue(render_cmd_queue) , m_content_state_ptr(state.shared_from_this()) , m_mesh_subset_by_instance_index(m_settings.instance_count, 0U) , m_min_mesh_lod_screen_size_log_2(std::log2(m_settings.mesh_lod_min_screen_size)) @@ -218,54 +229,57 @@ AsteroidsArray::AsteroidsArray(gfx::CommandQueue& render_cmd_queue, gfx::RenderP META_FUNCTION_TASK(); META_SCOPE_TIMER("AsteroidsArray::AsteroidsArray"); - const gfx::RenderContext& context = render_pattern.GetRenderContext(); + const rhi::RenderContext& context = render_pattern.GetRenderContext(); const size_t textures_array_size = m_settings.textures_array_enabled ? m_settings.textures_count : 1; - const gfx::Shader::MacroDefinitions macro_definitions{ { "TEXTURES_COUNT", std::to_string(textures_array_size) } }; + const rhi::Shader::MacroDefinitions macro_definitions{ { "TEXTURES_COUNT", std::to_string(textures_array_size) } }; - gfx::RenderState::Settings state_settings; - state_settings.program_ptr = gfx::Program::Create(context, - gfx::Program::Settings + rhi::RenderState::Settings state_settings; + state_settings.program = context.CreateProgram( + rhi::Program::Settings { - gfx::Program::Shaders + rhi::Program::ShaderSet { - gfx::Shader::CreateVertex(context, { Data::ShaderProvider::Get(), { "Asteroids", "AsteroidVS" }, macro_definitions }), - gfx::Shader::CreatePixel( context, { Data::ShaderProvider::Get(), { "Asteroids", "AsteroidPS" }, macro_definitions }), + { rhi::ShaderType::Vertex, { Data::ShaderProvider::Get(), { "Asteroids", "AsteroidVS" }, macro_definitions } }, + { rhi::ShaderType::Pixel, { Data::ShaderProvider::Get(), { "Asteroids", "AsteroidPS" }, macro_definitions } } }, - gfx::Program::InputBufferLayouts + rhi::Program::InputBufferLayouts { - gfx::Program::InputBufferLayout { state.uber_mesh.GetVertexLayout().GetSemantics() } + rhi::Program::InputBufferLayout { state.uber_mesh.GetVertexLayout().GetSemantics() } }, - gfx::Program::ArgumentAccessors + rhi::Program::ArgumentAccessors { - { { gfx::Shader::Type::All, "g_mesh_uniforms" }, gfx::Program::ArgumentAccessor::Type::Mutable, true }, - { { gfx::Shader::Type::All, "g_scene_uniforms" }, gfx::Program::ArgumentAccessor::Type::FrameConstant }, - { { gfx::Shader::Type::Pixel, "g_constants" }, gfx::Program::ArgumentAccessor::Type::Constant }, - { { gfx::Shader::Type::Pixel, "g_texture_sampler"}, gfx::Program::ArgumentAccessor::Type::Constant }, - { { gfx::Shader::Type::Pixel, "g_face_textures" }, m_settings.textures_array_enabled - ? gfx::Program::ArgumentAccessor::Type::Constant - : gfx::Program::ArgumentAccessor::Type::Mutable }, + { { rhi::ShaderType::All, "g_mesh_uniforms" }, rhi::Program::ArgumentAccessor::Type::Mutable, true }, + { { rhi::ShaderType::All, "g_scene_uniforms" }, rhi::Program::ArgumentAccessor::Type::FrameConstant }, + { { rhi::ShaderType::Pixel, "g_constants" }, rhi::Program::ArgumentAccessor::Type::Constant }, + { { rhi::ShaderType::Pixel, "g_texture_sampler"}, rhi::Program::ArgumentAccessor::Type::Constant }, + { { rhi::ShaderType::Pixel, "g_face_textures" }, m_settings.textures_array_enabled + ? rhi::Program::ArgumentAccessor::Type::Constant + : rhi::Program::ArgumentAccessor::Type::Mutable }, }, render_pattern.GetAttachmentFormats() } ); - state_settings.program_ptr->SetName("Asteroid Shaders"); - state_settings.render_pattern_ptr = std::dynamic_pointer_cast(render_pattern.GetPtr()); + state_settings.program.SetName("Asteroid Shaders"); + state_settings.render_pattern = render_pattern; state_settings.depth.enabled = true; state_settings.depth.compare = m_settings.depth_reversed ? gfx::Compare::GreaterEqual : gfx::Compare::Less; - m_render_state_ptr = gfx::RenderState::Create(context, state_settings); - m_render_state_ptr->SetName("Asteroids Render State"); + m_render_state = context.CreateRenderState(state_settings); + m_render_state.SetName("Asteroids Render State"); SetInstanceCount(m_settings.instance_count); // Create texture arrays initialized with sub-resources data uint32_t texture_index = 0U; m_unique_textures.reserve(m_settings.textures_count); - for(const gfx::Resource::SubResources& texture_subresources : m_content_state_ptr->texture_array_subresources) + for(const rhi::SubResources& texture_subresources : m_content_state_ptr->texture_array_subresources) { - m_unique_textures.emplace_back(gfx::Texture::CreateImage(context, m_settings.texture_dimensions, static_cast(texture_subresources.size()), gfx::PixelFormat::RGBA8Unorm, true)); - m_unique_textures.back()->SetData(texture_subresources, *m_render_cmd_queue_ptr); - m_unique_textures.back()->SetName(fmt::format("Asteroid Texture {:d}", texture_index)); + m_unique_textures.emplace_back(context.CreateTexture( + rhi::TextureSettings::ForImage(m_settings.texture_dimensions, + static_cast(texture_subresources.size()), + gfx::PixelFormat::RGBA8Unorm, true))); + m_unique_textures.back().SetData(texture_subresources, m_render_cmd_queue); + m_unique_textures.back().SetName(fmt::format("Asteroid Texture {:d}", texture_index)); texture_index++; } @@ -277,60 +291,60 @@ AsteroidsArray::AsteroidsArray(gfx::CommandQueue& render_cmd_queue, gfx::RenderP SetSubsetTexture(m_unique_textures[subset_texture_index], subset_index); } - m_texture_sampler_ptr = gfx::Sampler::Create(context, { - gfx::Sampler::Filter(gfx::Sampler::Filter::MinMag::Linear), - gfx::Sampler::Address(gfx::Sampler::Address::Mode::ClampToZero) + m_texture_sampler = context.CreateSampler({ + rhi::Sampler::Filter(rhi::Sampler::Filter::MinMag::Linear), + rhi::Sampler::Address(rhi::Sampler::Address::Mode::ClampToZero) }); - m_texture_sampler_ptr->SetName("Asteroid Texture Sampler"); + m_texture_sampler.SetName("Asteroid Texture Sampler"); // Initialize default uniforms to be ready to render right aways Update(0.0, 0.0); } - -Ptrs AsteroidsArray::CreateProgramBindings(const Ptr& constants_buffer_ptr, - const Ptr& scene_uniforms_buffer_ptr, - const Ptr& asteroids_uniforms_buffer_ptr, - Data::Index frame_index) const + +std::vector AsteroidsArray::CreateProgramBindings(const rhi::Buffer& constants_buffer, + const rhi::Buffer& scene_uniforms_buffer, + const rhi::Buffer& asteroids_uniforms_buffer, + Data::Index frame_index) const { META_FUNCTION_TASK(); META_SCOPE_TIMER("AsteroidsArray::CreateProgramBindings"); - Ptrs program_bindings_array; + std::vector program_bindings_array; if (m_settings.instance_count == 0) return program_bindings_array; const Data::Size uniform_data_size = MeshBuffers::GetAlignedUniformSize(); - const gfx::Resource::Views face_texture_locations = m_settings.textures_array_enabled - ? gfx::Resource::CreateViews(m_unique_textures) - : gfx::Resource::Views{ { GetInstanceTexture() } }; + const rhi::ResourceViews face_texture_locations = m_settings.textures_array_enabled + ? rhi::CreateResourceViews(m_unique_textures) + : rhi::CreateResourceViews(GetInstanceTexture()); program_bindings_array.resize(m_settings.instance_count); - program_bindings_array[0] = gfx::ProgramBindings::Create(m_render_state_ptr->GetSettings().program_ptr, { - { { gfx::Shader::Type::All, "g_mesh_uniforms" }, { { *asteroids_uniforms_buffer_ptr, GetUniformsBufferOffset(0), uniform_data_size } } }, - { { gfx::Shader::Type::All, "g_scene_uniforms" }, { { *scene_uniforms_buffer_ptr } } }, - { { gfx::Shader::Type::Pixel, "g_constants" }, { { *constants_buffer_ptr } } }, - { { gfx::Shader::Type::Pixel, "g_face_textures" }, face_texture_locations }, - { { gfx::Shader::Type::Pixel, "g_texture_sampler"}, { { *m_texture_sampler_ptr } } }, + program_bindings_array[0] = m_render_state.GetProgram().CreateBindings({ + { { rhi::ShaderType::All, "g_mesh_uniforms" }, { { asteroids_uniforms_buffer.GetInterface(), GetUniformsBufferOffset(0), uniform_data_size } } }, + { { rhi::ShaderType::All, "g_scene_uniforms" }, { { scene_uniforms_buffer.GetInterface() } } }, + { { rhi::ShaderType::Pixel, "g_constants" }, { { constants_buffer.GetInterface() } } }, + { { rhi::ShaderType::Pixel, "g_face_textures" }, face_texture_locations }, + { { rhi::ShaderType::Pixel, "g_texture_sampler"}, { { m_texture_sampler.GetInterface() } } }, }, frame_index); - program_bindings_array[0]->SetName(fmt::format("Asteroids[0] Bindings {}", frame_index)); + program_bindings_array[0].SetName(fmt::format("Asteroids[0] Bindings {}", frame_index)); tf::Taskflow task_flow; task_flow.for_each_index(1U, m_settings.instance_count, 1U, - [this, &program_bindings_array, &asteroids_uniforms_buffer_ptr, uniform_data_size, frame_index](const uint32_t asteroid_index) + [this, &program_bindings_array, &asteroids_uniforms_buffer, uniform_data_size, frame_index](const uint32_t asteroid_index) { const Data::Size asteroid_uniform_offset = GetUniformsBufferOffset(asteroid_index); META_CHECK_ARG_EQUAL(asteroid_uniform_offset % 256, 0); - gfx::ProgramBindings::ResourceViewsByArgument set_resource_view_by_argument{ - { { gfx::Shader::Type::All, "g_mesh_uniforms" }, { { *asteroids_uniforms_buffer_ptr, asteroid_uniform_offset, uniform_data_size } } }, + rhi::ProgramBindings::ResourceViewsByArgument set_resource_view_by_argument{ + { { rhi::ShaderType::All, "g_mesh_uniforms" }, { { asteroids_uniforms_buffer.GetInterface(), asteroid_uniform_offset, uniform_data_size } } }, }; if (!m_settings.textures_array_enabled) { set_resource_view_by_argument.insert( - { { gfx::Shader::Type::Pixel, "g_face_textures" }, { { GetInstanceTexture(asteroid_index) } } } + { { rhi::ShaderType::Pixel, "g_face_textures" }, { { GetInstanceTexture(asteroid_index).GetInterface() } } } ); } - program_bindings_array[asteroid_index] = gfx::ProgramBindings::CreateCopy(*program_bindings_array[0], set_resource_view_by_argument, frame_index); - program_bindings_array[asteroid_index]->SetName(fmt::format("Asteroids[{}] Bindings {}", asteroid_index, frame_index)); + program_bindings_array[asteroid_index] = rhi::ProgramBindings(program_bindings_array[0], set_resource_view_by_argument, frame_index); + program_bindings_array[asteroid_index].SetName(fmt::format("Asteroids[{}] Bindings {}", asteroid_index, frame_index)); } ); GetContext().GetParallelExecutor().run(task_flow).get(); @@ -357,60 +371,59 @@ bool AsteroidsArray::Update(double elapsed_seconds, double /*delta_seconds*/) return true; } -void AsteroidsArray::Draw(gfx::RenderCommandList &cmd_list, +void AsteroidsArray::Draw(const rhi::RenderCommandList& cmd_list, const gfx::InstancedMeshBufferBindings& buffer_bindings, - gfx::ViewState& view_state) + const rhi::ViewState& view_state) { META_FUNCTION_TASK(); META_SCOPE_TIMER("AsteroidsArray::Draw"); - META_DEBUG_GROUP_CREATE_VAR(s_debug_group, "Asteroids rendering"); - - META_CHECK_ARG_NOT_NULL(buffer_bindings.uniforms_buffer_ptr); - META_CHECK_ARG_GREATER_OR_EQUAL(buffer_bindings.uniforms_buffer_ptr->GetDataSize(), GetUniformsBufferSize()); + META_CHECK_ARG_GREATER_OR_EQUAL(buffer_bindings.uniforms_buffer.GetDataSize(), GetUniformsBufferSize()); // Upload uniforms buffer data to GPU asynchronously while encoding drawing commands on CPU auto uniforms_update_future = std::async([this, &buffer_bindings]() { - buffer_bindings.uniforms_buffer_ptr->SetData(GetFinalPassUniformsSubresources(), *m_render_cmd_queue_ptr); + buffer_bindings.uniforms_buffer.SetData(GetFinalPassUniformsSubresources(), m_render_cmd_queue); }); - cmd_list.ResetWithState(*m_render_state_ptr, s_debug_group.get()); + META_DEBUG_GROUP_VAR(s_debug_group, "Asteroids rendering"); + cmd_list.ResetWithState(m_render_state, &s_debug_group); cmd_list.SetViewState(view_state); META_CHECK_ARG_EQUAL(buffer_bindings.program_bindings_per_instance.size(), m_settings.instance_count); BaseBuffers::Draw( - cmd_list, buffer_bindings.program_bindings_per_instance, - gfx::ProgramBindings::ApplyBehavior::ConstantOnce, 0, // Constant bindings are applied once mutable always, resource barriers are not set to reduce overhead - true, // Bound resources are not retained by command lists to reduce overhead from the huge amount of bindings - false // Do not set resource barriers for Vertex and Index buffers since their state does not change and to reduce runtime overhead + cmd_list, + buffer_bindings.program_bindings_per_instance, + { rhi::ProgramBindings::ApplyBehavior::ConstantOnce }, // Constant bindings are applied once mutable always, resource barriers are not set to reduce overhead + 0, + true, // Bound resources are not retained by command lists to reduce overhead from the huge amount of bindings + false // Do not set resource barriers for Vertex and Index buffers since their state does not change and to reduce runtime overhead ); // Make sure that uniforms have finished uploading to GPU uniforms_update_future.wait(); } -void AsteroidsArray::DrawParallel(gfx::ParallelRenderCommandList& parallel_cmd_list, +void AsteroidsArray::DrawParallel(const rhi::ParallelRenderCommandList& parallel_cmd_list, const gfx::InstancedMeshBufferBindings& buffer_bindings, - gfx::ViewState& view_state) + const rhi::ViewState& view_state) { META_FUNCTION_TASK(); META_SCOPE_TIMER("AsteroidsArray::DrawParallel"); - META_DEBUG_GROUP_CREATE_VAR(s_debug_group, "Parallel Asteroids rendering"); - - META_CHECK_ARG_NOT_NULL(buffer_bindings.uniforms_buffer_ptr); - META_CHECK_ARG_GREATER_OR_EQUAL(buffer_bindings.uniforms_buffer_ptr->GetDataSize(), GetUniformsBufferSize()); + META_CHECK_ARG_GREATER_OR_EQUAL(buffer_bindings.uniforms_buffer.GetDataSize(), GetUniformsBufferSize()); // Upload uniforms buffer data to GPU asynchronously while encoding drawing commands on CPU auto uniforms_update_future = std::async([this, &buffer_bindings]() { - buffer_bindings.uniforms_buffer_ptr->SetData(GetFinalPassUniformsSubresources(), *m_render_cmd_queue_ptr); + buffer_bindings.uniforms_buffer.SetData(GetFinalPassUniformsSubresources(), m_render_cmd_queue); }); - parallel_cmd_list.ResetWithState(*m_render_state_ptr, s_debug_group.get()); + META_DEBUG_GROUP_VAR(s_debug_group, "Parallel Asteroids rendering"); + parallel_cmd_list.ResetWithState(m_render_state, &s_debug_group); parallel_cmd_list.SetViewState(view_state); META_CHECK_ARG_EQUAL(buffer_bindings.program_bindings_per_instance.size(), m_settings.instance_count); BaseBuffers::DrawParallel( - parallel_cmd_list, buffer_bindings.program_bindings_per_instance, - gfx::ProgramBindings::ApplyBehavior::ConstantOnce, // Constant bindings are applied once, mutable always, resource barriers are not set to reduce overhead + parallel_cmd_list, + buffer_bindings.program_bindings_per_instance, + { rhi::ProgramBindings::ApplyBehavior::ConstantOnce }, // Constant bindings are applied once, mutable always, resource barriers are not set to reduce overhead true, // Bound resources are not retained by command lists to reduce overhead from the huge amount of bindings false // Do not set resource barriers for Vertex and Index buffers since their state does not change and to reduce runtime overhead ); diff --git a/Modules/Simulation/AsteroidsArray.h b/Modules/Simulation/AsteroidsArray.h index df6186c..fc8d3a3 100644 --- a/Modules/Simulation/AsteroidsArray.h +++ b/Modules/Simulation/AsteroidsArray.h @@ -24,12 +24,11 @@ Random generated asteroids array with uber-mesh and textures ready for rendering #pragma once #include "Asteroid.h" - -#include -#include -#include -#include +#include +#include +#include #include +#include #include namespace hlslpp // NOSONAR @@ -41,12 +40,23 @@ namespace hlslpp // NOSONAR #include + +namespace Methane::Graphics::Rhi +{ +class RenderPattern; +class ViewState; +class ProgramBindings; +class RenderCommandList; +class ParallelRenderCommandList; +} + namespace Methane::Samples { namespace gfx = Graphics; -class AsteroidsArray final : public gfx::TexturedMeshBuffers +class AsteroidsArray final + : public gfx::TexturedMeshBuffers { public: using BaseBuffers = gfx::TexturedMeshBuffers; @@ -91,7 +101,7 @@ class AsteroidsArray final : public gfx::TexturedMeshBuffers; - using TextureArraySubresources = std::vector; + using TextureArraySubresources = std::vector; struct ContentState : public std::enable_shared_from_this { @@ -105,21 +115,33 @@ class AsteroidsArray final : public gfx::TexturedMeshBuffers& GetState() const { return m_content_state_ptr; } using BaseBuffers::GetUniformsBufferSize; - Ptrs CreateProgramBindings(const Ptr& constants_buffer_ptr, - const Ptr& scene_uniforms_buffer_ptr, - const Ptr& asteroids_uniforms_buffer_ptr, - Data::Index frame_index) const; + std::vector CreateProgramBindings(const rhi::Buffer& constants_buffer, + const rhi::Buffer& scene_uniforms_buffer, + const rhi::Buffer& asteroids_uniforms_buffer, + Data::Index frame_index) const; bool Update(double elapsed_seconds, double delta_seconds); - void Draw(gfx::RenderCommandList& cmd_list, const gfx::InstancedMeshBufferBindings& buffer_bindings, gfx::ViewState& view_state); - void DrawParallel(gfx::ParallelRenderCommandList& parallel_cmd_list, const gfx::InstancedMeshBufferBindings& buffer_bindings, gfx::ViewState& view_state); + + void Draw(const rhi::RenderCommandList& cmd_list, + const gfx::InstancedMeshBufferBindings& buffer_bindings, + const rhi::ViewState& view_state); + + void DrawParallel(const rhi::ParallelRenderCommandList& parallel_cmd_list, + const gfx::InstancedMeshBufferBindings& buffer_bindings, + const rhi::ViewState& view_state); [[nodiscard]] bool IsMeshLodColoringEnabled() const { return m_mesh_lod_coloring_enabled; } void SetMeshLodColoringEnabled(bool mesh_lod_coloring_enabled) { m_mesh_lod_coloring_enabled = mesh_lod_coloring_enabled; } @@ -134,17 +156,19 @@ class AsteroidsArray final : public gfx::TexturedMeshBuffers; - void UpdateAsteroidUniforms(const Asteroid::Parameters& asteroid_parameters, const hlslpp::float3& eye_position, float elapsed_radians); - - const Settings m_settings; - const Ptr m_render_cmd_queue_ptr; - Ptr m_content_state_ptr; - Textures m_unique_textures; - Ptr m_texture_sampler_ptr; - Ptr m_render_state_ptr; - MeshSubsetByInstanceIndex m_mesh_subset_by_instance_index; - bool m_mesh_lod_coloring_enabled = false; - float m_min_mesh_lod_screen_size_log_2; + void UpdateAsteroidUniforms(const Asteroid::Parameters& asteroid_parameters, + const hlslpp::float3& eye_position, + float elapsed_radians); + + Settings m_settings; + rhi::CommandQueue m_render_cmd_queue; + Ptr m_content_state_ptr; + Textures m_unique_textures; + rhi::Sampler m_texture_sampler; + rhi::RenderState m_render_state; + MeshSubsetByInstanceIndex m_mesh_subset_by_instance_index; + bool m_mesh_lod_coloring_enabled = false; + float m_min_mesh_lod_screen_size_log_2; }; } // namespace Methane::Samples diff --git a/Modules/Simulation/Planet.cpp b/Modules/Simulation/Planet.cpp index 40b5ba8..d3d580a 100644 --- a/Modules/Simulation/Planet.cpp +++ b/Modules/Simulation/Planet.cpp @@ -23,93 +23,95 @@ Planet rendering primitive #include "Planet.h" -#include +#include #include -#include -#include #include #include namespace Methane::Samples { -Planet::Planet(gfx::CommandQueue& render_cmd_queue, gfx::RenderPattern& render_pattern, const gfx::ImageLoader& image_loader, const Settings& settings) +Planet::Planet(const rhi::CommandQueue& render_cmd_queue, + const rhi::RenderPattern& render_pattern, + const gfx::ImageLoader& image_loader, + const Settings& settings) : Planet(render_cmd_queue, render_pattern, image_loader, settings, gfx::SphereMesh(Vertex::layout, 1.F, 32, 32)) { META_FUNCTION_TASK(); } -Planet::Planet(gfx::CommandQueue& render_cmd_queue, gfx::RenderPattern& render_pattern, const gfx::ImageLoader& image_loader, const Settings& settings, const gfx::BaseMesh& mesh) +Planet::Planet(const rhi::CommandQueue& render_cmd_queue, + const rhi::RenderPattern& render_pattern, + const gfx::ImageLoader& image_loader, + const Settings& settings, + const gfx::BaseMesh& mesh) : m_settings(settings) , m_context(render_pattern.GetRenderContext()) - , m_render_cmd_queue_ptr(std::dynamic_pointer_cast(render_cmd_queue.GetPtr())) + , m_render_cmd_queue(render_cmd_queue) , m_mesh_buffers(render_cmd_queue, mesh, "Planet") { META_FUNCTION_TASK(); - - gfx::RenderState::Settings state_settings; - state_settings.program_ptr = gfx::Program::Create(m_context, - gfx::Program::Settings + rhi::RenderState::Settings state_settings; + state_settings.program = m_context.CreateProgram( + rhi::Program::Settings { - gfx::Program::Shaders + rhi::Program::ShaderSet { - gfx::Shader::CreateVertex(m_context, { Data::ShaderProvider::Get(), { "Planet", "PlanetVS" }, { } }), - gfx::Shader::CreatePixel( m_context, { Data::ShaderProvider::Get(), { "Planet", "PlanetPS" }, { } }), + { rhi::ShaderType::Vertex, { Data::ShaderProvider::Get(), { "Planet", "PlanetVS" }, { } } }, + { rhi::ShaderType::Pixel, { Data::ShaderProvider::Get(), { "Planet", "PlanetPS" }, { } } } }, - gfx::Program::InputBufferLayouts + rhi::Program::InputBufferLayouts { - gfx::Program::InputBufferLayout { mesh.GetVertexLayout().GetSemantics() } + rhi::Program::InputBufferLayout { mesh.GetVertexLayout().GetSemantics() } }, - gfx::Program::ArgumentAccessors + rhi::Program::ArgumentAccessors { - { { gfx::Shader::Type::All, "g_uniforms" }, gfx::Program::ArgumentAccessor::Type::FrameConstant }, - { { gfx::Shader::Type::Pixel, "g_constants" }, gfx::Program::ArgumentAccessor::Type::Constant }, - { { gfx::Shader::Type::Pixel, "g_texture" }, gfx::Program::ArgumentAccessor::Type::Constant }, - { { gfx::Shader::Type::Pixel, "g_sampler" }, gfx::Program::ArgumentAccessor::Type::Constant }, + { { rhi::ShaderType::All, "g_uniforms" }, rhi::Program::ArgumentAccessor::Type::FrameConstant }, + { { rhi::ShaderType::Pixel, "g_constants" }, rhi::Program::ArgumentAccessor::Type::Constant }, + { { rhi::ShaderType::Pixel, "g_texture" }, rhi::Program::ArgumentAccessor::Type::Constant }, + { { rhi::ShaderType::Pixel, "g_sampler" }, rhi::Program::ArgumentAccessor::Type::Constant }, }, render_pattern.GetAttachmentFormats() } ); - state_settings.program_ptr->SetName("Planet Shaders"); - state_settings.render_pattern_ptr = std::dynamic_pointer_cast(render_pattern.GetPtr()); + state_settings.program.SetName("Planet Shaders"); + state_settings.render_pattern = render_pattern; state_settings.depth.enabled = true; state_settings.depth.compare = m_settings.depth_reversed ? gfx::Compare::GreaterEqual : gfx::Compare::Less; - m_render_state_ptr = gfx::RenderState::Create(m_context, state_settings); - m_render_state_ptr->SetName("Planet Render State"); + m_render_state = m_context.CreateRenderState(state_settings); + m_render_state.SetName("Planet Render State"); m_mesh_buffers.SetTexture(image_loader.LoadImageToTexture2D(render_cmd_queue, m_settings.texture_path, m_settings.image_options, "Planet Texture")); - m_texture_sampler_ptr = gfx::Sampler::Create(m_context, { - gfx::Sampler::Filter(gfx::Sampler::Filter::MinMag::Linear), - gfx::Sampler::Address(gfx::Sampler::Address::Mode::ClampToEdge), - gfx::Sampler::LevelOfDetail(m_settings.lod_bias) + m_texture_sampler = m_context.CreateSampler({ + rhi::Sampler::Filter(rhi::Sampler::Filter::MinMag::Linear), + rhi::Sampler::Address(rhi::Sampler::Address::Mode::ClampToEdge), + rhi::Sampler::LevelOfDetail(m_settings.lod_bias) }); - m_texture_sampler_ptr->SetName("Planet Texture Sampler"); + m_texture_sampler.SetName("Planet Texture Sampler"); // Initialize default uniforms to be ready to render right away Update(0.0, 0.0); } -Ptr Planet::CreateProgramBindings(const Ptr& constants_buffer_ptr, const Ptr& uniforms_buffer_ptr, Data::Index frame_index) const +rhi::ProgramBindings Planet::CreateProgramBindings(const rhi::Buffer& constants_buffer, + const rhi::Buffer& uniforms_buffer, + Data::Index frame_index) const { META_FUNCTION_TASK(); - META_CHECK_ARG_NOT_NULL(m_render_state_ptr); - META_CHECK_ARG_NOT_NULL(m_render_state_ptr->GetSettings().program_ptr); - - return gfx::ProgramBindings::Create(m_render_state_ptr->GetSettings().program_ptr, { - { { gfx::Shader::Type::All, "g_uniforms" }, { { *uniforms_buffer_ptr } } }, - { { gfx::Shader::Type::Pixel, "g_constants" }, { { *constants_buffer_ptr } } }, - { { gfx::Shader::Type::Pixel, "g_texture" }, { { m_mesh_buffers.GetTexture() } } }, - { { gfx::Shader::Type::Pixel, "g_sampler" }, { { *m_texture_sampler_ptr } } }, + return m_render_state.GetProgram().CreateBindings({ + { { rhi::ShaderType::All, "g_uniforms" }, { { uniforms_buffer.GetInterface() } } }, + { { rhi::ShaderType::Pixel, "g_constants" }, { { constants_buffer.GetInterface() } } }, + { { rhi::ShaderType::Pixel, "g_texture" }, { { m_mesh_buffers.GetTexture().GetInterface() } } }, + { { rhi::ShaderType::Pixel, "g_sampler" }, { { m_texture_sampler.GetInterface() } } }, }, frame_index); } bool Planet::Update(double elapsed_seconds, double) { META_FUNCTION_TASK(); - const hlslpp::float4x4 model_scale_matrix = hlslpp::float4x4::scale(m_settings.scale); const hlslpp::float4x4 model_translate_matrix = hlslpp::float4x4::translation(m_settings.position); const hlslpp::float4x4 model_rotation_matrix = hlslpp::float4x4::rotation_y(static_cast(-m_settings.spin_velocity_rps * elapsed_seconds)); @@ -125,19 +127,18 @@ bool Planet::Update(double elapsed_seconds, double) return true; } -void Planet::Draw(gfx::RenderCommandList& cmd_list, const gfx::MeshBufferBindings& buffer_bindings, gfx::ViewState& view_state) +void Planet::Draw(const rhi::RenderCommandList& cmd_list, + const gfx::MeshBufferBindings& buffer_bindings, + const rhi::ViewState& view_state) { META_FUNCTION_TASK(); - META_CHECK_ARG_NOT_NULL(buffer_bindings.uniforms_buffer_ptr); - META_CHECK_ARG_GREATER_OR_EQUAL(buffer_bindings.uniforms_buffer_ptr->GetDataSize(), sizeof(hlslpp::PlanetUniforms)); - META_CHECK_ARG_NOT_NULL(buffer_bindings.program_bindings_ptr); - - buffer_bindings.uniforms_buffer_ptr->SetData(m_mesh_buffers.GetFinalPassUniformsSubresources(), *m_render_cmd_queue_ptr); + META_CHECK_ARG_GREATER_OR_EQUAL(buffer_bindings.uniforms_buffer.GetDataSize(), sizeof(hlslpp::PlanetUniforms)); + buffer_bindings.uniforms_buffer.SetData(m_mesh_buffers.GetFinalPassUniformsSubresources(), m_render_cmd_queue); - META_DEBUG_GROUP_CREATE_VAR(s_debug_group, "Planet Rendering"); - cmd_list.ResetWithState(*m_render_state_ptr, s_debug_group.get()); + META_DEBUG_GROUP_VAR(s_debug_group, "Planet Rendering"); + cmd_list.ResetWithState(m_render_state, &s_debug_group); cmd_list.SetViewState(view_state); - m_mesh_buffers.Draw(cmd_list, *buffer_bindings.program_bindings_ptr); + m_mesh_buffers.Draw(cmd_list, buffer_bindings.program_bindings); } } // namespace Methane::Graphics diff --git a/Modules/Simulation/Planet.h b/Modules/Simulation/Planet.h index ac8ff0f..28e7dc7 100644 --- a/Modules/Simulation/Planet.h +++ b/Modules/Simulation/Planet.h @@ -23,14 +23,18 @@ Planet rendering primitive #pragma once +#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include -#include -#include -#include -#include #include -#include #include namespace hlslpp // NOSONAR @@ -46,6 +50,7 @@ namespace Methane::Samples { namespace gfx = Graphics; +namespace rhi = Graphics::Rhi; struct RenderPattern; @@ -54,22 +59,29 @@ class Planet public: struct Settings { - const gfx::Camera& view_camera; - const gfx::Camera& light_camera; - std::string texture_path; - hlslpp::float3 position; - float scale; - float spin_velocity_rps = 0.3F; // (rps = radians per second) - bool depth_reversed = false; - gfx::ImageLoader::Options image_options = gfx::ImageLoader::Options::None; - float lod_bias = 0.F; + const gfx::Camera& view_camera; + const gfx::Camera& light_camera; + std::string texture_path; + hlslpp::float3 position; + float scale; + float spin_velocity_rps = 0.3F; // (rps = radians per second) + bool depth_reversed = false; + gfx::ImageLoader::OptionMask image_options = {}; + float lod_bias = 0.F; }; - Planet(gfx::CommandQueue& render_cmd_queue, gfx::RenderPattern& render_pattern, const gfx::ImageLoader& image_loader, const Settings& settings); + Planet(const rhi::CommandQueue& render_cmd_queue, + const rhi::RenderPattern& render_pattern, + const gfx::ImageLoader& image_loader, + const Settings& settings); - Ptr CreateProgramBindings(const Ptr& constants_buffer_ptr, const Ptr& uniforms_buffer_ptr, Data::Index frame_index) const; + rhi::ProgramBindings CreateProgramBindings(const rhi::Buffer& constants_buffer_ptr, + const rhi::Buffer& uniforms_buffer_ptr, + Data::Index frame_index) const; bool Update(double elapsed_seconds, double delta_seconds); - void Draw(gfx::RenderCommandList& cmd_list, const gfx::MeshBufferBindings& buffer_bindings, gfx::ViewState& view_state); + void Draw(const rhi::RenderCommandList& cmd_list, + const gfx::MeshBufferBindings& buffer_bindings, + const rhi::ViewState& view_state); private: using TexturedMeshBuffers = gfx::TexturedMeshBuffers; @@ -87,14 +99,18 @@ class Planet }; }; - Planet(gfx::CommandQueue& render_cmd_queue, gfx::RenderPattern& render_pattern, const gfx::ImageLoader& image_loader, const Settings& settings, const gfx::BaseMesh& mesh); - - Settings m_settings; - gfx::RenderContext& m_context; - const Ptr m_render_cmd_queue_ptr; - TexturedMeshBuffers m_mesh_buffers; - Ptr m_texture_sampler_ptr; - Ptr m_render_state_ptr; + Planet(const rhi::CommandQueue& render_cmd_queue, + const rhi::RenderPattern& render_pattern, + const gfx::ImageLoader& image_loader, + const Settings& settings, + const gfx::BaseMesh& mesh); + + Settings m_settings; + rhi::RenderContext m_context; + rhi::CommandQueue m_render_cmd_queue; + TexturedMeshBuffers m_mesh_buffers; + rhi::Sampler m_texture_sampler; + rhi::RenderState m_render_state; }; } // namespace Methane::Graphics