diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/SCsub | 8 | ||||
-rw-r--r-- | drivers/d3d12/SCsub | 6 | ||||
-rw-r--r-- | drivers/d3d12/dxil_hash.cpp | 2 | ||||
-rw-r--r-- | drivers/d3d12/rendering_device_driver_d3d12.cpp | 338 | ||||
-rw-r--r-- | drivers/d3d12/rendering_device_driver_d3d12.h | 76 | ||||
-rw-r--r-- | drivers/egl/egl_manager.cpp | 65 | ||||
-rw-r--r-- | drivers/egl/egl_manager.h | 7 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_canvas_gles3.h | 2 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_gles3.cpp | 21 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_gles3.h | 11 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 1 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.h | 5 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 2 | ||||
-rw-r--r-- | drivers/gles3/storage/material_storage.cpp | 1 | ||||
-rw-r--r-- | drivers/gles3/storage/texture_storage.cpp | 5 | ||||
-rw-r--r-- | drivers/gles3/storage/texture_storage.h | 2 | ||||
-rw-r--r-- | drivers/metal/rendering_device_driver_metal.mm | 9 | ||||
-rw-r--r-- | drivers/unix/dir_access_unix.cpp | 12 | ||||
-rw-r--r-- | drivers/vulkan/rendering_device_driver_vulkan.cpp | 4 | ||||
-rw-r--r-- | drivers/vulkan/rendering_device_driver_vulkan.h | 2 |
20 files changed, 309 insertions, 270 deletions
diff --git a/drivers/SCsub b/drivers/SCsub index 219c4451ee..e0bfa138f5 100644 --- a/drivers/SCsub +++ b/drivers/SCsub @@ -1,6 +1,8 @@ #!/usr/bin/env python from misc.utility.scons_hints import * +from methods import print_error + Import("env") env.drivers_sources = [] @@ -20,7 +22,7 @@ if env["platform"] == "windows": SConscript("backtrace/SCsub") if env["xaudio2"]: if "xaudio2" not in supported: - print("Target platform '{}' does not support the XAudio2 audio driver. Aborting.".format(env["platform"])) + print_error("Target platform '{}' does not support the XAudio2 audio driver".format(env["platform"])) Exit(255) SConscript("xaudio2/SCsub") @@ -34,7 +36,7 @@ if env["vulkan"]: SConscript("vulkan/SCsub") if env["d3d12"]: if "d3d12" not in supported: - print("Target platform '{}' does not support the D3D12 rendering driver. Aborting.".format(env["platform"])) + print_error("Target platform '{}' does not support the D3D12 rendering driver".format(env["platform"])) Exit(255) SConscript("d3d12/SCsub") if env["opengl3"]: @@ -43,7 +45,7 @@ if env["opengl3"]: SConscript("egl/SCsub") if env["metal"]: if "metal" not in supported: - print("Target platform '{}' does not support the Metal rendering driver. Aborting.".format(env["platform"])) + print_error("Target platform '{}' does not support the Metal rendering driver".format(env["platform"])) Exit(255) SConscript("metal/SCsub") diff --git a/drivers/d3d12/SCsub b/drivers/d3d12/SCsub index b6ceed23ac..beeb13398e 100644 --- a/drivers/d3d12/SCsub +++ b/drivers/d3d12/SCsub @@ -4,6 +4,8 @@ from misc.utility.scons_hints import * import os from pathlib import Path +import methods + Import("env") env_d3d12_rdd = env.Clone() @@ -139,6 +141,10 @@ else: extra_defines += [ "HAVE_STRUCT_TIMESPEC", ] + if methods.using_gcc(env) and methods.get_compiler_version(env)["major"] < 13: + # `region` & `endregion` not recognized as valid pragmas. + env_d3d12_rdd.Append(CCFLAGS=["-Wno-unknown-pragmas"]) + env.Append(CCFLAGS=["-Wno-unknown-pragmas"]) # This is needed since rendering_device_d3d12.cpp needs to include some Mesa internals. env_d3d12_rdd.Prepend(CPPPATH=mesa_private_inc_paths) diff --git a/drivers/d3d12/dxil_hash.cpp b/drivers/d3d12/dxil_hash.cpp index f94a4a30df..e08492c9ea 100644 --- a/drivers/d3d12/dxil_hash.cpp +++ b/drivers/d3d12/dxil_hash.cpp @@ -96,7 +96,7 @@ void compute_dxil_hash(const BYTE *pData, UINT byteCount, BYTE *pOutHash) { UINT NextEndState = bTwoRowsPadding ? N - 2 : N - 1; const BYTE *pCurrData = pData; for (UINT i = 0; i < N; i++, offset += 64, pCurrData += 64) { - UINT x[16]; + UINT x[16] = {}; const UINT *pX; if (i == NextEndState) { if (!bTwoRowsPadding && i == N - 1) { diff --git a/drivers/d3d12/rendering_device_driver_d3d12.cpp b/drivers/d3d12/rendering_device_driver_d3d12.cpp index 52883de45e..0ef88e7d52 100644 --- a/drivers/d3d12/rendering_device_driver_d3d12.cpp +++ b/drivers/d3d12/rendering_device_driver_d3d12.cpp @@ -481,44 +481,6 @@ void RenderingDeviceDriverD3D12::_debug_message_func(D3D12_MESSAGE_CATEGORY p_ca } } -/****************/ -/**** MEMORY ****/ -/****************/ - -static const uint32_t SMALL_ALLOCATION_MAX_SIZE = 4096; - -#ifdef USE_SMALL_ALLOCS_POOL -D3D12MA::Pool *RenderingDeviceDriverD3D12::_find_or_create_small_allocs_pool(D3D12_HEAP_TYPE p_heap_type, D3D12_HEAP_FLAGS p_heap_flags) { - D3D12_HEAP_FLAGS effective_heap_flags = p_heap_flags; - if (allocator->GetD3D12Options().ResourceHeapTier != D3D12_RESOURCE_HEAP_TIER_1) { - // Heap tier 2 allows mixing resource types liberally. - effective_heap_flags &= ~(D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS | D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES | D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES); - } - - AllocPoolKey pool_key; - pool_key.heap_type = p_heap_type; - pool_key.heap_flags = effective_heap_flags; - if (small_allocs_pools.has(pool_key.key)) { - return small_allocs_pools[pool_key.key].Get(); - } - -#ifdef DEV_ENABLED - print_verbose("Creating D3D12MA small objects pool for heap type " + itos(p_heap_type) + " and heap flags " + itos(p_heap_flags)); -#endif - - D3D12MA::POOL_DESC poolDesc = {}; - poolDesc.HeapProperties.Type = p_heap_type; - poolDesc.HeapFlags = effective_heap_flags; - - ComPtr<D3D12MA::Pool> pool; - HRESULT res = allocator->CreatePool(&poolDesc, pool.GetAddressOf()); - small_allocs_pools[pool_key.key] = pool; // Don't try to create it again if failed the first time. - ERR_FAIL_COND_V_MSG(!SUCCEEDED(res), nullptr, "CreatePool failed with error " + vformat("0x%08ux", (uint64_t)res) + "."); - - return pool.Get(); -} -#endif - /******************/ /**** RESOURCE ****/ /******************/ @@ -533,13 +495,9 @@ static const D3D12_RESOURCE_DIMENSION RD_TEXTURE_TYPE_TO_D3D12_RESOURCE_DIMENSIO D3D12_RESOURCE_DIMENSION_TEXTURE2D, }; -void RenderingDeviceDriverD3D12::_resource_transition_batch(ResourceInfo *p_resource, uint32_t p_subresource, uint32_t p_num_planes, D3D12_RESOURCE_STATES p_new_state) { +void RenderingDeviceDriverD3D12::_resource_transition_batch(CommandBufferInfo *p_command_buffer, ResourceInfo *p_resource, uint32_t p_subresource, uint32_t p_num_planes, D3D12_RESOURCE_STATES p_new_state) { DEV_ASSERT(p_subresource != UINT32_MAX); // We don't support an "all-resources" command here. -#ifdef DEBUG_COUNT_BARRIERS - uint64_t start = OS::get_singleton()->get_ticks_usec(); -#endif - ResourceInfo::States *res_states = p_resource->states_ptr; D3D12_RESOURCE_STATES *curr_state = &res_states->subresource_states[p_subresource]; @@ -549,21 +507,21 @@ void RenderingDeviceDriverD3D12::_resource_transition_batch(ResourceInfo *p_reso bool redundant_transition = any_state_is_common ? *curr_state == p_new_state : ((*curr_state) & p_new_state) == p_new_state; if (redundant_transition) { bool just_written = *curr_state == D3D12_RESOURCE_STATE_UNORDERED_ACCESS; - bool needs_uav_barrier = just_written && res_states->last_batch_with_uav_barrier != res_barriers_batch; + bool needs_uav_barrier = just_written && res_states->last_batch_with_uav_barrier != p_command_buffer->res_barriers_batch; if (needs_uav_barrier) { - if (res_barriers.size() < res_barriers_count + 1) { - res_barriers.resize(res_barriers_count + 1); + if (p_command_buffer->res_barriers.size() < p_command_buffer->res_barriers_count + 1) { + p_command_buffer->res_barriers.resize(p_command_buffer->res_barriers_count + 1); } - res_barriers[res_barriers_count] = CD3DX12_RESOURCE_BARRIER::UAV(p_resource->resource); - res_barriers_count++; - res_states->last_batch_with_uav_barrier = res_barriers_batch; + p_command_buffer->res_barriers[p_command_buffer->res_barriers_count] = CD3DX12_RESOURCE_BARRIER::UAV(p_resource->resource); + p_command_buffer->res_barriers_count++; + res_states->last_batch_with_uav_barrier = p_command_buffer->res_barriers_batch; } } else { uint64_t subres_mask_piece = ((uint64_t)1 << (p_subresource & 0b111111)); uint8_t subres_qword = p_subresource >> 6; - if (res_barriers_requests.has(res_states)) { - BarrierRequest &br = res_barriers_requests.get(res_states); + if (p_command_buffer->res_barriers_requests.has(res_states)) { + BarrierRequest &br = p_command_buffer->res_barriers_requests.get(res_states); DEV_ASSERT(br.dx_resource == p_resource->resource); DEV_ASSERT(br.subres_mask_qwords == STEPIFY(res_states->subresource_states.size(), 64) / 64); DEV_ASSERT(br.planes == p_num_planes); @@ -681,7 +639,7 @@ void RenderingDeviceDriverD3D12::_resource_transition_batch(ResourceInfo *p_reso } } } else { - BarrierRequest &br = res_barriers_requests[res_states]; + BarrierRequest &br = p_command_buffer->res_barriers_requests[res_states]; br.dx_resource = p_resource->resource; br.subres_mask_qwords = STEPIFY(p_resource->states_ptr->subresource_states.size(), 64) / 64; CRASH_COND(p_resource->states_ptr->subresource_states.size() > BarrierRequest::MAX_SUBRESOURCES); @@ -697,18 +655,10 @@ void RenderingDeviceDriverD3D12::_resource_transition_batch(ResourceInfo *p_reso br.groups_count = 1; } } - -#ifdef DEBUG_COUNT_BARRIERS - frame_barriers_cpu_time += OS::get_singleton()->get_ticks_usec() - start; -#endif } -void RenderingDeviceDriverD3D12::_resource_transitions_flush(ID3D12GraphicsCommandList *p_cmd_list) { -#ifdef DEBUG_COUNT_BARRIERS - uint64_t start = OS::get_singleton()->get_ticks_usec(); -#endif - - for (const KeyValue<ResourceInfo::States *, BarrierRequest> &E : res_barriers_requests) { +void RenderingDeviceDriverD3D12::_resource_transitions_flush(CommandBufferInfo *p_command_buffer) { + for (const KeyValue<ResourceInfo::States *, BarrierRequest> &E : p_command_buffer->res_barriers_requests) { ResourceInfo::States *res_states = E.key; const BarrierRequest &br = E.value; @@ -760,22 +710,22 @@ void RenderingDeviceDriverD3D12::_resource_transitions_flush(ID3D12GraphicsComma // Hurray!, we can do a single barrier (plus maybe a UAV one, too). bool just_written = res_states->subresource_states[0] == D3D12_RESOURCE_STATE_UNORDERED_ACCESS; - bool needs_uav_barrier = just_written && res_states->last_batch_with_uav_barrier != res_barriers_batch; + bool needs_uav_barrier = just_written && res_states->last_batch_with_uav_barrier != p_command_buffer->res_barriers_batch; uint32_t needed_barriers = (needs_uav_barrier ? 1 : 0) + 1; - if (res_barriers.size() < res_barriers_count + needed_barriers) { - res_barriers.resize(res_barriers_count + needed_barriers); + if (p_command_buffer->res_barriers.size() < p_command_buffer->res_barriers_count + needed_barriers) { + p_command_buffer->res_barriers.resize(p_command_buffer->res_barriers_count + needed_barriers); } if (needs_uav_barrier) { - res_barriers[res_barriers_count] = CD3DX12_RESOURCE_BARRIER::UAV(br.dx_resource); - res_barriers_count++; - res_states->last_batch_with_uav_barrier = res_barriers_batch; + p_command_buffer->res_barriers[p_command_buffer->res_barriers_count] = CD3DX12_RESOURCE_BARRIER::UAV(br.dx_resource); + p_command_buffer->res_barriers_count++; + res_states->last_batch_with_uav_barrier = p_command_buffer->res_barriers_batch; } if (res_states->subresource_states[0] != br.groups[0].states) { - res_barriers[res_barriers_count] = CD3DX12_RESOURCE_BARRIER::Transition(br.dx_resource, res_states->subresource_states[0], br.groups[0].states, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES); - res_barriers_count++; + p_command_buffer->res_barriers[p_command_buffer->res_barriers_count] = CD3DX12_RESOURCE_BARRIER::Transition(br.dx_resource, res_states->subresource_states[0], br.groups[0].states, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES); + p_command_buffer->res_barriers_count++; } for (uint32_t i = 0; i < num_subresources; i++) { @@ -811,23 +761,23 @@ void RenderingDeviceDriverD3D12::_resource_transitions_flush(ID3D12GraphicsComma D3D12_RESOURCE_STATES *curr_state = &res_states->subresource_states[subresource]; bool just_written = *curr_state == D3D12_RESOURCE_STATE_UNORDERED_ACCESS; - bool needs_uav_barrier = just_written && res_states->last_batch_with_uav_barrier != res_barriers_batch; + bool needs_uav_barrier = just_written && res_states->last_batch_with_uav_barrier != p_command_buffer->res_barriers_batch; uint32_t needed_barriers = (needs_uav_barrier ? 1 : 0) + br.planes; - if (res_barriers.size() < res_barriers_count + needed_barriers) { - res_barriers.resize(res_barriers_count + needed_barriers); + if (p_command_buffer->res_barriers.size() < p_command_buffer->res_barriers_count + needed_barriers) { + p_command_buffer->res_barriers.resize(p_command_buffer->res_barriers_count + needed_barriers); } if (needs_uav_barrier) { - res_barriers[res_barriers_count] = CD3DX12_RESOURCE_BARRIER::UAV(br.dx_resource); - res_barriers_count++; - res_states->last_batch_with_uav_barrier = res_barriers_batch; + p_command_buffer->res_barriers[p_command_buffer->res_barriers_count] = CD3DX12_RESOURCE_BARRIER::UAV(br.dx_resource); + p_command_buffer->res_barriers_count++; + res_states->last_batch_with_uav_barrier = p_command_buffer->res_barriers_batch; } if (*curr_state != g.states) { for (uint8_t k = 0; k < br.planes; k++) { - res_barriers[res_barriers_count] = CD3DX12_RESOURCE_BARRIER::Transition(br.dx_resource, *curr_state, g.states, subresource + k * num_subresources); - res_barriers_count++; + p_command_buffer->res_barriers[p_command_buffer->res_barriers_count] = CD3DX12_RESOURCE_BARRIER::Transition(br.dx_resource, *curr_state, g.states, subresource + k * num_subresources); + p_command_buffer->res_barriers_count++; } } @@ -839,19 +789,13 @@ void RenderingDeviceDriverD3D12::_resource_transitions_flush(ID3D12GraphicsComma } } - if (res_barriers_count) { - p_cmd_list->ResourceBarrier(res_barriers_count, res_barriers.ptr()); - res_barriers_requests.clear(); + if (p_command_buffer->res_barriers_count) { + p_command_buffer->cmd_list->ResourceBarrier(p_command_buffer->res_barriers_count, p_command_buffer->res_barriers.ptr()); + p_command_buffer->res_barriers_requests.clear(); } -#ifdef DEBUG_COUNT_BARRIERS - frame_barriers_count += res_barriers_count; - frame_barriers_batches_count++; - frame_barriers_cpu_time += OS::get_singleton()->get_ticks_usec() - start; -#endif - - res_barriers_count = 0; - res_barriers_batch++; + p_command_buffer->res_barriers_count = 0; + p_command_buffer->res_barriers_batch++; } /*****************/ @@ -889,11 +833,7 @@ RDD::BufferID RenderingDeviceDriverD3D12::buffer_create(uint64_t p_size, BitFiel } } break; case MEMORY_ALLOCATION_TYPE_GPU: { -#ifdef USE_SMALL_ALLOCS_POOL - if (p_size <= SMALL_ALLOCATION_MAX_SIZE) { - allocation_desc.CustomPool = _find_or_create_small_allocs_pool(allocation_desc.HeapType, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS); - } -#endif + // Use default parameters. } break; } @@ -1002,6 +942,7 @@ static const D3D12_UAV_DIMENSION RD_TEXTURE_TYPE_TO_D3D12_VIEW_DIMENSION_FOR_UAV uint32_t RenderingDeviceDriverD3D12::_find_max_common_supported_sample_count(VectorView<DXGI_FORMAT> p_formats) { uint32_t common = UINT32_MAX; + MutexLock lock(format_sample_counts_mask_cache_mutex); for (uint32_t i = 0; i < p_formats.size(); i++) { if (format_sample_counts_mask_cache.has(p_formats[i])) { common &= format_sample_counts_mask_cache[p_formats[i]]; @@ -1292,14 +1233,6 @@ RDD::TextureID RenderingDeviceDriverD3D12::texture_create(const TextureFormat &p allocation_desc.ExtraHeapFlags |= D3D12_HEAP_FLAG_ALLOW_SHADER_ATOMICS; } -#ifdef USE_SMALL_ALLOCS_POOL - uint32_t width = 0, height = 0; - uint32_t image_size = get_image_format_required_size(p_format.format, p_format.width, p_format.height, p_format.depth, p_format.mipmaps, &width, &height); - if (image_size <= SMALL_ALLOCATION_MAX_SIZE) { - allocation_desc.CustomPool = _find_or_create_small_allocs_pool(allocation_desc.HeapType, allocation_desc.ExtraHeapFlags); - } -#endif - D3D12_RESOURCE_STATES initial_state = {}; ID3D12Resource *texture = nullptr; ComPtr<ID3D12Resource> main_texture; @@ -1415,7 +1348,14 @@ RDD::TextureID RenderingDeviceDriverD3D12::texture_create(const TextureFormat &p } tex_info->states_ptr = &tex_info->owner_info.states; tex_info->format = p_format.format; +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif tex_info->desc = *(CD3DX12_RESOURCE_DESC *)&resource_desc; +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif tex_info->base_layer = 0; tex_info->layers = resource_desc.ArraySize(); tex_info->base_mip = 0; @@ -4132,6 +4072,7 @@ void RenderingDeviceDriverD3D12::command_uniform_set_prepare_for_use(CommandBuff } } + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; const UniformSetInfo *uniform_set_info = (const UniformSetInfo *)p_uniform_set.id; const ShaderInfo *shader_info_in = (const ShaderInfo *)p_shader.id; const ShaderInfo::UniformSet &shader_set = shader_info_in->sets[p_set_index]; @@ -4247,7 +4188,7 @@ void RenderingDeviceDriverD3D12::command_uniform_set_prepare_for_use(CommandBuff if (likely(wanted_state)) { if (sr.is_buffer) { - _resource_transition_batch(sr.resource, 0, 1, wanted_state); + _resource_transition_batch(cmd_buf_info, sr.resource, 0, 1, wanted_state); } else { TextureInfo *tex_info = (TextureInfo *)sr.resource; uint32_t planes = 1; @@ -4257,7 +4198,7 @@ void RenderingDeviceDriverD3D12::command_uniform_set_prepare_for_use(CommandBuff for (uint32_t i = 0; i < tex_info->layers; i++) { for (uint32_t j = 0; j < tex_info->mipmaps; j++) { uint32_t subresource = D3D12CalcSubresource(tex_info->base_mip + j, tex_info->base_layer + i, 0, tex_info->desc.MipLevels, tex_info->desc.ArraySize()); - _resource_transition_batch(tex_info, subresource, planes, wanted_state); + _resource_transition_batch(cmd_buf_info, tex_info, subresource, planes, wanted_state); } } } @@ -4266,8 +4207,7 @@ void RenderingDeviceDriverD3D12::command_uniform_set_prepare_for_use(CommandBuff } if (p_set_index == shader_info_in->sets.size() - 1) { - CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transitions_flush(cmd_buf_info); } } @@ -4520,7 +4460,7 @@ void RenderingDeviceDriverD3D12::_command_bind_uniform_set(CommandBufferID p_cmd void RenderingDeviceDriverD3D12::command_clear_buffer(CommandBufferID p_cmd_buffer, BufferID p_buffer, uint64_t p_offset, uint64_t p_size) { _command_check_descriptor_sets(p_cmd_buffer); - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; BufferInfo *buf_info = (BufferInfo *)p_buffer.id; if (frames[frame_idx].desc_heap_walkers.resources.is_at_eof()) { @@ -4545,8 +4485,8 @@ void RenderingDeviceDriverD3D12::command_clear_buffer(CommandBufferID p_cmd_buff } if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(buf_info, 0, 1, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transition_batch(cmd_buf_info, buf_info, 0, 1, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + _resource_transitions_flush(cmd_buf_info); } D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc = {}; @@ -4583,14 +4523,14 @@ void RenderingDeviceDriverD3D12::command_clear_buffer(CommandBufferID p_cmd_buff } void RenderingDeviceDriverD3D12::command_copy_buffer(CommandBufferID p_cmd_buffer, BufferID p_src_buffer, BufferID p_buf_locfer, VectorView<BufferCopyRegion> p_regions) { - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; BufferInfo *src_buf_info = (BufferInfo *)p_src_buffer.id; BufferInfo *buf_loc_info = (BufferInfo *)p_buf_locfer.id; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(src_buf_info, 0, 1, D3D12_RESOURCE_STATE_COPY_SOURCE); - _resource_transition_batch(buf_loc_info, 0, 1, D3D12_RESOURCE_STATE_COPY_DEST); - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transition_batch(cmd_buf_info, src_buf_info, 0, 1, D3D12_RESOURCE_STATE_COPY_SOURCE); + _resource_transition_batch(cmd_buf_info, buf_loc_info, 0, 1, D3D12_RESOURCE_STATE_COPY_DEST); + _resource_transitions_flush(cmd_buf_info); } for (uint32_t i = 0; i < p_regions.size(); i++) { @@ -4599,7 +4539,7 @@ void RenderingDeviceDriverD3D12::command_copy_buffer(CommandBufferID p_cmd_buffe } void RenderingDeviceDriverD3D12::command_copy_texture(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, VectorView<TextureCopyRegion> p_regions) { - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; TextureInfo *src_tex_info = (TextureInfo *)p_src_texture.id; TextureInfo *dst_tex_info = (TextureInfo *)p_dst_texture.id; @@ -4610,12 +4550,12 @@ void RenderingDeviceDriverD3D12::command_copy_texture(CommandBufferID p_cmd_buff for (uint32_t j = 0; j < layer_count; j++) { UINT src_subresource = _compute_subresource_from_layers(src_tex_info, p_regions[i].src_subresources, j); UINT dst_subresource = _compute_subresource_from_layers(dst_tex_info, p_regions[i].dst_subresources, j); - _resource_transition_batch(src_tex_info, src_subresource, 1, D3D12_RESOURCE_STATE_COPY_SOURCE); - _resource_transition_batch(dst_tex_info, dst_subresource, 1, D3D12_RESOURCE_STATE_COPY_DEST); + _resource_transition_batch(cmd_buf_info, src_tex_info, src_subresource, 1, D3D12_RESOURCE_STATE_COPY_SOURCE); + _resource_transition_batch(cmd_buf_info, dst_tex_info, dst_subresource, 1, D3D12_RESOURCE_STATE_COPY_DEST); } } - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transitions_flush(cmd_buf_info); } CD3DX12_BOX src_box; @@ -4638,23 +4578,23 @@ void RenderingDeviceDriverD3D12::command_copy_texture(CommandBufferID p_cmd_buff } void RenderingDeviceDriverD3D12::command_resolve_texture(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, uint32_t p_src_layer, uint32_t p_src_mipmap, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, uint32_t p_dst_layer, uint32_t p_dst_mipmap) { - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; TextureInfo *src_tex_info = (TextureInfo *)p_src_texture.id; TextureInfo *dst_tex_info = (TextureInfo *)p_dst_texture.id; UINT src_subresource = D3D12CalcSubresource(p_src_mipmap, p_src_layer, 0, src_tex_info->desc.MipLevels, src_tex_info->desc.ArraySize()); UINT dst_subresource = D3D12CalcSubresource(p_dst_mipmap, p_dst_layer, 0, dst_tex_info->desc.MipLevels, dst_tex_info->desc.ArraySize()); if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(src_tex_info, src_subresource, 1, D3D12_RESOURCE_STATE_RESOLVE_SOURCE); - _resource_transition_batch(dst_tex_info, dst_subresource, 1, D3D12_RESOURCE_STATE_RESOLVE_DEST); - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transition_batch(cmd_buf_info, src_tex_info, src_subresource, 1, D3D12_RESOURCE_STATE_RESOLVE_SOURCE); + _resource_transition_batch(cmd_buf_info, dst_tex_info, dst_subresource, 1, D3D12_RESOURCE_STATE_RESOLVE_DEST); + _resource_transitions_flush(cmd_buf_info); } cmd_buf_info->cmd_list->ResolveSubresource(dst_tex_info->resource, dst_subresource, src_tex_info->resource, src_subresource, RD_TO_D3D12_FORMAT[src_tex_info->format].general_format); } void RenderingDeviceDriverD3D12::command_clear_color_texture(CommandBufferID p_cmd_buffer, TextureID p_texture, TextureLayout p_texture_layout, const Color &p_color, const TextureSubresourceRange &p_subresources) { - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; TextureInfo *tex_info = (TextureInfo *)p_texture.id; if (tex_info->main_texture) { tex_info = tex_info->main_texture; @@ -4669,10 +4609,10 @@ void RenderingDeviceDriverD3D12::command_clear_color_texture(CommandBufferID p_c 0, tex_info->desc.MipLevels, tex_info->desc.ArraySize()); - _resource_transition_batch(tex_info, subresource, 1, p_new_state); + _resource_transition_batch(cmd_buf_info, tex_info, subresource, 1, p_new_state); } } - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transitions_flush(cmd_buf_info); }; if ((tex_info->desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET)) { @@ -4775,11 +4715,11 @@ void RenderingDeviceDriverD3D12::command_clear_color_texture(CommandBufferID p_c } void RenderingDeviceDriverD3D12::command_copy_buffer_to_texture(CommandBufferID p_cmd_buffer, BufferID p_src_buffer, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, VectorView<BufferTextureCopyRegion> p_regions) { - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; BufferInfo *buf_info = (BufferInfo *)p_src_buffer.id; TextureInfo *tex_info = (TextureInfo *)p_dst_texture.id; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(buf_info, 0, 1, D3D12_RESOURCE_STATE_COPY_SOURCE); + _resource_transition_batch(cmd_buf_info, buf_info, 0, 1, D3D12_RESOURCE_STATE_COPY_SOURCE); } uint32_t pixel_size = get_image_format_pixel_size(tex_info->format); @@ -4816,10 +4756,10 @@ void RenderingDeviceDriverD3D12::command_copy_buffer_to_texture(CommandBufferID tex_info->desc.ArraySize()); CD3DX12_TEXTURE_COPY_LOCATION copy_dst(tex_info->resource, dst_subresource); - _resource_transition_batch(tex_info, dst_subresource, 1, D3D12_RESOURCE_STATE_COPY_DEST); + _resource_transition_batch(cmd_buf_info, tex_info, dst_subresource, 1, D3D12_RESOURCE_STATE_COPY_DEST); } - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transitions_flush(cmd_buf_info); } for (uint32_t j = 0; j < p_regions[i].texture_subresources.layer_count; j++) { @@ -4843,12 +4783,12 @@ void RenderingDeviceDriverD3D12::command_copy_buffer_to_texture(CommandBufferID } void RenderingDeviceDriverD3D12::command_copy_texture_to_buffer(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, BufferID p_buf_locfer, VectorView<BufferTextureCopyRegion> p_regions) { - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; TextureInfo *tex_info = (TextureInfo *)p_src_texture.id; BufferInfo *buf_info = (BufferInfo *)p_buf_locfer.id; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(buf_info, 0, 1, D3D12_RESOURCE_STATE_COPY_DEST); + _resource_transition_batch(cmd_buf_info, buf_info, 0, 1, D3D12_RESOURCE_STATE_COPY_DEST); } uint32_t block_w = 0, block_h = 0; @@ -4864,10 +4804,10 @@ void RenderingDeviceDriverD3D12::command_copy_texture_to_buffer(CommandBufferID tex_info->desc.MipLevels, tex_info->desc.ArraySize()); - _resource_transition_batch(tex_info, src_subresource, 1, D3D12_RESOURCE_STATE_COPY_SOURCE); + _resource_transition_batch(cmd_buf_info, tex_info, src_subresource, 1, D3D12_RESOURCE_STATE_COPY_SOURCE); } - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transitions_flush(cmd_buf_info); } for (uint32_t j = 0; j < p_regions[i].texture_subresources.layer_count; j++) { @@ -4910,10 +4850,9 @@ void RenderingDeviceDriverD3D12::command_copy_texture_to_buffer(CommandBufferID /******************/ void RenderingDeviceDriverD3D12::pipeline_free(PipelineID p_pipeline) { - ID3D12PipelineState *pso = (ID3D12PipelineState *)p_pipeline.id; - pso->Release(); - pipelines_shaders.erase(pso); - render_psos_extra_info.erase(pso); + PipelineInfo *pipeline_info = (PipelineInfo *)(p_pipeline.id); + pipeline_info->pso->Release(); + memdelete(pipeline_info); } // ----- BINDING ----- @@ -5013,7 +4952,8 @@ void RenderingDeviceDriverD3D12::command_begin_render_pass(CommandBufferID p_cmd 0, p_texture_info->desc.MipLevels, p_texture_info->desc.ArraySize()); - _resource_transition_batch(p_texture_info, subresource, planes, p_states); + + _resource_transition_batch(cmd_buf_info, p_texture_info, subresource, planes, p_states); } } }; @@ -5035,7 +4975,7 @@ void RenderingDeviceDriverD3D12::command_begin_render_pass(CommandBufferID p_cmd _transition_subresources(tex_info, D3D12_RESOURCE_STATE_SHADING_RATE_SOURCE); } - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transitions_flush(cmd_buf_info); } cmd_buf_info->render_pass_state.region_rect = CD3DX12_RECT( @@ -5109,7 +5049,7 @@ void RenderingDeviceDriverD3D12::command_begin_render_pass(CommandBufferID p_cmd } void RenderingDeviceDriverD3D12::_end_render_pass(CommandBufferID p_cmd_buffer) { - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; DEV_ASSERT(cmd_buf_info->render_pass_state.current_subpass != UINT32_MAX); @@ -5122,7 +5062,7 @@ void RenderingDeviceDriverD3D12::_end_render_pass(CommandBufferID p_cmd_buffer) for (uint32_t i = 0; i < fb_info->attachments.size(); i++) { TextureInfo *src_tex_info = (TextureInfo *)(fb_info->attachments[i].id); uint32_t src_subresource = D3D12CalcSubresource(src_tex_info->base_mip, src_tex_info->base_layer, 0, src_tex_info->desc.MipLevels, src_tex_info->desc.ArraySize()); - _resource_transition_batch(src_tex_info, src_subresource, 1, D3D12_RESOURCE_STATE_PRESENT); + _resource_transition_batch(cmd_buf_info, src_tex_info, src_subresource, 1, D3D12_RESOURCE_STATE_PRESENT); } } @@ -5146,11 +5086,11 @@ void RenderingDeviceDriverD3D12::_end_render_pass(CommandBufferID p_cmd_buffer) TextureInfo *src_tex_info = (TextureInfo *)fb_info->attachments[color_index].id; uint32_t src_subresource = D3D12CalcSubresource(src_tex_info->base_mip, src_tex_info->base_layer, 0, src_tex_info->desc.MipLevels, src_tex_info->desc.ArraySize()); - _resource_transition_batch(src_tex_info, src_subresource, 1, D3D12_RESOURCE_STATE_RESOLVE_SOURCE); + _resource_transition_batch(cmd_buf_info, src_tex_info, src_subresource, 1, D3D12_RESOURCE_STATE_RESOLVE_SOURCE); TextureInfo *dst_tex_info = (TextureInfo *)fb_info->attachments[resolve_index].id; uint32_t dst_subresource = D3D12CalcSubresource(dst_tex_info->base_mip, dst_tex_info->base_layer, 0, dst_tex_info->desc.MipLevels, dst_tex_info->desc.ArraySize()); - _resource_transition_batch(dst_tex_info, dst_subresource, 1, D3D12_RESOURCE_STATE_RESOLVE_DEST); + _resource_transition_batch(cmd_buf_info, dst_tex_info, dst_subresource, 1, D3D12_RESOURCE_STATE_RESOLVE_DEST); resolves[num_resolves].src_res = src_tex_info->resource; resolves[num_resolves].src_subres = src_subresource; @@ -5160,7 +5100,7 @@ void RenderingDeviceDriverD3D12::_end_render_pass(CommandBufferID p_cmd_buffer) num_resolves++; } - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transitions_flush(cmd_buf_info); for (uint32_t i = 0; i < num_resolves; i++) { cmd_buf_info->cmd_list->ResolveSubresource(resolves[i].dst_res, resolves[i].dst_subres, resolves[i].src_res, resolves[i].src_subres, resolves[i].format); @@ -5348,36 +5288,36 @@ void RenderingDeviceDriverD3D12::command_render_clear_attachments(CommandBufferI void RenderingDeviceDriverD3D12::command_bind_render_pipeline(CommandBufferID p_cmd_buffer, PipelineID p_pipeline) { CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; - ID3D12PipelineState *pso = (ID3D12PipelineState *)p_pipeline.id; + const PipelineInfo *pipeline_info = (const PipelineInfo *)p_pipeline.id; - if (cmd_buf_info->graphics_pso == pso) { + if (cmd_buf_info->graphics_pso == pipeline_info->pso) { return; } - const ShaderInfo *shader_info_in = pipelines_shaders[pso]; - const RenderPipelineExtraInfo &pso_extra_info = render_psos_extra_info[pso]; + const ShaderInfo *shader_info_in = pipeline_info->shader_info; + const RenderPipelineInfo &render_info = pipeline_info->render_info; - cmd_buf_info->cmd_list->SetPipelineState(pso); + cmd_buf_info->cmd_list->SetPipelineState(pipeline_info->pso); if (cmd_buf_info->graphics_root_signature_crc != shader_info_in->root_signature_crc) { cmd_buf_info->cmd_list->SetGraphicsRootSignature(shader_info_in->root_signature.Get()); cmd_buf_info->graphics_root_signature_crc = shader_info_in->root_signature_crc; } - cmd_buf_info->cmd_list->IASetPrimitiveTopology(pso_extra_info.dyn_params.primitive_topology); - cmd_buf_info->cmd_list->OMSetBlendFactor(pso_extra_info.dyn_params.blend_constant.components); - cmd_buf_info->cmd_list->OMSetStencilRef(pso_extra_info.dyn_params.stencil_reference); + cmd_buf_info->cmd_list->IASetPrimitiveTopology(render_info.dyn_params.primitive_topology); + cmd_buf_info->cmd_list->OMSetBlendFactor(render_info.dyn_params.blend_constant.components); + cmd_buf_info->cmd_list->OMSetStencilRef(render_info.dyn_params.stencil_reference); if (misc_features_support.depth_bounds_supported) { ComPtr<ID3D12GraphicsCommandList1> command_list_1; cmd_buf_info->cmd_list->QueryInterface(command_list_1.GetAddressOf()); if (command_list_1) { - command_list_1->OMSetDepthBounds(pso_extra_info.dyn_params.depth_bounds_min, pso_extra_info.dyn_params.depth_bounds_max); + command_list_1->OMSetDepthBounds(render_info.dyn_params.depth_bounds_min, render_info.dyn_params.depth_bounds_max); } } - cmd_buf_info->render_pass_state.vf_info = pso_extra_info.vf_info; + cmd_buf_info->render_pass_state.vf_info = render_info.vf_info; - cmd_buf_info->graphics_pso = pso; + cmd_buf_info->graphics_pso = pipeline_info->pso; cmd_buf_info->compute_pso = nullptr; } @@ -5402,8 +5342,8 @@ void RenderingDeviceDriverD3D12::command_render_draw_indexed_indirect(CommandBuf _bind_vertex_buffers(cmd_buf_info); BufferInfo *indirect_buf_info = (BufferInfo *)p_indirect_buffer.id; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(indirect_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transition_batch(cmd_buf_info, indirect_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); + _resource_transitions_flush(cmd_buf_info); } cmd_buf_info->cmd_list->ExecuteIndirect(indirect_cmd_signatures.draw_indexed.Get(), p_draw_count, indirect_buf_info->resource, p_offset, nullptr, 0); @@ -5415,9 +5355,9 @@ void RenderingDeviceDriverD3D12::command_render_draw_indexed_indirect_count(Comm BufferInfo *indirect_buf_info = (BufferInfo *)p_indirect_buffer.id; BufferInfo *count_buf_info = (BufferInfo *)p_count_buffer.id; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(indirect_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); - _resource_transition_batch(count_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transition_batch(cmd_buf_info, indirect_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); + _resource_transition_batch(cmd_buf_info, count_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); + _resource_transitions_flush(cmd_buf_info); } cmd_buf_info->cmd_list->ExecuteIndirect(indirect_cmd_signatures.draw_indexed.Get(), p_max_draw_count, indirect_buf_info->resource, p_offset, count_buf_info->resource, p_count_buffer_offset); @@ -5428,8 +5368,8 @@ void RenderingDeviceDriverD3D12::command_render_draw_indirect(CommandBufferID p_ _bind_vertex_buffers(cmd_buf_info); BufferInfo *indirect_buf_info = (BufferInfo *)p_indirect_buffer.id; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(indirect_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transition_batch(cmd_buf_info, indirect_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); + _resource_transitions_flush(cmd_buf_info); } cmd_buf_info->cmd_list->ExecuteIndirect(indirect_cmd_signatures.draw.Get(), p_draw_count, indirect_buf_info->resource, p_offset, nullptr, 0); @@ -5441,9 +5381,9 @@ void RenderingDeviceDriverD3D12::command_render_draw_indirect_count(CommandBuffe BufferInfo *indirect_buf_info = (BufferInfo *)p_indirect_buffer.id; BufferInfo *count_buf_info = (BufferInfo *)p_count_buffer.id; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(indirect_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); - _resource_transition_batch(count_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transition_batch(cmd_buf_info, indirect_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); + _resource_transition_batch(cmd_buf_info, count_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); + _resource_transitions_flush(cmd_buf_info); } cmd_buf_info->cmd_list->ExecuteIndirect(indirect_cmd_signatures.draw.Get(), p_max_draw_count, indirect_buf_info->resource, p_offset, count_buf_info->resource, p_count_buffer_offset); @@ -5465,19 +5405,19 @@ void RenderingDeviceDriverD3D12::command_render_bind_vertex_buffers(CommandBuffe cmd_buf_info->render_pass_state.vertex_buffer_views[i].BufferLocation = buffer_info->resource->GetGPUVirtualAddress() + p_offsets[i]; cmd_buf_info->render_pass_state.vertex_buffer_views[i].SizeInBytes = buffer_info->size - p_offsets[i]; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(buffer_info, 0, 1, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER); + _resource_transition_batch(cmd_buf_info, buffer_info, 0, 1, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER); } } if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transitions_flush(cmd_buf_info); } cmd_buf_info->render_pass_state.vertex_buffer_count = p_binding_count; } void RenderingDeviceDriverD3D12::command_render_bind_index_buffer(CommandBufferID p_cmd_buffer, BufferID p_buffer, IndexBufferFormat p_format, uint64_t p_offset) { - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; BufferInfo *buffer_info = (BufferInfo *)p_buffer.id; D3D12_INDEX_BUFFER_VIEW d3d12_ib_view = {}; @@ -5486,8 +5426,8 @@ void RenderingDeviceDriverD3D12::command_render_bind_index_buffer(CommandBufferI d3d12_ib_view.Format = p_format == INDEX_BUFFER_FORMAT_UINT16 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(buffer_info, 0, 1, D3D12_RESOURCE_STATE_INDEX_BUFFER); - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transition_batch(cmd_buf_info, buffer_info, 0, 1, D3D12_RESOURCE_STATE_INDEX_BUFFER); + _resource_transitions_flush(cmd_buf_info); } cmd_buf_info->cmd_list->IASetIndexBuffer(&d3d12_ib_view); @@ -5628,9 +5568,9 @@ RDD::PipelineID RenderingDeviceDriverD3D12::render_pipeline_create( const ShaderInfo *shader_info_in = (const ShaderInfo *)p_shader.id; CD3DX12_PIPELINE_STATE_STREAM pipeline_desc = {}; - RenderPipelineExtraInfo pso_extra_info; const RenderPassInfo *pass_info = (const RenderPassInfo *)p_render_pass.id; + RenderPipelineInfo render_info; // Attachments. LocalVector<uint32_t> color_attachments; @@ -5664,7 +5604,7 @@ RDD::PipelineID RenderingDeviceDriverD3D12::render_pipeline_create( const VertexFormatInfo *vf_info = (const VertexFormatInfo *)p_vertex_format.id; (&pipeline_desc.InputLayout)->pInputElementDescs = vf_info->input_elem_descs.ptr(); (&pipeline_desc.InputLayout)->NumElements = vf_info->input_elem_descs.size(); - pso_extra_info.vf_info = vf_info; + render_info.vf_info = vf_info; } // Input assembly & tessellation. @@ -5673,9 +5613,9 @@ RDD::PipelineID RenderingDeviceDriverD3D12::render_pipeline_create( if (p_render_primitive == RENDER_PRIMITIVE_TESSELATION_PATCH) { // Is there any way to get the true point count limit? ERR_FAIL_COND_V(p_rasterization_state.patch_control_points < 1 || p_rasterization_state.patch_control_points > 32, PipelineID()); - pso_extra_info.dyn_params.primitive_topology = (D3D12_PRIMITIVE_TOPOLOGY)((int)D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + p_rasterization_state.patch_control_points); + render_info.dyn_params.primitive_topology = (D3D12_PRIMITIVE_TOPOLOGY)((int)D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + p_rasterization_state.patch_control_points); } else { - pso_extra_info.dyn_params.primitive_topology = RD_PRIMITIVE_TO_D3D12_TOPOLOGY[p_render_primitive]; + render_info.dyn_params.primitive_topology = RD_PRIMITIVE_TO_D3D12_TOPOLOGY[p_render_primitive]; } if (p_render_primitive == RENDER_PRIMITIVE_TRIANGLE_STRIPS_WITH_RESTART_INDEX) { // TODO: This is right for 16-bit indices; for 32-bit there's a different enum value to set, but we don't know at this point. @@ -5763,15 +5703,15 @@ RDD::PipelineID RenderingDeviceDriverD3D12::render_pipeline_create( (&pipeline_desc.DepthStencilState)->BackFace.StencilFunc = RD_TO_D3D12_COMPARE_OP[p_depth_stencil_state.back_op.compare]; if (misc_features_support.depth_bounds_supported) { - pso_extra_info.dyn_params.depth_bounds_min = p_depth_stencil_state.enable_depth_range ? p_depth_stencil_state.depth_range_min : 0.0f; - pso_extra_info.dyn_params.depth_bounds_max = p_depth_stencil_state.enable_depth_range ? p_depth_stencil_state.depth_range_max : 1.0f; + render_info.dyn_params.depth_bounds_min = p_depth_stencil_state.enable_depth_range ? p_depth_stencil_state.depth_range_min : 0.0f; + render_info.dyn_params.depth_bounds_max = p_depth_stencil_state.enable_depth_range ? p_depth_stencil_state.depth_range_max : 1.0f; } else { if (p_depth_stencil_state.enable_depth_range) { WARN_PRINT_ONCE("Depth bounds test is not supported by the GPU driver."); } } - pso_extra_info.dyn_params.stencil_reference = p_depth_stencil_state.front_op.reference; + render_info.dyn_params.stencil_reference = p_depth_stencil_state.front_op.reference; } // Blend states. @@ -5818,7 +5758,7 @@ RDD::PipelineID RenderingDeviceDriverD3D12::render_pipeline_create( (&pipeline_desc.BlendState)->IndependentBlendEnable = !all_attachments_same_blend; } - pso_extra_info.dyn_params.blend_constant = p_blend_state.blend_constant; + render_info.dyn_params.blend_constant = p_blend_state.blend_constant; // Stages bytecodes + specialization constants. @@ -5852,12 +5792,12 @@ RDD::PipelineID RenderingDeviceDriverD3D12::render_pipeline_create( } ERR_FAIL_COND_V_MSG(!SUCCEEDED(res), PipelineID(), "Create(Graphics)PipelineState failed with error " + vformat("0x%08ux", (uint64_t)res) + "."); - // Bookkeep ancillary info. - - pipelines_shaders[pso] = shader_info_in; - render_psos_extra_info[pso] = pso_extra_info; + PipelineInfo *pipeline_info = memnew(PipelineInfo); + pipeline_info->pso = pso; + pipeline_info->shader_info = shader_info_in; + pipeline_info->render_info = render_info; - return PipelineID(pso); + return PipelineID(pipeline_info); } /*****************/ @@ -5868,20 +5808,20 @@ RDD::PipelineID RenderingDeviceDriverD3D12::render_pipeline_create( void RenderingDeviceDriverD3D12::command_bind_compute_pipeline(CommandBufferID p_cmd_buffer, PipelineID p_pipeline) { CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; - ID3D12PipelineState *pso = (ID3D12PipelineState *)p_pipeline.id; - const ShaderInfo *shader_info_in = pipelines_shaders[pso]; + const PipelineInfo *pipeline_info = (const PipelineInfo *)p_pipeline.id; - if (cmd_buf_info->compute_pso == pso) { + if (cmd_buf_info->compute_pso == pipeline_info->pso) { return; } - cmd_buf_info->cmd_list->SetPipelineState(pso); + const ShaderInfo *shader_info_in = pipeline_info->shader_info; + cmd_buf_info->cmd_list->SetPipelineState(pipeline_info->pso); if (cmd_buf_info->compute_root_signature_crc != shader_info_in->root_signature_crc) { cmd_buf_info->cmd_list->SetComputeRootSignature(shader_info_in->root_signature.Get()); cmd_buf_info->compute_root_signature_crc = shader_info_in->root_signature_crc; } - cmd_buf_info->compute_pso = pso; + cmd_buf_info->compute_pso = pipeline_info->pso; cmd_buf_info->graphics_pso = nullptr; } @@ -5890,20 +5830,20 @@ void RenderingDeviceDriverD3D12::command_bind_compute_uniform_set(CommandBufferI } void RenderingDeviceDriverD3D12::command_compute_dispatch(CommandBufferID p_cmd_buffer, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups) { - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transitions_flush(cmd_buf_info); } cmd_buf_info->cmd_list->Dispatch(p_x_groups, p_y_groups, p_z_groups); } void RenderingDeviceDriverD3D12::command_compute_dispatch_indirect(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset) { - const CommandBufferInfo *cmd_buf_info = (const CommandBufferInfo *)p_cmd_buffer.id; + CommandBufferInfo *cmd_buf_info = (CommandBufferInfo *)p_cmd_buffer.id; BufferInfo *indirect_buf_info = (BufferInfo *)p_indirect_buffer.id; if (!barrier_capabilities.enhanced_barriers_supported) { - _resource_transition_batch(indirect_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); - _resource_transitions_flush(cmd_buf_info->cmd_list.Get()); + _resource_transition_batch(cmd_buf_info, indirect_buf_info, 0, 1, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); + _resource_transitions_flush(cmd_buf_info); } cmd_buf_info->cmd_list->ExecuteIndirect(indirect_cmd_signatures.dispatch.Get(), 1, indirect_buf_info->resource, p_offset, nullptr, 0); @@ -5944,11 +5884,11 @@ RDD::PipelineID RenderingDeviceDriverD3D12::compute_pipeline_create(ShaderID p_s } ERR_FAIL_COND_V_MSG(!SUCCEEDED(res), PipelineID(), "Create(Compute)PipelineState failed with error " + vformat("0x%08ux", (uint64_t)res) + "."); - // Bookkeep ancillary info. + PipelineInfo *pipeline_info = memnew(PipelineInfo); + pipeline_info->pso = pso; + pipeline_info->shader_info = shader_info_in; - pipelines_shaders[pso] = shader_info_in; - - return PipelineID(pso); + return PipelineID(pipeline_info); } /*****************/ @@ -6111,8 +6051,8 @@ void RenderingDeviceDriverD3D12::set_object_name(ObjectType p_type, ID p_driver_ } } break; case OBJECT_TYPE_PIPELINE: { - ID3D12PipelineState *pso = (ID3D12PipelineState *)p_driver_id.id; - _set_object_name(pso, p_name); + const PipelineInfo *pipeline_info = (const PipelineInfo *)p_driver_id.id; + _set_object_name(pipeline_info->pso, p_name); } break; default: { DEV_ASSERT(false); @@ -6645,8 +6585,6 @@ static Error create_command_signature(ID3D12Device *device, D3D12_INDIRECT_ARGUM Error RenderingDeviceDriverD3D12::_initialize_frames(uint32_t p_frame_count) { Error err; - D3D12MA::ALLOCATION_DESC allocation_desc = {}; - allocation_desc.HeapType = D3D12_HEAP_TYPE_DEFAULT; //CD3DX12_RESOURCE_DESC resource_desc = CD3DX12_RESOURCE_DESC::Buffer(D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT); uint32_t resource_descriptors_per_frame = GLOBAL_GET("rendering/rendering_device/d3d12/max_resource_descriptors_per_frame"); diff --git a/drivers/d3d12/rendering_device_driver_d3d12.h b/drivers/d3d12/rendering_device_driver_d3d12.h index d8381279ec..b449a90876 100644 --- a/drivers/d3d12/rendering_device_driver_d3d12.h +++ b/drivers/d3d12/rendering_device_driver_d3d12.h @@ -80,7 +80,6 @@ using Microsoft::WRL::ComPtr; #define D3D12_BITCODE_OFFSETS_NUM_STAGES 3 #ifdef DEV_ENABLED -//#define DEBUG_COUNT_BARRIERS #define CUSTOM_INFO_QUEUE_ENABLED 0 #endif @@ -223,20 +222,6 @@ private: ComPtr<D3D12MA::Allocator> allocator; -#define USE_SMALL_ALLOCS_POOL // Disabled by now; seems not to be beneficial as it is in Vulkan. -#ifdef USE_SMALL_ALLOCS_POOL - union AllocPoolKey { - struct { - D3D12_HEAP_TYPE heap_type; - D3D12_HEAP_FLAGS heap_flags; - }; - uint64_t key = 0; - }; - HashMap<uint64_t, ComPtr<D3D12MA::Pool>> small_allocs_pools; - - D3D12MA::Pool *_find_or_create_small_allocs_pool(D3D12_HEAP_TYPE p_heap_type, D3D12_HEAP_FLAGS p_heap_flags); -#endif - /******************/ /**** RESOURCE ****/ /******************/ @@ -274,20 +259,11 @@ private: uint8_t groups_count = 0; static const D3D12_RESOURCE_STATES DELETED_GROUP = D3D12_RESOURCE_STATES(0xFFFFFFFFU); }; - PagedAllocator<HashMapElement<ResourceInfo::States *, BarrierRequest>> res_barriers_requests_allocator; - HashMap<ResourceInfo::States *, BarrierRequest, HashMapHasherDefault, HashMapComparatorDefault<ResourceInfo::States *>, decltype(res_barriers_requests_allocator)> res_barriers_requests; - - LocalVector<D3D12_RESOURCE_BARRIER> res_barriers; - uint32_t res_barriers_count = 0; - uint32_t res_barriers_batch = 0; -#ifdef DEBUG_COUNT_BARRIERS - int frame_barriers_count = 0; - int frame_barriers_batches_count = 0; - uint64_t frame_barriers_cpu_time = 0; -#endif - void _resource_transition_batch(ResourceInfo *p_resource, uint32_t p_subresource, uint32_t p_num_planes, D3D12_RESOURCE_STATES p_new_state); - void _resource_transitions_flush(ID3D12GraphicsCommandList *p_cmd_list); + struct CommandBufferInfo; + + void _resource_transition_batch(CommandBufferInfo *p_command_buffer, ResourceInfo *p_resource, uint32_t p_subresource, uint32_t p_num_planes, D3D12_RESOURCE_STATES p_new_state); + void _resource_transitions_flush(CommandBufferInfo *p_command_buffer); /*****************/ /**** BUFFERS ****/ @@ -334,6 +310,7 @@ private: SelfList<TextureInfo>::List textures_pending_clear; HashMap<DXGI_FORMAT, uint32_t> format_sample_counts_mask_cache; + Mutex format_sample_counts_mask_cache_mutex; uint32_t _find_max_common_supported_sample_count(VectorView<DXGI_FORMAT> p_formats); UINT _compute_component_mapping(const TextureView &p_view); @@ -341,7 +318,6 @@ private: UINT _compute_plane_slice(DataFormat p_format, TextureAspect p_aspect); UINT _compute_subresource_from_layers(TextureInfo *p_texture, const TextureSubresourceLayers &p_layers, uint32_t p_layer_offset); - struct CommandBufferInfo; void _discard_texture_subresources(const TextureInfo *p_tex_info, const CommandBufferInfo *p_cmd_buf_info); protected: @@ -492,6 +468,11 @@ private: RenderPassState render_pass_state; bool descriptor_heaps_set = false; + + HashMap<ResourceInfo::States *, BarrierRequest> res_barriers_requests; + LocalVector<D3D12_RESOURCE_BARRIER> res_barriers; + uint32_t res_barriers_count = 0; + uint32_t res_barriers_batch = 0; }; public: @@ -797,10 +778,25 @@ public: /**** PIPELINE ****/ /******************/ - virtual void pipeline_free(PipelineID p_pipeline) override final; + struct RenderPipelineInfo { + const VertexFormatInfo *vf_info = nullptr; -private: - HashMap<ID3D12PipelineState *, const ShaderInfo *> pipelines_shaders; + struct { + D3D12_PRIMITIVE_TOPOLOGY primitive_topology = {}; + Color blend_constant; + float depth_bounds_min = 0.0f; + float depth_bounds_max = 0.0f; + uint32_t stencil_reference = 0; + } dyn_params; + }; + + struct PipelineInfo { + ID3D12PipelineState *pso = nullptr; + const ShaderInfo *shader_info = nullptr; + RenderPipelineInfo render_info; + }; + + virtual void pipeline_free(PipelineID p_pipeline) override final; public: // ----- BINDING ----- @@ -873,20 +869,6 @@ public: // ----- PIPELINE ----- -private: - struct RenderPipelineExtraInfo { - struct { - D3D12_PRIMITIVE_TOPOLOGY primitive_topology = {}; - Color blend_constant; - float depth_bounds_min = 0.0f; - float depth_bounds_max = 0.0f; - uint32_t stencil_reference = 0; - } dyn_params; - - const VertexFormatInfo *vf_info = nullptr; - }; - HashMap<ID3D12PipelineState *, RenderPipelineExtraInfo> render_psos_extra_info; - public: virtual PipelineID render_pipeline_create( ShaderID p_shader, @@ -1034,7 +1016,7 @@ private: UniformSetInfo, RenderPassInfo, TimestampQueryPoolInfo>; - PagedAllocator<VersatileResource> resources_allocator; + PagedAllocator<VersatileResource, true> resources_allocator; /******************/ diff --git a/drivers/egl/egl_manager.cpp b/drivers/egl/egl_manager.cpp index 4477ba7752..603dfadd4b 100644 --- a/drivers/egl/egl_manager.cpp +++ b/drivers/egl/egl_manager.cpp @@ -30,6 +30,8 @@ #include "egl_manager.h" +#include "drivers/gles3/rasterizer_gles3.h" + #ifdef EGL_ENABLED #if defined(EGL_STATIC) @@ -51,6 +53,16 @@ extern "C" EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT(EGLenum platfo #define GLAD_EGL_EXT_platform_base 0 #endif +#ifdef WINDOWS_ENABLED +// Unofficial ANGLE extension: EGL_ANGLE_surface_orientation +#ifndef EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE +#define EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE 0x33A7 +#define EGL_SURFACE_ORIENTATION_ANGLE 0x33A8 +#define EGL_SURFACE_ORIENTATION_INVERT_X_ANGLE 0x0001 +#define EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE 0x0002 +#endif +#endif + // Creates and caches a GLDisplay. Returns -1 on error. int EGLManager::_get_gldisplay_id(void *p_display) { // Look for a cached GLDisplay. @@ -115,6 +127,18 @@ int EGLManager::_get_gldisplay_id(void *p_display) { } #endif +#ifdef WINDOWS_ENABLED + String client_extensions_string = eglQueryString(new_gldisplay.egl_display, EGL_EXTENSIONS); + if (eglGetError() == EGL_SUCCESS) { + Vector<String> egl_extensions = client_extensions_string.split(" "); + + if (egl_extensions.has("EGL_ANGLE_surface_orientation")) { + new_gldisplay.has_EGL_ANGLE_surface_orientation = true; + print_verbose("EGL: EGL_ANGLE_surface_orientation is supported."); + } + } +#endif + displays.push_back(new_gldisplay); // Return the new GLDisplay's ID. @@ -237,8 +261,29 @@ Error EGLManager::window_create(DisplayServer::WindowID p_window_id, void *p_dis GLWindow &glwindow = windows[p_window_id]; glwindow.gldisplay_id = gldisplay_id; + Vector<EGLAttrib> egl_attribs; + +#ifdef WINDOWS_ENABLED + if (gldisplay.has_EGL_ANGLE_surface_orientation) { + EGLint optimal_orientation; + if (eglGetConfigAttrib(gldisplay.egl_display, gldisplay.egl_config, EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE, &optimal_orientation)) { + // We only need to support inverting Y for optimizing ANGLE on D3D11. + if (optimal_orientation & EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE && !(optimal_orientation & EGL_SURFACE_ORIENTATION_INVERT_X_ANGLE)) { + egl_attribs.push_back(EGL_SURFACE_ORIENTATION_ANGLE); + egl_attribs.push_back(EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE); + } + } else { + ERR_PRINT(vformat("Failed to get EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE, error: 0x%08X", eglGetError())); + } + } + + if (!egl_attribs.is_empty()) { + egl_attribs.push_back(EGL_NONE); + } +#endif + if (GLAD_EGL_VERSION_1_5) { - glwindow.egl_surface = eglCreatePlatformWindowSurface(gldisplay.egl_display, gldisplay.egl_config, p_native_window, nullptr); + glwindow.egl_surface = eglCreatePlatformWindowSurface(gldisplay.egl_display, gldisplay.egl_config, p_native_window, egl_attribs.ptr()); } else { EGLNativeWindowType *native_window_type = (EGLNativeWindowType *)p_native_window; glwindow.egl_surface = eglCreateWindowSurface(gldisplay.egl_display, gldisplay.egl_config, *native_window_type, nullptr); @@ -250,6 +295,20 @@ Error EGLManager::window_create(DisplayServer::WindowID p_window_id, void *p_dis glwindow.initialized = true; +#ifdef WINDOWS_ENABLED + if (gldisplay.has_EGL_ANGLE_surface_orientation) { + EGLint orientation; + if (eglQuerySurface(gldisplay.egl_display, glwindow.egl_surface, EGL_SURFACE_ORIENTATION_ANGLE, &orientation)) { + if (orientation & EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE && !(orientation & EGL_SURFACE_ORIENTATION_INVERT_X_ANGLE)) { + glwindow.flipped_y = true; + print_verbose("EGL: Using optimal surface orientation: Invert Y"); + } + } else { + ERR_PRINT(vformat("Failed to get EGL_SURFACE_ORIENTATION_ANGLE, error: 0x%08X", eglGetError())); + } + } +#endif + window_make_current(p_window_id); return OK; @@ -316,6 +375,10 @@ void EGLManager::window_make_current(DisplayServer::WindowID p_window_id) { GLDisplay ¤t_display = displays[current_window->gldisplay_id]; eglMakeCurrent(current_display.egl_display, current_window->egl_surface, current_window->egl_surface, current_display.egl_context); + +#ifdef WINDOWS_ENABLED + RasterizerGLES3::set_screen_flipped_y(glwindow.flipped_y); +#endif } void EGLManager::set_use_vsync(bool p_use) { diff --git a/drivers/egl/egl_manager.h b/drivers/egl/egl_manager.h index a4502c0687..f1b3dc99b7 100644 --- a/drivers/egl/egl_manager.h +++ b/drivers/egl/egl_manager.h @@ -53,11 +53,18 @@ private: EGLDisplay egl_display = EGL_NO_DISPLAY; EGLContext egl_context = EGL_NO_CONTEXT; EGLConfig egl_config = nullptr; + +#ifdef WINDOWS_ENABLED + bool has_EGL_ANGLE_surface_orientation = false; +#endif }; // EGL specific window data. struct GLWindow { bool initialized = false; +#ifdef WINDOWS_ENABLED + bool flipped_y = false; +#endif // An handle to the GLDisplay associated with this window. int gldisplay_id = -1; diff --git a/drivers/gles3/rasterizer_canvas_gles3.h b/drivers/gles3/rasterizer_canvas_gles3.h index 9c0d0abccb..a82e2713e0 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.h +++ b/drivers/gles3/rasterizer_canvas_gles3.h @@ -379,6 +379,8 @@ public: } } + virtual uint32_t get_pipeline_compilations(RS::PipelineSource p_source) override { return 0; } + static RasterizerCanvasGLES3 *get_singleton(); RasterizerCanvasGLES3(); ~RasterizerCanvasGLES3(); diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index e79f1db08d..6e508c6ebf 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -86,6 +86,10 @@ #define strcpy strcpy_s #endif +#ifdef WINDOWS_ENABLED +bool RasterizerGLES3::screen_flipped_y = false; +#endif + bool RasterizerGLES3::gles_over_gl = true; void RasterizerGLES3::begin_frame(double frame_step) { @@ -389,6 +393,12 @@ void RasterizerGLES3::_blit_render_target_to_screen(RID p_render_target, Display flip_y = false; } +#ifdef WINDOWS_ENABLED + if (screen_flipped_y) { + flip_y = !flip_y; + } +#endif + GLuint read_fbo = 0; glGenFramebuffers(1, &read_fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, read_fbo); @@ -485,9 +495,14 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c screenrect.position += ((Size2(win_size.width, win_size.height) - screenrect.size) / 2.0).floor(); } - // Flip Y. - screenrect.position.y = win_size.y - screenrect.position.y; - screenrect.size.y = -screenrect.size.y; +#ifdef WINDOWS_ENABLED + if (!screen_flipped_y) +#endif + { + // Flip Y. + screenrect.position.y = win_size.y - screenrect.position.y; + screenrect.size.y = -screenrect.size.y; + } // Normalize texture coordinates to window size. screenrect.position /= win_size; diff --git a/drivers/gles3/rasterizer_gles3.h b/drivers/gles3/rasterizer_gles3.h index 92c96519d2..6765d8b4d5 100644 --- a/drivers/gles3/rasterizer_gles3.h +++ b/drivers/gles3/rasterizer_gles3.h @@ -58,6 +58,10 @@ private: double time_total = 0.0; bool flip_xy_workaround = false; +#ifdef WINDOWS_ENABLED + static bool screen_flipped_y; +#endif + static bool gles_over_gl; protected: @@ -118,9 +122,16 @@ public: low_end = true; } +#ifdef WINDOWS_ENABLED + static void set_screen_flipped_y(bool p_flipped) { + screen_flipped_y = p_flipped; + } +#endif + _ALWAYS_INLINE_ uint64_t get_frame_number() const { return frame; } _ALWAYS_INLINE_ double get_frame_delta_time() const { return delta; } _ALWAYS_INLINE_ double get_total_time() const { return time_total; } + _ALWAYS_INLINE_ bool can_create_resources_async() const { return false; } static RasterizerGLES3 *get_singleton() { return singleton; } RasterizerGLES3(); diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index c2d1784958..a73f14c796 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -3443,6 +3443,7 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params, } material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::MODEL_FLAGS, inst->flags_cache, shader->version, instance_variant, spec_constants); + material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::INSTANCE_OFFSET, uint32_t(inst->shader_uniforms_offset), shader->version, instance_variant, spec_constants); if (p_pass_mode == PASS_MODE_MATERIAL) { material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::UV_OFFSET, p_params->uv_offset, shader->version, instance_variant, spec_constants); diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index e4af8f99e9..06371b2b7f 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -767,6 +767,11 @@ public: uint32_t geometry_instance_get_pair_mask() override; + /* PIPELINES */ + + virtual void mesh_generate_pipelines(RID p_mesh, bool p_background_compilation) override {} + virtual uint32_t get_pipeline_compilations(RS::PipelineSource p_source) override { return 0; } + /* SDFGI UPDATE */ void sdfgi_update(const Ref<RenderSceneBuffers> &p_render_buffers, RID p_environment, const Vector3 &p_world_position) override {} diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 9ce10a4488..fcfbeddb9e 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -430,6 +430,7 @@ uniform highp mat4 world_transform; uniform highp vec3 compressed_aabb_position; uniform highp vec3 compressed_aabb_size; uniform highp vec4 uv_scale; +uniform highp uint instance_offset; uniform highp uint model_flags; @@ -1201,6 +1202,7 @@ ivec2 multiview_uv(ivec2 uv) { uniform highp mat4 world_transform; uniform mediump float opaque_prepass_threshold; uniform highp uint model_flags; +uniform highp uint instance_offset; #if defined(RENDER_MATERIAL) layout(location = 0) out vec4 albedo_output_buffer; diff --git a/drivers/gles3/storage/material_storage.cpp b/drivers/gles3/storage/material_storage.cpp index 5dca149d99..684f179492 100644 --- a/drivers/gles3/storage/material_storage.cpp +++ b/drivers/gles3/storage/material_storage.cpp @@ -1379,6 +1379,7 @@ MaterialStorage::MaterialStorage() { actions.check_multiview_samplers = RasterizerGLES3::get_singleton()->is_xr_enabled(); actions.global_buffer_array_variable = "global_shader_uniforms"; + actions.instance_uniform_index_variable = "instance_offset"; shaders.compiler_scene.initialize(actions); } diff --git a/drivers/gles3/storage/texture_storage.cpp b/drivers/gles3/storage/texture_storage.cpp index 27ba89aa5f..d7b4d6911d 100644 --- a/drivers/gles3/storage/texture_storage.cpp +++ b/drivers/gles3/storage/texture_storage.cpp @@ -251,11 +251,6 @@ TextureStorage::~TextureStorage() { sdf_shader.shader.version_free(sdf_shader.shader_version); } -//TODO, move back to storage -bool TextureStorage::can_create_resources_async() const { - return false; -} - /* Canvas Texture API */ RID TextureStorage::canvas_texture_allocate() { diff --git a/drivers/gles3/storage/texture_storage.h b/drivers/gles3/storage/texture_storage.h index 2bf8546c0f..3786c8c690 100644 --- a/drivers/gles3/storage/texture_storage.h +++ b/drivers/gles3/storage/texture_storage.h @@ -505,8 +505,6 @@ public: texture_owner.initialize_rid(p_texture, p_tex); } - virtual bool can_create_resources_async() const override; - virtual RID texture_allocate() override; virtual void texture_free(RID p_rid) override; diff --git a/drivers/metal/rendering_device_driver_metal.mm b/drivers/metal/rendering_device_driver_metal.mm index 9d691a0d23..a4a408356a 100644 --- a/drivers/metal/rendering_device_driver_metal.mm +++ b/drivers/metal/rendering_device_driver_metal.mm @@ -358,7 +358,11 @@ RDD::TextureID RenderingDeviceDriverMetal::texture_create(const TextureFormat &p } RDD::TextureID RenderingDeviceDriverMetal::texture_create_from_extension(uint64_t p_native_texture, TextureType p_type, DataFormat p_format, uint32_t p_array_layers, bool p_depth_stencil) { - ERR_FAIL_V_MSG(RDD::TextureID(), "not implemented"); + id<MTLTexture> obj = (__bridge id<MTLTexture>)(void *)(uintptr_t)p_native_texture; + + // We only need to create a RDD::TextureID for an existing, natively-provided texture. + + return rid::make(obj); } RDD::TextureID RenderingDeviceDriverMetal::texture_create_shared(TextureID p_original_texture, const TextureView &p_view) { @@ -3667,7 +3671,8 @@ void RenderingDeviceDriverMetal::set_object_name(ObjectType p_type, ID p_driver_ uint64_t RenderingDeviceDriverMetal::get_resource_native_handle(DriverResource p_type, ID p_driver_id) { switch (p_type) { case DRIVER_RESOURCE_LOGICAL_DEVICE: { - return 0; + uintptr_t devicePtr = (uintptr_t)(__bridge void *)device; + return (uint64_t)devicePtr; } case DRIVER_RESOURCE_PHYSICAL_DEVICE: { return 0; diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index e4bad88083..816ffd7a32 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -410,7 +410,17 @@ Error DirAccessUnix::rename(String p_path, String p_new_path) { p_new_path = p_new_path.left(-1); } - return ::rename(p_path.utf8().get_data(), p_new_path.utf8().get_data()) == 0 ? OK : FAILED; + int res = ::rename(p_path.utf8().get_data(), p_new_path.utf8().get_data()); + if (res != 0 && errno == EXDEV) { // Cross-device move, use copy and remove. + Error err = OK; + err = copy(p_path, p_new_path); + if (err != OK) { + return err; + } + return remove(p_path); + } else { + return (res == 0) ? OK : FAILED; + } } Error DirAccessUnix::remove(String p_path) { diff --git a/drivers/vulkan/rendering_device_driver_vulkan.cpp b/drivers/vulkan/rendering_device_driver_vulkan.cpp index bd395f41e2..d20f396281 100644 --- a/drivers/vulkan/rendering_device_driver_vulkan.cpp +++ b/drivers/vulkan/rendering_device_driver_vulkan.cpp @@ -4103,10 +4103,6 @@ bool RenderingDeviceDriverVulkan::pipeline_cache_create(const Vector<uint8_t> &p cache_info.initialDataSize = pipelines_cache.buffer.size() - sizeof(PipelineCacheHeader); cache_info.pInitialData = pipelines_cache.buffer.ptr() + sizeof(PipelineCacheHeader); - if (pipeline_cache_control_support) { - cache_info.flags = VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT; - } - VkResult err = vkCreatePipelineCache(vk_device, &cache_info, VKC::get_allocation_callbacks(VK_OBJECT_TYPE_PIPELINE_CACHE), &pipelines_cache.vk_cache); if (err != VK_SUCCESS) { WARN_PRINT("vkCreatePipelinecache failed with error " + itos(err) + "."); diff --git a/drivers/vulkan/rendering_device_driver_vulkan.h b/drivers/vulkan/rendering_device_driver_vulkan.h index cc15c0a0fe..58f7a97ec0 100644 --- a/drivers/vulkan/rendering_device_driver_vulkan.h +++ b/drivers/vulkan/rendering_device_driver_vulkan.h @@ -668,7 +668,7 @@ private: VertexFormatInfo, ShaderInfo, UniformSetInfo>; - PagedAllocator<VersatileResource> resources_allocator; + PagedAllocator<VersatileResource, true> resources_allocator; /******************/ |