diff --git a/Yasno/Graphics/Primitive.hpp b/Yasno/Graphics/Primitive.hpp index 1abaf18..ab7a68b 100644 --- a/Yasno/Graphics/Primitive.hpp +++ b/Yasno/Graphics/Primitive.hpp @@ -25,6 +25,7 @@ namespace ysn D3D12_INDEX_BUFFER_VIEW index_buffer_view; uint32_t index_count = 0; + int material_id = -1; std::unordered_map attributes; }; diff --git a/Yasno/Graphics/RenderScene.hpp b/Yasno/Graphics/RenderScene.hpp index 854d6d6..5b2a9aa 100644 --- a/Yasno/Graphics/RenderScene.hpp +++ b/Yasno/Graphics/RenderScene.hpp @@ -22,16 +22,16 @@ namespace ysn struct ModelRenderParameters { - bool should_cast_shadow = false; - + bool should_cast_shadow = false; }; struct Model { - std::string name = "Unnamed Model"; + std::string name = "Unnamed Model"; ModelRenderParameters render_parameters; std::vector meshes; + std::vector materials; // Not sure about that std::vector buffers; @@ -41,7 +41,7 @@ namespace ysn std::vector node_buffers; // Per node GPU data std::vector sampler_descs; }; - + struct RenderScene { std::shared_ptr camera; diff --git a/Yasno/Graphics/Techniques/ShadowMapPass.hpp b/Yasno/Graphics/Techniques/ShadowMapPass.hpp index e7ed26a..cbb5f40 100644 --- a/Yasno/Graphics/Techniques/ShadowMapPass.hpp +++ b/Yasno/Graphics/Techniques/ShadowMapPass.hpp @@ -9,6 +9,7 @@ #include #include +#include namespace ysn { diff --git a/Yasno/Renderer/CommandQueue.cpp b/Yasno/Renderer/CommandQueue.cpp index bda333e..4d51d6a 100644 --- a/Yasno/Renderer/CommandQueue.cpp +++ b/Yasno/Renderer/CommandQueue.cpp @@ -74,7 +74,7 @@ namespace ysn return commandList; } - wil::com_ptr CommandQueue::GetCommandList() + wil::com_ptr CommandQueue::GetCommandList(std::string name) { wil::com_ptr commandAllocator; wil::com_ptr commandList; @@ -103,6 +103,10 @@ namespace ysn commandList = CreateCommandList(commandAllocator); } + #ifndef YSN_RELEASE + commandList->SetName(std::wstring(name.begin(), name.end()).c_str()); + #endif + // Associate the command allocator with the command list so that it can be // retrieved when the command list is executed. ThrowIfFailed(commandList->SetPrivateDataInterface(__uuidof(ID3D12CommandAllocator), commandAllocator.get())); diff --git a/Yasno/Renderer/CommandQueue.hpp b/Yasno/Renderer/CommandQueue.hpp index 033be4a..5dc64b3 100644 --- a/Yasno/Renderer/CommandQueue.hpp +++ b/Yasno/Renderer/CommandQueue.hpp @@ -14,7 +14,7 @@ namespace ysn CommandQueue(wil::com_ptr device, D3D12_COMMAND_LIST_TYPE type); virtual ~CommandQueue(); - wil::com_ptr GetCommandList(); + wil::com_ptr GetCommandList(std::string name = "Neyasno Command List"); // Execute a command list. // Returns the fence value to wait for this command list. diff --git a/Yasno/Renderer/GpuResource.hpp b/Yasno/Renderer/GpuResource.hpp index 23422b6..c67d14d 100644 --- a/Yasno/Renderer/GpuResource.hpp +++ b/Yasno/Renderer/GpuResource.hpp @@ -7,6 +7,8 @@ namespace ysn { struct GpuResource { + GpuResource() = default; + GpuResource(wil::com_ptr res) : resource(res) {} D3D12_GPU_VIRTUAL_ADDRESS GetGPUVirtualAddress() const diff --git a/Yasno/System/GltfLoader.cpp b/Yasno/System/GltfLoader.cpp index 10c37af..24fc557 100644 --- a/Yasno/System/GltfLoader.cpp +++ b/Yasno/System/GltfLoader.cpp @@ -217,11 +217,12 @@ static bool BuildImages(ysn::Model& model, LoadGltfContext& build_context, const } #ifndef YSN_RELEASE - std::wstring name(image.name.begin(), image.name.end()); + std::wstring name(image.uri.begin(), image.uri.end()); dst_texture->SetName(name.c_str()); #endif ysn::GpuTexture new_texture; + new_texture.name = std::wstring(image.uri.begin(), image.uri.end()); new_texture.gpu_resource = dst_texture; new_texture.is_srgb = is_srgb; new_texture.num_mips = num_mips; @@ -652,21 +653,18 @@ static void BuildMeshes(ysn::Model& model, const tinygltf::Model& gltf_model) { for (const tinygltf::Mesh& gltf_mesh : gltf_model.meshes) { - ysn::Mesh mesh = {}; + ysn::Mesh mesh; mesh.name = gltf_mesh.name; for (const tinygltf::Primitive& gltf_primitive : gltf_mesh.primitives) { - ysn::Primitive primitive = {}; + ysn::Primitive primitive; BuildAttributesAccessors(primitive, model, gltf_model, gltf_primitive.attributes); BuildIndexBuffer(primitive, model, gltf_primitive.indices, gltf_model); BuildPrimitiveTopology(primitive, gltf_primitive.mode); - //if (gltf_primitive.material >= 0) - //{ - // primitive.pMaterial = &pModelRenderContext->Materials[gltf_primitive.material]; // TODO: Move out - //} + primitive.material_id = gltf_primitive.material; //BuildPipelines(&primitive, renderer); @@ -751,7 +749,7 @@ static bool BuildNodes(ysn::Model& model, const tinygltf::Model& gltf_model, con } } -bool BuildMaterials(ysn::Model& model, LoadGltfContext& build_context, const tinygltf::Model& gltf_model) +static bool BuildMaterials(ysn::Model& model, LoadGltfContext& build_context, const tinygltf::Model& gltf_model) { auto dx_renderer = ysn::Application::Get().GetRenderer(); @@ -779,6 +777,8 @@ bool BuildMaterials(ysn::Model& model, LoadGltfContext& build_context, const tin } else if (gltf_material.alphaMode == "OPAQUE") { + material.blend_desc.RenderTarget[0].BlendEnable = false; + // TODO(gltf): Check other alpha modes // assert( false ); } @@ -852,26 +852,6 @@ bool BuildMaterials(ysn::Model& model, LoadGltfContext& build_context, const tin shader_parameters->metallic_factor = static_cast(gltf_pbr_material.metallicFactor); shader_parameters->roughness_factor = static_cast(gltf_pbr_material.roughnessFactor); - if (gltf_pbr_material.metallicRoughnessTexture.index >= 0) - { - shader_parameters->texture_enable_bitmask |= 1 << METALLIC_ROUGHNESS_ENABLED_BIT; - } - - if (gltf_material.normalTexture.index >= 0) - { - shader_parameters->texture_enable_bitmask |= 1 << NORMAL_ENABLED_BIT; - } - - if (gltf_material.occlusionTexture.index >= 0) - { - shader_parameters->texture_enable_bitmask |= 1 << OCCLUSION_ENABLED_BIT; - } - - if (gltf_material.emissiveTexture.index >= 0) - { - shader_parameters->texture_enable_bitmask |= 1 << EMISSIVE_ENABLED_BIT; - } - if (gltf_pbr_material.baseColorTexture.index >= 0) { shader_parameters->texture_enable_bitmask |= 1 << ALBEDO_ENABLED_BIT; @@ -879,122 +859,140 @@ bool BuildMaterials(ysn::Model& model, LoadGltfContext& build_context, const tin const tinygltf::Texture& gltf_texture = gltf_model.textures[gltf_pbr_material.baseColorTexture.index]; // TODO: Preallocate 5 handles and provide them through array, do not save first handle - RenderMaterial.srv_handle = p_renderer->GetCbvSrvUavDescriptorHeap()->GetNewHandle(); - RenderMaterial.sampler_handle = p_renderer->GetSamplerDescriptorHeap()->GetNewHandle(); + const auto srv_handle = dx_renderer->GetCbvSrvUavDescriptorHeap()->GetNewHandle(); + const auto sampler_handle = dx_renderer->GetSamplerDescriptorHeap()->GetNewHandle(); - ysn::Texture& texture = pModelRenderContext->pTextures[GltfTexture.source]; - texture.descriptor_handle = RenderMaterial.srv_handle; + ysn::GpuTexture& texture = model.textures[gltf_texture.source]; // TODO: use it for srgb? + texture.descriptor_handle = srv_handle; + texture.is_srgb = true; - pPBRMetallicRoughness->albedo_texture_index = p_renderer->GetCbvSrvUavDescriptorHeap()->GetDescriptorIndex(RenderMaterial.srv_handle); + shader_parameters->albedo_texture_index = dx_renderer->GetCbvSrvUavDescriptorHeap()->GetDescriptorIndex(srv_handle); - auto resource = texture.gpuTexture; - auto resource_desc = resource->GetDesc(); + auto resource_desc = texture.gpu_resource->GetDesc(); - resource->SetName(L"Albedo"); - texture.name = L"Albedo"; + #ifndef YSN_RELEASE + texture.gpu_resource->SetName(L"Albedo Texture"); + #endif - D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc = {}; - srv_desc.Format = resource_desc.Format; - srv_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; - srv_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; - srv_desc.Texture2D.MipLevels = resource_desc.MipLevels; + texture.name = L"Albedo Texture"; - p_renderer->GetDevice()->CreateShaderResourceView(resource.get(), &srv_desc, RenderMaterial.srv_handle.cpu); + //D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc = {}; + //srv_desc.Format = resource_desc.Format; + //srv_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + //srv_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; + //srv_desc.Texture2D.MipLevels = resource_desc.MipLevels; - D3D12_SAMPLER_DESC& SamplerDesc = pModelRenderContext->SamplerDescs[GltfTexture.sampler]; - p_renderer->GetDevice()->CreateSampler(&SamplerDesc, RenderMaterial.sampler_handle.cpu); + //p_renderer->GetDevice()->CreateShaderResourceView(texture.gpu_resource.get(), &srv_desc, RenderMaterial.srv_handle.cpu); + + //D3D12_SAMPLER_DESC& SamplerDesc = pModelRenderContext->SamplerDescs[GltfTexture.sampler]; + //p_renderer->GetDevice()->CreateSampler(&SamplerDesc, RenderMaterial.sampler_handle.cpu); } - tinygltf::TextureInfo& glTFMetallicRoughnessTexture = GltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture; - if (glTFMetallicRoughnessTexture.index > 0) + if (gltf_material.pbrMetallicRoughness.metallicRoughnessTexture.index > 0) { - tinygltf::Texture& gltfTexture = pGltfModel->textures[glTFMetallicRoughnessTexture.index]; - auto& texture = pModelRenderContext->pTextures[gltfTexture.source]; + shader_parameters->texture_enable_bitmask |= 1 << METALLIC_ROUGHNESS_ENABLED_BIT; + + const tinygltf::Texture& gltfTexture = gltf_model.textures[gltf_material.pbrMetallicRoughness.metallicRoughnessTexture.index]; + ysn::GpuTexture& texture = model.textures[gltfTexture.source]; - auto SrvDescriptor = p_renderer->GetCbvSrvUavDescriptorHeap()->GetNewHandle(); - CD3DX12_CPU_DESCRIPTOR_HANDLE SamplerDescriptor = p_renderer->GetSamplerDescriptorHeap()->GetNewHandle().cpu; + const auto srv_handle = dx_renderer->GetCbvSrvUavDescriptorHeap()->GetNewHandle(); + const auto sampler_handle = dx_renderer->GetSamplerDescriptorHeap()->GetNewHandle(); - texture.descriptor_handle = SrvDescriptor; - pPBRMetallicRoughness->metallic_roughness_texture_index = p_renderer->GetCbvSrvUavDescriptorHeap()->GetDescriptorIndex(SrvDescriptor); + texture.descriptor_handle = srv_handle; + shader_parameters->metallic_roughness_texture_index = dx_renderer->GetCbvSrvUavDescriptorHeap()->GetDescriptorIndex(srv_handle); - texture.gpuTexture->SetName(L"MetallicRoughness"); + #ifndef YSN_RELEASE + texture.gpu_resource->SetName(L"Metallic Roughness Texture"); + #endif - p_renderer->GetDevice()->CreateShaderResourceView(texture.gpuTexture.get(), nullptr, SrvDescriptor.cpu); + texture.name = L"Metallic Roughness Texture"; - auto& samplerDesc = pModelRenderContext->SamplerDescs[gltfTexture.sampler]; - p_renderer->GetDevice()->CreateSampler(&samplerDesc, SamplerDescriptor); + //p_renderer->GetDevice()->CreateShaderResourceView(texture.gpuTexture.get(), nullptr, SrvDescriptor.cpu); + + //auto& samplerDesc = pModelRenderContext->SamplerDescs[gltfTexture.sampler]; + //p_renderer->GetDevice()->CreateSampler(&samplerDesc, SamplerDescriptor); } - // Normal - // TODO: add scale - tinygltf::NormalTextureInfo& gltfNormalTexture = GltfMaterial.normalTexture; - if (gltfNormalTexture.index > 0) + if (gltf_material.normalTexture.index > 0) { - const tinygltf::Texture& GltfTexture = pGltfModel->textures[gltfNormalTexture.index]; - ID3D12Resource* pTexture = pModelRenderContext->pTextures[GltfTexture.source].gpuTexture.get(); + shader_parameters->texture_enable_bitmask |= 1 << NORMAL_ENABLED_BIT; - auto descriptor = p_renderer->GetCbvSrvUavDescriptorHeap()->GetNewHandle(); + const tinygltf::Texture& gltf_texture = gltf_model.textures[gltf_material.normalTexture.index]; + ysn::GpuTexture& texture = model.textures[gltf_texture.source]; - CD3DX12_CPU_DESCRIPTOR_HANDLE SrvDescriptor = descriptor.cpu; - CD3DX12_CPU_DESCRIPTOR_HANDLE SamplerDescriptor = p_renderer->GetSamplerDescriptorHeap()->GetNewHandle().cpu; + const auto srv_handle = dx_renderer->GetCbvSrvUavDescriptorHeap()->GetNewHandle(); + const auto sampler_handle = dx_renderer->GetSamplerDescriptorHeap()->GetNewHandle(); - pPBRMetallicRoughness->normal_texture_index = p_renderer->GetCbvSrvUavDescriptorHeap()->GetDescriptorIndex(descriptor); + shader_parameters->normal_texture_index = dx_renderer->GetCbvSrvUavDescriptorHeap()->GetDescriptorIndex(srv_handle); + + #ifndef YSN_RELEASE + texture.gpu_resource->SetName(L"Normals Texture"); + #endif - pTexture->SetName(L"Normal"); + texture.name = L"Normals Texture"; - p_renderer->GetDevice()->CreateShaderResourceView(pTexture, nullptr, SrvDescriptor); + //p_renderer->GetDevice()->CreateShaderResourceView(pTexture, nullptr, SrvDescriptor); - D3D12_SAMPLER_DESC& SamplerDesc = pModelRenderContext->SamplerDescs[GltfTexture.sampler]; - p_renderer->GetDevice()->CreateSampler(&SamplerDesc, SamplerDescriptor); + //D3D12_SAMPLER_DESC& SamplerDesc = pModelRenderContext->SamplerDescs[GltfTexture.sampler]; + //p_renderer->GetDevice()->CreateSampler(&SamplerDesc, SamplerDescriptor); } - // Occlusion - tinygltf::OcclusionTextureInfo& gltfOcclusionTexture = GltfMaterial.occlusionTexture; - if (gltfOcclusionTexture.index > 0) + if (gltf_material.occlusionTexture.index > 0) { - tinygltf::Texture& gltfTexture = pGltfModel->textures[gltfOcclusionTexture.index]; - ID3D12Resource* pTexture = pModelRenderContext->pTextures[gltfTexture.source].gpuTexture.get(); + shader_parameters->texture_enable_bitmask |= 1 << OCCLUSION_ENABLED_BIT; + + const tinygltf::Texture& gltf_texture = gltf_model.textures[gltf_material.occlusionTexture.index]; + ysn::GpuTexture& texture = model.textures[gltf_texture.source]; - auto descriptor = p_renderer->GetCbvSrvUavDescriptorHeap()->GetNewHandle(); + const auto srv_handle = dx_renderer->GetCbvSrvUavDescriptorHeap()->GetNewHandle(); + const auto sampler_handle = dx_renderer->GetSamplerDescriptorHeap()->GetNewHandle(); - CD3DX12_CPU_DESCRIPTOR_HANDLE SrvDescriptor = descriptor.cpu; - CD3DX12_CPU_DESCRIPTOR_HANDLE SamplerDescriptor = p_renderer->GetSamplerDescriptorHeap()->GetNewHandle().cpu; + shader_parameters->occlusion_texture_index = dx_renderer->GetCbvSrvUavDescriptorHeap()->GetDescriptorIndex(srv_handle); + + #ifndef YSN_RELEASE + texture.gpu_resource->SetName(L"Occlusion Texture"); + #endif - pPBRMetallicRoughness->occlusion_texture_index = p_renderer->GetCbvSrvUavDescriptorHeap()->GetDescriptorIndex(descriptor); + texture.name = L"Occlusion Texture"; - p_renderer->GetDevice()->CreateShaderResourceView(pTexture, nullptr, SrvDescriptor); + //p_renderer->GetDevice()->CreateShaderResourceView(pTexture, nullptr, SrvDescriptor); - D3D12_SAMPLER_DESC& samplerDesc = pModelRenderContext->SamplerDescs[gltfTexture.sampler]; - p_renderer->GetDevice()->CreateSampler(&samplerDesc, SamplerDescriptor); + //D3D12_SAMPLER_DESC& samplerDesc = pModelRenderContext->SamplerDescs[gltfTexture.sampler]; + //p_renderer->GetDevice()->CreateSampler(&samplerDesc, SamplerDescriptor); } - // Emissive - tinygltf::TextureInfo& gltfEmissiveTexture = GltfMaterial.emissiveTexture; - if (gltfEmissiveTexture.index > 0) + if (gltf_material.emissiveTexture.index > 0) { - tinygltf::Texture& gltfTexture = pGltfModel->textures[gltfEmissiveTexture.index]; - ID3D12Resource* pTexture = pModelRenderContext->pTextures[gltfTexture.source].gpuTexture.get(); + shader_parameters->texture_enable_bitmask |= 1 << EMISSIVE_ENABLED_BIT; - auto descriptor = p_renderer->GetCbvSrvUavDescriptorHeap()->GetNewHandle(); + const tinygltf::Texture& gltf_texture = gltf_model.textures[gltf_material.emissiveTexture.index]; + ysn::GpuTexture& texture = model.textures[gltf_texture.source]; + texture.is_srgb = true; - CD3DX12_CPU_DESCRIPTOR_HANDLE SrvDescriptor = descriptor.cpu; - CD3DX12_CPU_DESCRIPTOR_HANDLE SamplerDescriptor = p_renderer->GetSamplerDescriptorHeap()->GetNewHandle().cpu; + const auto srv_handle = dx_renderer->GetCbvSrvUavDescriptorHeap()->GetNewHandle(); + const auto sampler_handle = dx_renderer->GetSamplerDescriptorHeap()->GetNewHandle(); - pPBRMetallicRoughness->emissive_texture_index = p_renderer->GetCbvSrvUavDescriptorHeap()->GetDescriptorIndex(descriptor); + shader_parameters->emissive_texture_index = dx_renderer->GetCbvSrvUavDescriptorHeap()->GetDescriptorIndex(srv_handle); - p_renderer->GetDevice()->CreateShaderResourceView(pTexture, nullptr, SrvDescriptor); + #ifndef YSN_RELEASE + texture.gpu_resource->SetName(L"Emissive Texture"); + #endif - D3D12_SAMPLER_DESC& samplerDesc = pModelRenderContext->SamplerDescs[gltfTexture.sampler]; - p_renderer->GetDevice()->CreateSampler(&samplerDesc, SamplerDescriptor); + texture.name = L"Emissive Texture"; + + //p_renderer->GetDevice()->CreateShaderResourceView(pTexture, nullptr, SrvDescriptor); + + //D3D12_SAMPLER_DESC& samplerDesc = pModelRenderContext->SamplerDescs[gltfTexture.sampler]; + //p_renderer->GetDevice()->CreateSampler(&samplerDesc, SamplerDescriptor); } - pModelRenderContext->Materials.push_back(RenderMaterial); + model.materials.push_back(material); } } namespace ysn { - void ReadModel(Model& model, const tinygltf::Model& gltf_model, const LoadingParameters& loading_parameters) + bool ReadModel(Model& model, const tinygltf::Model& gltf_model, const LoadingParameters& loading_parameters) { auto dx_renderer = Application::Get().GetRenderer(); auto command_queue = Application::Get().GetDirectQueue(); @@ -1010,13 +1008,29 @@ namespace ysn load_gltf_context.staging_resources.reserve(256); load_gltf_context.copy_cmd_list = command_queue->GetCommandList(); - BuildBuffers(model, load_gltf_context, gltf_model); + if(!BuildBuffers(model, load_gltf_context, gltf_model)) + { + LogError << "GLTF loader can't build buffers\n"; + return false; + } + if(!BuildImages(model, load_gltf_context, gltf_model)) + { + LogError << "GLTF loader can't build materials\n"; + return false; + } //FindAllSrgbTextures(ModelRenderContext, pModel); - BuildMaterials(model, load_gltf_context, gltf_model); - BuildImages(model, load_gltf_context, gltf_model); + if(!BuildMaterials(model, load_gltf_context, gltf_model)) + { + LogError << "GLTF loader can't build materials\n"; + return false; + } BuildSamplerDescs(model, gltf_model); BuildMeshes(model, gltf_model); - BuildNodes(model, gltf_model, loading_parameters); + if(!BuildNodes(model, gltf_model, loading_parameters)) + { + LogError << "GLTF loader can't build nodes\n"; + return false; + } // Build pipelines // Compute mips @@ -1024,6 +1038,8 @@ namespace ysn auto fence_value = command_queue->ExecuteCommandList(command_list); command_queue->WaitForFenceValue(fence_value); + + return true; } bool LoadGltfFromFile(RenderScene& render_scene, const std::wstring& load_path, const LoadingParameters& loading_parameters) @@ -1037,6 +1053,8 @@ namespace ysn const bool result = gltf_loader.LoadASCIIFromFile(&gltf_model, &error_str, &warning_str, load_path_str.c_str()); + LogInfo << "GLTF loading: " << load_path_str << "\n"; + if (!warning_str.empty()) { LogWarning << "GLTF loading: " << warning_str.c_str() << "\n"; @@ -1055,10 +1073,16 @@ namespace ysn Model model; - ReadModel(model, gltf_model, loading_parameters); + if(!ReadModel(model, gltf_model, loading_parameters)) + { + LogInfo << "GLTF can't load model\n"; + return false; + } render_scene.models.push_back(model); + LogInfo << "GLTF loaded successfully: " << load_path_str << "\n"; + return true; } } diff --git a/Yasno/System/GltfLoader.hpp b/Yasno/System/GltfLoader.hpp index f201f00..f165429 100644 --- a/Yasno/System/GltfLoader.hpp +++ b/Yasno/System/GltfLoader.hpp @@ -16,65 +16,6 @@ namespace ysn { - //struct GltfMaterial - //{ - // std::string name; - - // D3D12_BLEND_DESC blendDesc; - // D3D12_RASTERIZER_DESC rasterizerDesc; - // void* pBufferData; - - // DescriptorHandle srv_handle; - // DescriptorHandle sampler_handle; - - // wil::com_ptr pBuffer; - //}; - - //struct GltfPrimitive - //{ - // std::vector RenderAttributes; - - // D3D12_PRIMITIVE_TOPOLOGY primitiveTopology; - - // uint32_t vertexCount; - - // D3D12_INDEX_BUFFER_VIEW indexBufferView; - // uint32_t indexCount; - - // Material* pMaterial; - - // wil::com_ptr pRootSignature; - // wil::com_ptr pPipelineState; - - // wil::com_ptr pShadowRootSignature; - // wil::com_ptr pShadowPipelineState; - - // // TODO: This is lazy way to keep eye on this info for RTX BLAS generation, clean that up later - // wil::com_ptr vertex_buffer; - // uint64_t vertex_offset_in_bytes; - // uint32_t vertex_count; - // uint32_t vertex_stride; - - // wil::com_ptr index_buffer; - // uint64_t index_offset_in_bytes; - // uint32_t index_count; - // // ... - //}; - - //struct ModelRenderContext - //{ - // std::vector> pBuffers; - // std::vector pTextures; - // std::unordered_set srgb_textures; - // std::vector SamplerDescs; - // std::vector Materials; - // std::vector Meshes; - // std::vector> pNodeBuffers; - // std::vector> stagingResources; // TODO: make it temp? - - // tinygltf::Model gltfModel; - //}; - struct LoadingParameters { DirectX::XMMATRIX model_modifier = DirectX::XMMatrixIdentity(); // Applies matrix modifier for nodes and RTX BVH generation diff --git a/Yasno/Yasno/Yasno.cpp b/Yasno/Yasno/Yasno.cpp index e14e07f..532bcd1 100644 --- a/Yasno/Yasno/Yasno.cpp +++ b/Yasno/Yasno/Yasno.cpp @@ -256,7 +256,7 @@ namespace ysn // TODO(last): Another command list? bool load_result = false; //LoadGLTFModel(&m_gltf_draw_context, GetVirtualFilesystemPath(L"Assets/DamagedHelmet/DamagedHelmet.gltf"), Application::Get().GetRenderer(), command_list); - load_result = LoadGltfFromFile(m_render_scene, GetVirtualFilesystemPath(L"Assets/Sponza/Sponza.gltf"), loading_parameters); + //load_result = LoadGltfFromFile(m_render_scene, GetVirtualFilesystemPath(L"Assets/Sponza/Sponza.gltf"), loading_parameters); load_result = LoadGltfFromFile(m_render_scene, GetVirtualFilesystemPath(L"Assets/DamagedHelmet/DamagedHelmet.gltf"), loading_parameters); //LoadGLTFModel(&m_gltf_draw_context, GetVirtualFilesystemPath(L"Assets/BoomBoxWithAxes/glTF/BoomBoxWithAxes.gltf"), Application::Get().GetRenderer(), command_list); //LoadGLTFModel(&m_gltf_draw_context, GetVirtualFilesystemPath(L"Assets/Bistro/Bistro.gltf"), Application::Get().GetRenderer(), command_list); @@ -319,11 +319,11 @@ namespace ysn // Setup techniques m_shadow_pass.Initialize(Application::Get().GetRenderer()); - if (!m_ray_tracing_pass.Initialize(Application::Get().GetRenderer(), m_scene_color_buffer, m_raytracing_context, m_camera_gpu_buffer)) - { - LogFatal << "Can't initialize raytracing pass\n"; - return false; - } + //if (!m_ray_tracing_pass.Initialize(Application::Get().GetRenderer(), m_scene_color_buffer, m_raytracing_context, m_camera_gpu_buffer)) + //{ + // LogFatal << "Can't initialize raytracing pass\n"; + // return false; + //} // Setup camera m_render_scene.camera = std::make_shared(); @@ -703,6 +703,25 @@ namespace ysn if (m_is_raster) { + wil::com_ptr command_list = command_queue->GetCommandList(); + + PIXBeginEvent(command_list.get(), PIX_COLOR_DEFAULT, "GeometryPass"); + + // Clear the render targets. + { + FLOAT clear_color[] = { 44.0f / 255.0f, 58.f / 255.0f, 74.0f / 255.0f, 1.0f }; + + CD3DX12_RESOURCE_BARRIER barrier = CD3DX12_RESOURCE_BARRIER::Transition(current_back_buffer.get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET); + command_list->ResourceBarrier(1, &barrier); + + command_list->ClearRenderTargetView(backbuffer_handle, clear_color, 0, nullptr); + command_list->ClearDepthStencilView(m_depth_dsv_descriptor_handle.cpu, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr); + command_list->ClearRenderTargetView(m_hdr_rtv_descriptor_handle.cpu, clear_color, 0, nullptr); + } + + command_queue->ExecuteCommandList(command_list); + + // TODO(return) //m_forward_pass.Render(Application::Get().GetRenderer(), command_queue, m_scene_parameters_gpu_buffer, &m_render_scene); } @@ -732,21 +751,21 @@ namespace ysn command_queue->ExecuteCommandList(command_list); } - if (m_is_raster) - { - SkyboxPassParameters skybox_parameters; - skybox_parameters.command_queue = command_queue; - skybox_parameters.cbv_srv_uav_heap = renderer->GetCbvSrvUavDescriptorHeap(); - skybox_parameters.scene_color_buffer = m_scene_color_buffer; - skybox_parameters.hdr_rtv_descriptor_handle = m_hdr_rtv_descriptor_handle; - skybox_parameters.dsv_descriptor_handle = m_depth_dsv_descriptor_handle; - skybox_parameters.viewport = m_viewport; - skybox_parameters.scissors_rect = m_scissors_rect; - skybox_parameters.equirectangular_texture = &m_environment_texture; - skybox_parameters.camera_gpu_buffer = m_camera_gpu_buffer; - - m_skybox_pass.RenderSkybox(&skybox_parameters); - } + //if (m_is_raster) + //{ + // SkyboxPassParameters skybox_parameters; + // skybox_parameters.command_queue = command_queue; + // skybox_parameters.cbv_srv_uav_heap = renderer->GetCbvSrvUavDescriptorHeap(); + // skybox_parameters.scene_color_buffer = m_scene_color_buffer; + // skybox_parameters.hdr_rtv_descriptor_handle = m_hdr_rtv_descriptor_handle; + // skybox_parameters.dsv_descriptor_handle = m_depth_dsv_descriptor_handle; + // skybox_parameters.viewport = m_viewport; + // skybox_parameters.scissors_rect = m_scissors_rect; + // skybox_parameters.equirectangular_texture = &m_environment_texture; + // skybox_parameters.camera_gpu_buffer = m_camera_gpu_buffer; + // + // m_skybox_pass.RenderSkybox(&skybox_parameters); + //} { TonemapPostprocessParameters tonemap_parameters;