diff options
author | Spartan322 <Megacake1234@gmail.com> | 2024-11-27 13:52:25 -0500 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2024-11-27 13:52:25 -0500 |
commit | 721f53fde47c2727d99e3ecccdb789a67df36de0 (patch) | |
tree | 55ec5bfa061a5c27272b831e697b78ed1b756a70 /drivers | |
parent | b06d20bf39d15ec736d08d4e4fcb32e0c3c1ce1e (diff) | |
parent | f128f383e892865379cb8b14e7bcc9858efe2973 (diff) | |
download | redot-engine-721f53fde47c2727d99e3ecccdb789a67df36de0.tar.gz |
Merge commit godotengine/godot@f128f383e892865379cb8b14e7bcc9858efe2973
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/d3d12/rendering_context_driver_d3d12.cpp | 6 | ||||
-rw-r--r-- | drivers/d3d12/rendering_context_driver_d3d12.h | 18 | ||||
-rw-r--r-- | drivers/d3d12/rendering_device_driver_d3d12.cpp | 43 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 11 |
4 files changed, 64 insertions, 14 deletions
diff --git a/drivers/d3d12/rendering_context_driver_d3d12.cpp b/drivers/d3d12/rendering_context_driver_d3d12.cpp index d8e8915941..a7bf29d44e 100644 --- a/drivers/d3d12/rendering_context_driver_d3d12.cpp +++ b/drivers/d3d12/rendering_context_driver_d3d12.cpp @@ -98,6 +98,9 @@ RenderingContextDriverD3D12::~RenderingContextDriverD3D12() { if (lib_dxgi) { FreeLibrary(lib_dxgi); } + if (lib_dcomp) { + FreeLibrary(lib_dcomp); + } } Error RenderingContextDriverD3D12::_init_device_factory() { @@ -110,6 +113,9 @@ Error RenderingContextDriverD3D12::_init_device_factory() { lib_dxgi = LoadLibraryW(L"DXGI.dll"); ERR_FAIL_NULL_V(lib_dxgi, ERR_CANT_CREATE); + lib_dcomp = LoadLibraryW(L"Dcomp.dll"); + ERR_FAIL_NULL_V(lib_dcomp, ERR_CANT_CREATE); + // Note: symbol is not available in MinGW import library. PFN_D3D12_GET_INTERFACE d3d_D3D12GetInterface = (PFN_D3D12_GET_INTERFACE)(void *)GetProcAddress(lib_d3d12, "D3D12GetInterface"); if (!d3d_D3D12GetInterface) { diff --git a/drivers/d3d12/rendering_context_driver_d3d12.h b/drivers/d3d12/rendering_context_driver_d3d12.h index 2a3b3c5b1d..e49da526ff 100644 --- a/drivers/d3d12/rendering_context_driver_d3d12.h +++ b/drivers/d3d12/rendering_context_driver_d3d12.h @@ -61,6 +61,20 @@ #undef AS #endif +#if (WINVER < _WIN32_WINNT_WIN8) && defined(_MSC_VER) +#pragma push_macro("NTDDI_VERSION") +#pragma push_macro("WINVER") +#undef NTDDI_VERSION +#undef WINVER +#define NTDDI_VERSION NTDDI_WIN8 +#define WINVER _WIN32_WINNT_WIN8 +#include <dcomp.h> +#pragma pop_macro("WINVER") +#pragma pop_macro("NTDDI_VERSION") +#else +#include <dcomp.h> +#endif + #include "d3dx12.h" #include <dxgi1_6.h> @@ -116,10 +130,14 @@ public: uint32_t height = 0; DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED; bool needs_resize = false; + ComPtr<IDCompositionDevice> composition_device; + ComPtr<IDCompositionTarget> composition_target; + ComPtr<IDCompositionVisual> composition_visual; }; HMODULE lib_d3d12 = nullptr; HMODULE lib_dxgi = nullptr; + HMODULE lib_dcomp = nullptr; IDXGIAdapter1 *create_adapter(uint32_t p_adapter_index) const; ID3D12DeviceFactory *device_factory_get() const; diff --git a/drivers/d3d12/rendering_device_driver_d3d12.cpp b/drivers/d3d12/rendering_device_driver_d3d12.cpp index 053f98b395..cc711977c5 100644 --- a/drivers/d3d12/rendering_device_driver_d3d12.cpp +++ b/drivers/d3d12/rendering_device_driver_d3d12.cpp @@ -2471,7 +2471,7 @@ Error RenderingDeviceDriverD3D12::swap_chain_resize(CommandQueueID p_cmd_queue, DXGI_SWAP_CHAIN_DESC1 swap_chain_desc = {}; if (swap_chain->d3d_swap_chain != nullptr) { _swap_chain_release_buffers(swap_chain); - res = swap_chain->d3d_swap_chain->ResizeBuffers(p_desired_framebuffer_count, 0, 0, DXGI_FORMAT_UNKNOWN, creation_flags); + res = swap_chain->d3d_swap_chain->ResizeBuffers(p_desired_framebuffer_count, surface->width, surface->height, DXGI_FORMAT_UNKNOWN, creation_flags); ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_UNAVAILABLE); } else { swap_chain_desc.BufferCount = p_desired_framebuffer_count; @@ -2480,7 +2480,7 @@ Error RenderingDeviceDriverD3D12::swap_chain_resize(CommandQueueID p_cmd_queue, swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; swap_chain_desc.SampleDesc.Count = 1; swap_chain_desc.Flags = creation_flags; - swap_chain_desc.Scaling = DXGI_SCALING_NONE; + swap_chain_desc.Scaling = DXGI_SCALING_STRETCH; if (OS::get_singleton()->is_layered_allowed()) { swap_chain_desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED; has_comp_alpha[(uint64_t)p_cmd_queue.id] = true; @@ -2488,14 +2488,11 @@ Error RenderingDeviceDriverD3D12::swap_chain_resize(CommandQueueID p_cmd_queue, swap_chain_desc.AlphaMode = DXGI_ALPHA_MODE_IGNORE; has_comp_alpha[(uint64_t)p_cmd_queue.id] = false; } + swap_chain_desc.Width = surface->width; + swap_chain_desc.Height = surface->height; ComPtr<IDXGISwapChain1> swap_chain_1; - res = context_driver->dxgi_factory_get()->CreateSwapChainForHwnd(command_queue->d3d_queue.Get(), surface->hwnd, &swap_chain_desc, nullptr, nullptr, swap_chain_1.GetAddressOf()); - if (!SUCCEEDED(res) && swap_chain_desc.AlphaMode != DXGI_ALPHA_MODE_IGNORE) { - swap_chain_desc.AlphaMode = DXGI_ALPHA_MODE_IGNORE; - has_comp_alpha[(uint64_t)p_cmd_queue.id] = false; - res = context_driver->dxgi_factory_get()->CreateSwapChainForHwnd(command_queue->d3d_queue.Get(), surface->hwnd, &swap_chain_desc, nullptr, nullptr, swap_chain_1.GetAddressOf()); - } + res = context_driver->dxgi_factory_get()->CreateSwapChainForComposition(command_queue->d3d_queue.Get(), &swap_chain_desc, nullptr, swap_chain_1.GetAddressOf()); ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); swap_chain_1.As(&swap_chain->d3d_swap_chain); @@ -2505,6 +2502,36 @@ Error RenderingDeviceDriverD3D12::swap_chain_resize(CommandQueueID p_cmd_queue, ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); } + if (surface->composition_device.Get() == nullptr) { + using PFN_DCompositionCreateDevice = HRESULT(WINAPI *)(IDXGIDevice *, REFIID, void **); + PFN_DCompositionCreateDevice pfn_DCompositionCreateDevice = (PFN_DCompositionCreateDevice)(void *)GetProcAddress(context_driver->lib_dcomp, "DCompositionCreateDevice"); + ERR_FAIL_NULL_V(pfn_DCompositionCreateDevice, ERR_CANT_CREATE); + + res = pfn_DCompositionCreateDevice(nullptr, IID_PPV_ARGS(surface->composition_device.GetAddressOf())); + ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); + + res = surface->composition_device->CreateTargetForHwnd(surface->hwnd, TRUE, surface->composition_target.GetAddressOf()); + ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); + + res = surface->composition_device->CreateVisual(surface->composition_visual.GetAddressOf()); + ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); + + res = surface->composition_visual->SetContent(swap_chain->d3d_swap_chain.Get()); + ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); + + res = surface->composition_target->SetRoot(surface->composition_visual.Get()); + ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); + + res = surface->composition_device->Commit(); + ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); + } else { + res = surface->composition_visual->SetContent(swap_chain->d3d_swap_chain.Get()); + ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); + + res = surface->composition_device->Commit(); + ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); + } + res = swap_chain->d3d_swap_chain->GetDesc1(&swap_chain_desc); ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); ERR_FAIL_COND_V(swap_chain_desc.BufferCount == 0, ERR_CANT_CREATE); diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 8b16da8d47..504924b36d 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -3316,10 +3316,6 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params, } material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::OPAQUE_PREPASS_THRESHOLD, opaque_prepass_threshold, shader->version, instance_variant, spec_constants); - - prev_shader = shader; - prev_variant = instance_variant; - prev_spec_constants = spec_constants; } // Pass in lighting uniforms. @@ -3357,7 +3353,7 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params, } // Pass light count and array of light indices for base pass. - if ((prev_inst != inst || prev_shader != shader || prev_variant != instance_variant) && pass == 0) { + if ((prev_inst != inst || prev_shader != shader || prev_variant != instance_variant || prev_spec_constants != spec_constants) && pass == 0) { // Rebind the light indices. material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::OMNI_LIGHT_COUNT, inst->omni_light_gl_cache.size(), shader->version, instance_variant, spec_constants); material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::SPOT_LIGHT_COUNT, inst->spot_light_gl_cache.size(), shader->version, instance_variant, spec_constants); @@ -3414,11 +3410,14 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params, } else if (inst->lightmap_sh) { glUniform4fv(material_storage->shaders.scene_shader.version_get_uniform(SceneShaderGLES3::LIGHTMAP_CAPTURES, shader->version, instance_variant, spec_constants), 9, reinterpret_cast<const GLfloat *>(inst->lightmap_sh->sh)); } - prev_inst = inst; } } + prev_shader = shader; + prev_variant = instance_variant; + prev_spec_constants = spec_constants; + // Pass in reflection probe data if constexpr (p_pass_mode == PASS_MODE_COLOR || p_pass_mode == PASS_MODE_COLOR_TRANSPARENT) { if (pass == 0 && inst->reflection_probe_rid_cache.size() > 0) { |