├── COMMIT ├── parallel-rdp ├── shaders │ ├── fb_formats.h │ ├── load_span_offsets.h │ ├── load_attribute_setup.h │ ├── vi_deinterlace.frag │ ├── load_scissor_state.h │ ├── clear_indirect_buffer.comp │ ├── clear_super_sampled_write_mask.comp │ ├── fullscreen.vert │ ├── vi_blend_fields.frag │ ├── clear_write_mask.comp │ ├── vi_deinterlace.vert │ ├── load_depth_blend_state.h │ ├── load_span_setup.h │ ├── load_static_raster_state.h │ ├── load_triangle_setup.h │ ├── store_span_setup.h │ ├── load_tile_info.h │ ├── z_encode.h │ ├── load_derived_setup.h │ ├── vi_debug.h │ ├── masked_rdram_resolve.comp │ ├── noise.h │ ├── vi_status.h │ ├── clamping.h │ ├── coverage.h │ ├── dither.h │ ├── slangmosh.json │ ├── vi_divot.frag │ ├── small_types.h │ ├── extract_vram.comp │ ├── update_upscaled_domain_post.comp │ └── ubershader.comp ├── command_ring.hpp ├── rdp_dump_write.hpp └── worker_thread.hpp ├── vulkan-headers └── include │ ├── vk_video │ ├── vulkan_video_codecs_common.h │ ├── vulkan_video_codec_h265std_decode.h │ └── vulkan_video_codec_h264std_decode.h │ └── vulkan │ ├── vulkan_vi.h │ ├── vulkan_ios.h │ ├── vulkan_macos.h │ ├── vulkan_xlib_xrandr.h │ ├── vulkan_wayland.h │ ├── vulkan_xlib.h │ ├── vulkan.h │ ├── vulkan_directfb.h │ ├── vulkan_xcb.h │ ├── vulkan_ggp.h │ ├── vk_sdk_platform.h │ └── vk_platform.h ├── LICENSE ├── util ├── thread_name.hpp ├── thread_id.hpp ├── enum_cast.hpp ├── environment.hpp ├── thread_id.cpp ├── stack_allocator.hpp ├── timer.hpp ├── thread_name.cpp ├── logging.cpp ├── dynamic_array.hpp ├── aligned_alloc.hpp ├── hash.hpp ├── aligned_alloc.cpp ├── environment.cpp ├── timeline_trace_file.hpp ├── timer.cpp ├── object_pool.hpp ├── logging.hpp └── read_write_lock.hpp ├── vulkan ├── cookie.cpp ├── pipeline_event.cpp ├── fence_manager.hpp ├── semaphore_manager.hpp ├── event_manager.hpp ├── cookie.hpp ├── limits.hpp ├── quirks.hpp ├── fence_manager.cpp ├── pipeline_event.hpp ├── command_pool.hpp ├── semaphore_manager.cpp ├── event_manager.cpp ├── indirect_layout.hpp ├── vulkan_headers.hpp ├── fence.hpp ├── device_fossilize.hpp ├── buffer.cpp ├── buffer_pool.hpp ├── renderdoc_capture.cpp ├── type_to_string.hpp ├── vulkan_common.hpp └── fence.cpp └── config.mk /COMMIT: -------------------------------------------------------------------------------- 1 | 1cecd042b2619bc505c12bfdc713808386f2b54d 2 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/fb_formats.h: -------------------------------------------------------------------------------- 1 | #ifndef FB_FORMATS_H_ 2 | #define FB_FORMATS_H_ 3 | 4 | const int FB_FMT_I4 = 0; 5 | const int FB_FMT_I8 = 1; 6 | const int FB_FMT_RGBA5551 = 2; 7 | const int FB_FMT_IA88 = 3; 8 | const int FB_FMT_RGBA8888 = 4; 9 | 10 | #endif -------------------------------------------------------------------------------- /vulkan-headers/include/vk_video/vulkan_video_codecs_common.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODECS_COMMON_H_ 2 | #define VULKAN_VIDEO_CODECS_COMMON_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codecs_common is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codecs_common 1 24 | #if !defined(VK_NO_STDINT_H) 25 | #include 26 | #endif 27 | 28 | #define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \ 29 | ((((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch))) 30 | 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020 Themaister 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /util/thread_name.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | namespace Util 26 | { 27 | void set_current_thread_name(const char *name); 28 | } 29 | -------------------------------------------------------------------------------- /util/thread_id.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | namespace Util 26 | { 27 | unsigned get_current_thread_index(); 28 | void register_thread_index(unsigned thread_index); 29 | } -------------------------------------------------------------------------------- /vulkan/cookie.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "cookie.hpp" 24 | #include "device.hpp" 25 | 26 | namespace Vulkan 27 | { 28 | Cookie::Cookie(Device *device) 29 | : cookie(device->allocate_cookie()) 30 | { 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/load_span_offsets.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LOAD_SPAN_OFFSETS_H_ 24 | #define LOAD_SPAN_OFFSETS_H_ 25 | 26 | SpanInfoOffsets load_span_offsets(uint index) 27 | { 28 | return span_offsets.elems[index]; 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /parallel-rdp/shaders/load_attribute_setup.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LOAD_ATTRIBUTE_SETUP_H_ 24 | #define LOAD_ATTRIBUTE_SETUP_H_ 25 | 26 | AttributeSetup load_attribute_setup(uint index) 27 | { 28 | return attribute_setup.elems[index]; 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /parallel-rdp/shaders/vi_deinterlace.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | layout(location = 0) in vec2 vUV; 25 | layout(set = 0, binding = 0) uniform sampler2D uSampler; 26 | layout(location = 0) out vec4 FragColor; 27 | 28 | void main() 29 | { 30 | FragColor = textureLod(uSampler, vUV, 0.0); 31 | } -------------------------------------------------------------------------------- /util/enum_cast.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace Util 28 | { 29 | template 30 | constexpr typename std::underlying_type::type ecast(T x) 31 | { 32 | return static_cast::type>(x); 33 | } 34 | } -------------------------------------------------------------------------------- /parallel-rdp/shaders/load_scissor_state.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LOAD_SCISSOR_STATE_H_ 24 | #define LOAD_SCISSOR_STATE_H_ 25 | 26 | ScissorState load_scissor_state(uint index) 27 | { 28 | ivec4 values = scissor_state.elems[index]; 29 | return ScissorState(values.x, values.y, values.z, values.w); 30 | } 31 | 32 | #endif -------------------------------------------------------------------------------- /parallel-rdp/shaders/clear_indirect_buffer.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | layout(local_size_x_id = 0) in; 24 | 25 | layout(set = 0, binding = 0, std430) writeonly buffer ClearIndirectBuffer 26 | { 27 | uvec4 indirects[]; 28 | }; 29 | 30 | void main() 31 | { 32 | indirects[gl_GlobalInvocationID.x] = uvec4(0, 1, 1, 0); 33 | } -------------------------------------------------------------------------------- /parallel-rdp/shaders/clear_super_sampled_write_mask.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | layout(local_size_x_id = 0) in; 25 | 26 | layout(set = 0, binding = 0, std430) writeonly buffer ToClear 27 | { 28 | uint elems[]; 29 | } mask_ram; 30 | 31 | void main() 32 | { 33 | mask_ram.elems[gl_GlobalInvocationID.x] = 0u; 34 | } 35 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/fullscreen.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | void main() 25 | { 26 | if (gl_VertexIndex == 0) 27 | gl_Position = vec4(-1.0, -1.0, 0.0, 1.0); 28 | else if (gl_VertexIndex == 1) 29 | gl_Position = vec4(-1.0, +3.0, 0.0, 1.0); 30 | else 31 | gl_Position = vec4(+3.0, -1.0, 0.0, 1.0); 32 | } 33 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vulkan_vi.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VI_H_ 2 | #define VULKAN_VI_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_NN_vi_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_NN_vi_surface 1 24 | #define VK_NN_VI_SURFACE_SPEC_VERSION 1 25 | #define VK_NN_VI_SURFACE_EXTENSION_NAME "VK_NN_vi_surface" 26 | typedef VkFlags VkViSurfaceCreateFlagsNN; 27 | typedef struct VkViSurfaceCreateInfoNN { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkViSurfaceCreateFlagsNN flags; 31 | void* window; 32 | } VkViSurfaceCreateInfoNN; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateViSurfaceNN)(VkInstance instance, const VkViSurfaceCreateInfoNN* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN( 38 | VkInstance instance, 39 | const VkViSurfaceCreateInfoNN* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vulkan_ios.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_IOS_H_ 2 | #define VULKAN_IOS_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_MVK_ios_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_MVK_ios_surface 1 24 | #define VK_MVK_IOS_SURFACE_SPEC_VERSION 3 25 | #define VK_MVK_IOS_SURFACE_EXTENSION_NAME "VK_MVK_ios_surface" 26 | typedef VkFlags VkIOSSurfaceCreateFlagsMVK; 27 | typedef struct VkIOSSurfaceCreateInfoMVK { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkIOSSurfaceCreateFlagsMVK flags; 31 | const void* pView; 32 | } VkIOSSurfaceCreateInfoMVK; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateIOSSurfaceMVK)(VkInstance instance, const VkIOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK( 38 | VkInstance instance, 39 | const VkIOSSurfaceCreateInfoMVK* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vulkan_macos.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_MACOS_H_ 2 | #define VULKAN_MACOS_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_MVK_macos_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_MVK_macos_surface 1 24 | #define VK_MVK_MACOS_SURFACE_SPEC_VERSION 3 25 | #define VK_MVK_MACOS_SURFACE_EXTENSION_NAME "VK_MVK_macos_surface" 26 | typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; 27 | typedef struct VkMacOSSurfaceCreateInfoMVK { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkMacOSSurfaceCreateFlagsMVK flags; 31 | const void* pView; 32 | } VkMacOSSurfaceCreateInfoMVK; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateMacOSSurfaceMVK)(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK( 38 | VkInstance instance, 39 | const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vulkan_xlib_xrandr.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_XRANDR_H_ 2 | #define VULKAN_XLIB_XRANDR_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_EXT_acquire_xlib_display is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_EXT_acquire_xlib_display 1 24 | #define VK_EXT_ACQUIRE_XLIB_DISPLAY_SPEC_VERSION 1 25 | #define VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME "VK_EXT_acquire_xlib_display" 26 | typedef VkResult (VKAPI_PTR *PFN_vkAcquireXlibDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, VkDisplayKHR display); 27 | typedef VkResult (VKAPI_PTR *PFN_vkGetRandROutputDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, RROutput rrOutput, VkDisplayKHR* pDisplay); 28 | 29 | #ifndef VK_NO_PROTOTYPES 30 | VKAPI_ATTR VkResult VKAPI_CALL vkAcquireXlibDisplayEXT( 31 | VkPhysicalDevice physicalDevice, 32 | Display* dpy, 33 | VkDisplayKHR display); 34 | 35 | VKAPI_ATTR VkResult VKAPI_CALL vkGetRandROutputDisplayEXT( 36 | VkPhysicalDevice physicalDevice, 37 | Display* dpy, 38 | RROutput rrOutput, 39 | VkDisplayKHR* pDisplay); 40 | #endif 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/vi_blend_fields.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | #extension GL_EXT_samplerless_texture_functions : require 24 | 25 | layout(location = 0) out vec4 FragColor; 26 | layout(set = 0, binding = 0) uniform texture2D uImage; 27 | 28 | void main() 29 | { 30 | // A persistent pixel does not propagate more than one frame. 31 | vec4 input_pixel = texelFetch(uImage, ivec2(gl_FragCoord.xy), 0); 32 | FragColor = vec4(input_pixel.rgb * input_pixel.a, 0.0); 33 | } -------------------------------------------------------------------------------- /vulkan/pipeline_event.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "pipeline_event.hpp" 24 | #include "device.hpp" 25 | 26 | namespace Vulkan 27 | { 28 | EventHolder::~EventHolder() 29 | { 30 | if (event) 31 | { 32 | if (internal_sync) 33 | device->destroy_event_nolock(event); 34 | else 35 | device->destroy_event(event); 36 | } 37 | } 38 | 39 | void EventHolderDeleter::operator()(Vulkan::EventHolder *event) 40 | { 41 | event->device->handle_pool.events.free(event); 42 | } 43 | } -------------------------------------------------------------------------------- /vulkan/fence_manager.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "vulkan_headers.hpp" 26 | #include 27 | 28 | namespace Vulkan 29 | { 30 | class Device; 31 | class FenceManager 32 | { 33 | public: 34 | void init(Device *device); 35 | ~FenceManager(); 36 | 37 | VkFence request_cleared_fence(); 38 | void recycle_fence(VkFence fence); 39 | 40 | private: 41 | Device *device = nullptr; 42 | const VolkDeviceTable *table = nullptr; 43 | std::vector fences; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /vulkan/semaphore_manager.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "vulkan_headers.hpp" 26 | #include 27 | 28 | namespace Vulkan 29 | { 30 | class Device; 31 | class SemaphoreManager 32 | { 33 | public: 34 | void init(Device *device); 35 | ~SemaphoreManager(); 36 | 37 | VkSemaphore request_cleared_semaphore(); 38 | void recycle(VkSemaphore semaphore); 39 | 40 | private: 41 | Device *device = nullptr; 42 | const VolkDeviceTable *table = nullptr; 43 | std::vector semaphores; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /util/environment.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace Util 28 | { 29 | bool get_environment(const char *env, std::string &str); 30 | std::string get_environment_string(const char *env, const char *default_value); 31 | unsigned get_environment_uint(const char *env, unsigned default_value); 32 | int get_environment_int(const char *env, int default_value); 33 | bool get_environment_bool(const char *env, bool default_value); 34 | void set_environment(const char *env, const char *value); 35 | } 36 | -------------------------------------------------------------------------------- /util/thread_id.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "thread_id.hpp" 24 | #include "logging.hpp" 25 | 26 | namespace Util 27 | { 28 | static thread_local unsigned thread_id_to_index = ~0u; 29 | 30 | unsigned get_current_thread_index() 31 | { 32 | auto ret = thread_id_to_index; 33 | if (ret == ~0u) 34 | { 35 | LOGE("Thread does not exist in thread manager or is not the main thread.\n"); 36 | return 0; 37 | } 38 | return ret; 39 | } 40 | 41 | void register_thread_index(unsigned index) 42 | { 43 | thread_id_to_index = index; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /vulkan/event_manager.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "vulkan_headers.hpp" 26 | #include 27 | 28 | namespace Vulkan 29 | { 30 | class Device; 31 | class EventManager 32 | { 33 | public: 34 | void init(Device *device); 35 | ~EventManager(); 36 | 37 | VkEvent request_cleared_event(); 38 | void recycle(VkEvent event); 39 | 40 | private: 41 | Device *device = nullptr; 42 | const VolkDeviceTable *table = nullptr; 43 | std::vector events; 44 | uint64_t workaround_counter = 0; 45 | bool workaround = false; 46 | }; 47 | } -------------------------------------------------------------------------------- /parallel-rdp/shaders/clear_write_mask.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | layout(local_size_x_id = 0) in; 25 | layout(constant_id = 1) const int PAGE_STRIDE = 256; 26 | 27 | layout(set = 0, binding = 0, std430) writeonly buffer SSBO 28 | { 29 | uint write_mask[]; 30 | }; 31 | 32 | layout(set = 1, binding = 0, std140) uniform UBO 33 | { 34 | uvec4 offsets[1024]; 35 | }; 36 | 37 | void main() 38 | { 39 | uint offset = offsets[gl_WorkGroupID.x >> 2u][gl_WorkGroupID.x & 3u]; 40 | offset *= PAGE_STRIDE; 41 | write_mask[offset + gl_LocalInvocationIndex] = 0u; 42 | } 43 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/vi_deinterlace.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | layout(location = 0) out vec2 vUV; 25 | 26 | layout(push_constant) uniform UBO 27 | { 28 | float y_offset; 29 | } registers; 30 | 31 | void main() 32 | { 33 | if (gl_VertexIndex == 0) 34 | gl_Position = vec4(-1.0, -1.0, 0.0, 1.0); 35 | else if (gl_VertexIndex == 1) 36 | gl_Position = vec4(-1.0, +3.0, 0.0, 1.0); 37 | else 38 | gl_Position = vec4(+3.0, -1.0, 0.0, 1.0); 39 | 40 | vUV = vec2(gl_Position.x * 0.5 + 0.5, gl_Position.y * 0.5 + 0.5 + registers.y_offset); 41 | } 42 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/load_depth_blend_state.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LOAD_DEPTH_BLEND_STATE_H_ 24 | #define LOAD_DEPTH_BLEND_STATE_H_ 25 | 26 | DepthBlendState load_depth_blend_state(uint index) 27 | { 28 | #if SMALL_TYPES 29 | return depth_blend_state.elems[index]; 30 | #else 31 | return DepthBlendState( 32 | u8x4(depth_blend_state.elems[index].blend_modes0), 33 | u8x4(depth_blend_state.elems[index].blend_modes1), 34 | depth_blend_state.elems[index].flags, 35 | u8(depth_blend_state.elems[index].coverage_mode), 36 | u8(depth_blend_state.elems[index].z_mode), 37 | u8(0), u8(0)); 38 | #endif 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /parallel-rdp/shaders/load_span_setup.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LOAD_SPAN_SETUP_H_ 24 | #define LOAD_SPAN_SETUP_H_ 25 | 26 | SpanSetup load_span_setup(uint index) 27 | { 28 | #if SMALL_TYPES 29 | return span_setups.elems[index]; 30 | #else 31 | return SpanSetup( 32 | span_setups.elems[index].rgba, 33 | span_setups.elems[index].stzw, 34 | u16x4(uvec4(span_setups.elems[index].xleft)), 35 | u16x4(uvec4(span_setups.elems[index].xright)), 36 | span_setups.elems[index].interpolation_base_x, 37 | span_setups.elems[index].start_x, 38 | span_setups.elems[index].end_x, 39 | i16(span_setups.elems[index].lodlength), 40 | u16(span_setups.elems[index].valid_line)); 41 | #endif 42 | } 43 | 44 | #endif -------------------------------------------------------------------------------- /vulkan/cookie.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include "hash.hpp" 27 | #include "intrusive_hash_map.hpp" 28 | 29 | namespace Vulkan 30 | { 31 | class Device; 32 | 33 | class Cookie 34 | { 35 | public: 36 | Cookie(Device *device); 37 | 38 | uint64_t get_cookie() const 39 | { 40 | return cookie; 41 | } 42 | 43 | private: 44 | uint64_t cookie; 45 | }; 46 | 47 | template 48 | using HashedObject = Util::IntrusiveHashMapEnabled; 49 | 50 | class InternalSyncEnabled 51 | { 52 | public: 53 | void set_internal_sync_object() 54 | { 55 | internal_sync = true; 56 | } 57 | 58 | protected: 59 | bool internal_sync = false; 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /util/stack_allocator.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace Util 28 | { 29 | template 30 | class StackAllocator 31 | { 32 | public: 33 | T *allocate(size_t count) 34 | { 35 | if (count == 0) 36 | return nullptr; 37 | if (offset + count > N) 38 | return nullptr; 39 | 40 | T *ret = buffer + offset; 41 | offset += count; 42 | return ret; 43 | } 44 | 45 | T *allocate_cleared(size_t count) 46 | { 47 | T *ret = allocate(count); 48 | if (ret) 49 | std::fill(ret, ret + count, T()); 50 | return ret; 51 | } 52 | 53 | void reset() 54 | { 55 | offset = 0; 56 | } 57 | 58 | private: 59 | T buffer[N]; 60 | size_t offset = 0; 61 | }; 62 | } -------------------------------------------------------------------------------- /util/timer.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace Util 28 | { 29 | class FrameTimer 30 | { 31 | public: 32 | FrameTimer(); 33 | 34 | void reset(); 35 | double frame(); 36 | double frame(double frame_time); 37 | double get_elapsed() const; 38 | double get_frame_time() const; 39 | 40 | void enter_idle(); 41 | void leave_idle(); 42 | 43 | private: 44 | int64_t start; 45 | int64_t last; 46 | int64_t last_period; 47 | int64_t idle_start; 48 | int64_t idle_time = 0; 49 | int64_t get_time(); 50 | }; 51 | 52 | class Timer 53 | { 54 | public: 55 | void start(); 56 | double end(); 57 | 58 | private: 59 | int64_t t = 0; 60 | }; 61 | 62 | int64_t get_current_time_nsecs(); 63 | } -------------------------------------------------------------------------------- /parallel-rdp/shaders/load_static_raster_state.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LOAD_STATIC_RASTER_STATE_H_ 24 | #define LOAD_STATIC_RASTER_STATE_H_ 25 | 26 | StaticRasterizationState load_static_rasterization_state(uint index) 27 | { 28 | #if SMALL_TYPES 29 | return static_raster_state.elems[index]; 30 | #else 31 | return StaticRasterizationState( 32 | u8x4(static_raster_state.elems[index].combiner_inputs_rgb0), 33 | u8x4(static_raster_state.elems[index].combiner_inputs_alpha0), 34 | u8x4(static_raster_state.elems[index].combiner_inputs_rgb1), 35 | u8x4(static_raster_state.elems[index].combiner_inputs_alpha1), 36 | static_raster_state.elems[index].flags, 37 | static_raster_state.elems[index].dither, 38 | 0, 0); 39 | #endif 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /parallel-rdp/shaders/load_triangle_setup.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LOAD_TRIANGLE_SETUP_H_ 24 | #define LOAD_TRIANGLE_SETUP_H_ 25 | 26 | TriangleSetup load_triangle_setup(uint index) 27 | { 28 | #if SMALL_TYPES 29 | return triangle_setup.elems[index]; 30 | #else 31 | return TriangleSetup( 32 | triangle_setup.elems[index].xh, 33 | triangle_setup.elems[index].xm, 34 | triangle_setup.elems[index].xl, 35 | i16(triangle_setup.elems[index].yh), 36 | i16(triangle_setup.elems[index].ym), 37 | triangle_setup.elems[index].dxhdy, 38 | triangle_setup.elems[index].dxmdy, 39 | triangle_setup.elems[index].dxldy, 40 | i16(triangle_setup.elems[index].yl), 41 | u8(triangle_setup.elems[index].flags), 42 | u8(triangle_setup.elems[index].tile)); 43 | #endif 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /parallel-rdp/shaders/store_span_setup.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef STORE_SPAN_SETUP_H_ 24 | #define STORE_SPAN_SETUP_H_ 25 | 26 | void store_span_setup(uint index, SpanSetup setup) 27 | { 28 | #if SMALL_TYPES 29 | span_setups.elems[index] = setup; 30 | #else 31 | span_setups.elems[index].rgba = setup.rgba; 32 | span_setups.elems[index].stzw = setup.stzw; 33 | span_setups.elems[index].xleft = mem_u16x4(uvec4(setup.xleft)); 34 | span_setups.elems[index].xright = mem_u16x4(uvec4(setup.xright)); 35 | span_setups.elems[index].interpolation_base_x = setup.interpolation_base_x; 36 | span_setups.elems[index].start_x = setup.start_x; 37 | span_setups.elems[index].end_x = setup.end_x; 38 | span_setups.elems[index].lodlength = mem_i16(setup.lodlength); 39 | span_setups.elems[index].valid_line = mem_u16(setup.valid_line); 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /parallel-rdp/shaders/load_tile_info.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LOAD_TILE_INFO_H_ 24 | #define LOAD_TILE_INFO_H_ 25 | 26 | TileInfo load_tile_info(uint index) 27 | { 28 | #if SMALL_TYPES 29 | return tile_infos.elems[index]; 30 | #else 31 | return TileInfo( 32 | tile_infos.elems[index].slo, 33 | tile_infos.elems[index].shi, 34 | tile_infos.elems[index].tlo, 35 | tile_infos.elems[index].thi, 36 | tile_infos.elems[index].offset, 37 | tile_infos.elems[index].stride, 38 | u8(tile_infos.elems[index].fmt), 39 | u8(tile_infos.elems[index].size), 40 | u8(tile_infos.elems[index].palette), 41 | u8(tile_infos.elems[index].mask_s), 42 | u8(tile_infos.elems[index].shift_s), 43 | u8(tile_infos.elems[index].mask_t), 44 | u8(tile_infos.elems[index].shift_t), 45 | u8(tile_infos.elems[index].flags)); 46 | #endif 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /vulkan/limits.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | namespace Vulkan 26 | { 27 | constexpr unsigned VULKAN_NUM_DESCRIPTOR_SETS = 4; 28 | constexpr unsigned VULKAN_NUM_DYNAMIC_UBOS = 8; // Vulkan min-spec 29 | constexpr unsigned VULKAN_NUM_BINDINGS = 32; 30 | constexpr unsigned VULKAN_NUM_BINDINGS_BINDLESS_VARYING = 16 * 1024; 31 | constexpr unsigned VULKAN_NUM_ATTACHMENTS = 8; 32 | constexpr unsigned VULKAN_NUM_VERTEX_ATTRIBS = 16; 33 | constexpr unsigned VULKAN_NUM_VERTEX_BUFFERS = 4; 34 | constexpr unsigned VULKAN_PUSH_CONSTANT_SIZE = 128; 35 | constexpr unsigned VULKAN_MAX_UBO_SIZE = 64 * 1024; 36 | constexpr unsigned VULKAN_NUM_USER_SPEC_CONSTANTS = 8; 37 | constexpr unsigned VULKAN_NUM_INTERNAL_SPEC_CONSTANTS = 4; 38 | constexpr unsigned VULKAN_NUM_TOTAL_SPEC_CONSTANTS = 39 | VULKAN_NUM_USER_SPEC_CONSTANTS + VULKAN_NUM_INTERNAL_SPEC_CONSTANTS; 40 | } 41 | -------------------------------------------------------------------------------- /vulkan/quirks.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | namespace Vulkan 26 | { 27 | struct ImplementationQuirks 28 | { 29 | bool instance_deferred_lights = true; 30 | bool merge_subpasses = true; 31 | bool use_transient_color = true; 32 | bool use_transient_depth_stencil = true; 33 | bool queue_wait_on_submission = false; 34 | bool use_async_compute_post = true; 35 | bool render_graph_force_single_queue = false; 36 | bool force_no_subgroups = false; 37 | bool force_no_subgroup_shuffle = false; 38 | bool force_no_subgroup_size_control = false; 39 | 40 | static ImplementationQuirks &get(); 41 | }; 42 | 43 | struct ImplementationWorkarounds 44 | { 45 | bool emulate_event_as_pipeline_barrier = false; 46 | bool broken_pipeline_cache_control = false; 47 | bool force_host_cached = false; 48 | bool force_sync1_access = false; 49 | bool broken_push_descriptors = false; 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /vulkan/fence_manager.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "fence_manager.hpp" 24 | #include "device.hpp" 25 | 26 | namespace Vulkan 27 | { 28 | void FenceManager::init(Device *device_) 29 | { 30 | device = device_; 31 | table = &device->get_device_table(); 32 | } 33 | 34 | VkFence FenceManager::request_cleared_fence() 35 | { 36 | if (!fences.empty()) 37 | { 38 | auto ret = fences.back(); 39 | fences.pop_back(); 40 | return ret; 41 | } 42 | else 43 | { 44 | VkFence fence; 45 | VkFenceCreateInfo info = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO }; 46 | table->vkCreateFence(device->get_device(), &info, nullptr, &fence); 47 | return fence; 48 | } 49 | } 50 | 51 | void FenceManager::recycle_fence(VkFence fence) 52 | { 53 | fences.push_back(fence); 54 | } 55 | 56 | FenceManager::~FenceManager() 57 | { 58 | for (auto &fence : fences) 59 | table->vkDestroyFence(device->get_device(), fence, nullptr); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vulkan_wayland.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_WAYLAND_H_ 2 | #define VULKAN_WAYLAND_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_KHR_wayland_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_KHR_wayland_surface 1 24 | #define VK_KHR_WAYLAND_SURFACE_SPEC_VERSION 6 25 | #define VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "VK_KHR_wayland_surface" 26 | typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; 27 | typedef struct VkWaylandSurfaceCreateInfoKHR { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkWaylandSurfaceCreateFlagsKHR flags; 31 | struct wl_display* display; 32 | struct wl_surface* surface; 33 | } VkWaylandSurfaceCreateInfoKHR; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateWaylandSurfaceKHR)(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct wl_display* display); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR( 40 | VkInstance instance, 41 | const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | struct wl_display* display); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vulkan_xlib.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_H_ 2 | #define VULKAN_XLIB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_KHR_xlib_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_KHR_xlib_surface 1 24 | #define VK_KHR_XLIB_SURFACE_SPEC_VERSION 6 25 | #define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface" 26 | typedef VkFlags VkXlibSurfaceCreateFlagsKHR; 27 | typedef struct VkXlibSurfaceCreateInfoKHR { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkXlibSurfaceCreateFlagsKHR flags; 31 | Display* dpy; 32 | Window window; 33 | } VkXlibSurfaceCreateInfoKHR; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXlibSurfaceKHR)(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR( 40 | VkInstance instance, 41 | const VkXlibSurfaceCreateInfoKHR* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | Display* dpy, 49 | VisualID visualID); 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vulkan.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_H_ 2 | #define VULKAN_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | #include "vk_platform.h" 11 | #include "vulkan_core.h" 12 | 13 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 14 | #include "vulkan_android.h" 15 | #endif 16 | 17 | #ifdef VK_USE_PLATFORM_FUCHSIA 18 | #include 19 | #include "vulkan_fuchsia.h" 20 | #endif 21 | 22 | #ifdef VK_USE_PLATFORM_IOS_MVK 23 | #include "vulkan_ios.h" 24 | #endif 25 | 26 | 27 | #ifdef VK_USE_PLATFORM_MACOS_MVK 28 | #include "vulkan_macos.h" 29 | #endif 30 | 31 | #ifdef VK_USE_PLATFORM_METAL_EXT 32 | #include "vulkan_metal.h" 33 | #endif 34 | 35 | #ifdef VK_USE_PLATFORM_VI_NN 36 | #include "vulkan_vi.h" 37 | #endif 38 | 39 | 40 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 41 | #include "vulkan_wayland.h" 42 | #endif 43 | 44 | 45 | #ifdef VK_USE_PLATFORM_WIN32_KHR 46 | #include 47 | #include "vulkan_win32.h" 48 | #endif 49 | 50 | 51 | #ifdef VK_USE_PLATFORM_XCB_KHR 52 | #include 53 | #include "vulkan_xcb.h" 54 | #endif 55 | 56 | 57 | #ifdef VK_USE_PLATFORM_XLIB_KHR 58 | #include 59 | #include "vulkan_xlib.h" 60 | #endif 61 | 62 | 63 | #ifdef VK_USE_PLATFORM_DIRECTFB_EXT 64 | #include 65 | #include "vulkan_directfb.h" 66 | #endif 67 | 68 | 69 | #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT 70 | #include 71 | #include 72 | #include "vulkan_xlib_xrandr.h" 73 | #endif 74 | 75 | 76 | #ifdef VK_USE_PLATFORM_GGP 77 | #include 78 | #include "vulkan_ggp.h" 79 | #endif 80 | 81 | 82 | #ifdef VK_USE_PLATFORM_SCREEN_QNX 83 | #include 84 | #include "vulkan_screen.h" 85 | #endif 86 | 87 | 88 | #ifdef VK_USE_PLATFORM_SCI 89 | #include 90 | #include 91 | #include "vulkan_sci.h" 92 | #endif 93 | 94 | 95 | #ifdef VK_ENABLE_BETA_EXTENSIONS 96 | #include "vulkan_beta.h" 97 | #endif 98 | 99 | #endif // VULKAN_H_ 100 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vulkan_directfb.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_DIRECTFB_H_ 2 | #define VULKAN_DIRECTFB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_EXT_directfb_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_EXT_directfb_surface 1 24 | #define VK_EXT_DIRECTFB_SURFACE_SPEC_VERSION 1 25 | #define VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME "VK_EXT_directfb_surface" 26 | typedef VkFlags VkDirectFBSurfaceCreateFlagsEXT; 27 | typedef struct VkDirectFBSurfaceCreateInfoEXT { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkDirectFBSurfaceCreateFlagsEXT flags; 31 | IDirectFB* dfb; 32 | IDirectFBSurface* surface; 33 | } VkDirectFBSurfaceCreateInfoEXT; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateDirectFBSurfaceEXT)(VkInstance instance, const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceDirectFBPresentationSupportEXT)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, IDirectFB* dfb); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateDirectFBSurfaceEXT( 40 | VkInstance instance, 41 | const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceDirectFBPresentationSupportEXT( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | IDirectFB* dfb); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vulkan_xcb.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XCB_H_ 2 | #define VULKAN_XCB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_KHR_xcb_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_KHR_xcb_surface 1 24 | #define VK_KHR_XCB_SURFACE_SPEC_VERSION 6 25 | #define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface" 26 | typedef VkFlags VkXcbSurfaceCreateFlagsKHR; 27 | typedef struct VkXcbSurfaceCreateInfoKHR { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkXcbSurfaceCreateFlagsKHR flags; 31 | xcb_connection_t* connection; 32 | xcb_window_t window; 33 | } VkXcbSurfaceCreateInfoKHR; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t* connection, xcb_visualid_t visual_id); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR( 40 | VkInstance instance, 41 | const VkXcbSurfaceCreateInfoKHR* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | xcb_connection_t* connection, 49 | xcb_visualid_t visual_id); 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/z_encode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef Z_ENCODE_H_ 24 | #define Z_ENCODE_H_ 25 | 26 | // The Z compression is kind of clever, and uses inverted FP, with more precision close to 1. 27 | // The compressed Z result is 14 bits, and decompresses to 18-bit UNORM. 28 | int z_decompress(u16 z_) 29 | { 30 | int z = int(z_); 31 | int exponent = z >> 11; 32 | int mantissa = z & 0x7ff; 33 | int shift = max(6 - exponent, 0); 34 | int base = 0x40000 - (0x40000 >> exponent); 35 | return (mantissa << shift) + base; 36 | } 37 | 38 | u16 z_compress(int z) 39 | { 40 | int inv_z = max(0x3ffff - z, 1); 41 | int exponent = 17 - findMSB(inv_z); 42 | exponent = clamp(exponent, 0, 7); 43 | int shift = max(6 - exponent, 0); 44 | int mantissa = (z >> shift) & 0x7ff; 45 | return u16((exponent << 11) + mantissa); 46 | } 47 | 48 | int dz_decompress(int dz) 49 | { 50 | return 1 << dz; 51 | } 52 | 53 | int dz_compress(int dz) 54 | { 55 | return max(findMSB(dz), 0); 56 | } 57 | 58 | #endif -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vulkan_ggp.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_GGP_H_ 2 | #define VULKAN_GGP_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_GGP_stream_descriptor_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_GGP_stream_descriptor_surface 1 24 | #define VK_GGP_STREAM_DESCRIPTOR_SURFACE_SPEC_VERSION 1 25 | #define VK_GGP_STREAM_DESCRIPTOR_SURFACE_EXTENSION_NAME "VK_GGP_stream_descriptor_surface" 26 | typedef VkFlags VkStreamDescriptorSurfaceCreateFlagsGGP; 27 | typedef struct VkStreamDescriptorSurfaceCreateInfoGGP { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkStreamDescriptorSurfaceCreateFlagsGGP flags; 31 | GgpStreamDescriptor streamDescriptor; 32 | } VkStreamDescriptorSurfaceCreateInfoGGP; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateStreamDescriptorSurfaceGGP)(VkInstance instance, const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateStreamDescriptorSurfaceGGP( 38 | VkInstance instance, 39 | const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | 45 | // VK_GGP_frame_token is a preprocessor guard. Do not pass it to API calls. 46 | #define VK_GGP_frame_token 1 47 | #define VK_GGP_FRAME_TOKEN_SPEC_VERSION 1 48 | #define VK_GGP_FRAME_TOKEN_EXTENSION_NAME "VK_GGP_frame_token" 49 | typedef struct VkPresentFrameTokenGGP { 50 | VkStructureType sType; 51 | const void* pNext; 52 | GgpFrameToken frameToken; 53 | } VkPresentFrameTokenGGP; 54 | 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /vulkan/pipeline_event.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "vulkan_headers.hpp" 26 | #include "vulkan_common.hpp" 27 | #include "cookie.hpp" 28 | #include "object_pool.hpp" 29 | 30 | namespace Vulkan 31 | { 32 | class Device; 33 | class EventHolder; 34 | 35 | struct EventHolderDeleter 36 | { 37 | void operator()(EventHolder *event); 38 | }; 39 | 40 | class EventHolder : public Util::IntrusivePtrEnabled, 41 | public InternalSyncEnabled 42 | { 43 | public: 44 | friend struct EventHolderDeleter; 45 | 46 | ~EventHolder(); 47 | 48 | const VkEvent &get_event() const 49 | { 50 | return event; 51 | } 52 | 53 | private: 54 | friend class Util::ObjectPool; 55 | EventHolder(Device *device_, VkEvent event_) 56 | : device(device_) 57 | , event(event_) 58 | { 59 | } 60 | 61 | Device *device; 62 | VkEvent event; 63 | }; 64 | 65 | using PipelineEvent = Util::IntrusivePtr; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /util/thread_name.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "thread_name.hpp" 24 | 25 | #if !defined(_WIN32) 26 | #include 27 | #else 28 | #define WIN32_LEAN_AND_MEAN 29 | #include 30 | #include 31 | #endif 32 | 33 | namespace Util 34 | { 35 | void set_current_thread_name(const char *name) 36 | { 37 | #if defined(__linux__) 38 | pthread_setname_np(pthread_self(), name); 39 | #elif defined(__APPLE__) 40 | pthread_setname_np(name); 41 | #elif defined(_WIN32) 42 | using PFN_SetThreadDescription = HRESULT (WINAPI *)(HANDLE, PCWSTR); 43 | auto module = GetModuleHandleA("kernel32.dll"); 44 | PFN_SetThreadDescription SetThreadDescription = module ? reinterpret_cast( 45 | (void *)GetProcAddress(module, "SetThreadDescription")) : nullptr; 46 | 47 | if (SetThreadDescription) 48 | { 49 | std::wstring wname; 50 | while (*name != '\0') 51 | { 52 | wname.push_back(*name); 53 | name++; 54 | } 55 | SetThreadDescription(GetCurrentThread(), wname.c_str()); 56 | } 57 | #endif 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vk_sdk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_sdk_platform.h 3 | // 4 | /* 5 | * Copyright (c) 2015-2016 The Khronos Group Inc. 6 | * Copyright (c) 2015-2016 Valve Corporation 7 | * Copyright (c) 2015-2016 LunarG, Inc. 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef VK_SDK_PLATFORM_H 23 | #define VK_SDK_PLATFORM_H 24 | 25 | #if defined(_WIN32) 26 | #ifndef NOMINMAX 27 | #define NOMINMAX 28 | #endif 29 | #ifndef __cplusplus 30 | #undef inline 31 | #define inline __inline 32 | #endif // __cplusplus 33 | 34 | #if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) 35 | // C99: 36 | // Microsoft didn't implement C99 in Visual Studio; but started adding it with 37 | // VS2013. However, VS2013 still didn't have snprintf(). The following is a 38 | // work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the 39 | // "CMakeLists.txt" file). 40 | // NOTE: This is fixed in Visual Studio 2015. 41 | #define snprintf _snprintf 42 | #endif 43 | 44 | #define strdup _strdup 45 | 46 | #endif // _WIN32 47 | 48 | // Check for noexcept support using clang, with fallback to Windows or GCC version numbers 49 | #ifndef NOEXCEPT 50 | #if defined(__clang__) 51 | #if __has_feature(cxx_noexcept) 52 | #define HAS_NOEXCEPT 53 | #endif 54 | #else 55 | #if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 56 | #define HAS_NOEXCEPT 57 | #else 58 | #if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026 && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS 59 | #define HAS_NOEXCEPT 60 | #endif 61 | #endif 62 | #endif 63 | 64 | #ifdef HAS_NOEXCEPT 65 | #define NOEXCEPT noexcept 66 | #else 67 | #define NOEXCEPT 68 | #endif 69 | #endif 70 | 71 | #endif // VK_SDK_PLATFORM_H 72 | -------------------------------------------------------------------------------- /parallel-rdp/command_ring.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #ifdef PARALLEL_RDP_SHADER_DIR 31 | #include "global_managers.hpp" 32 | #endif 33 | 34 | namespace RDP 35 | { 36 | class CommandProcessor; 37 | class CommandRing 38 | { 39 | public: 40 | void init( 41 | #ifdef PARALLEL_RDP_SHADER_DIR 42 | Granite::Global::GlobalManagersHandle global_handles, 43 | #endif 44 | CommandProcessor *processor, unsigned count); 45 | ~CommandRing(); 46 | void drain(); 47 | 48 | void enqueue_command(unsigned num_words, const uint32_t *words); 49 | 50 | private: 51 | CommandProcessor *processor = nullptr; 52 | std::thread thr; 53 | std::mutex lock; 54 | std::condition_variable cond; 55 | 56 | std::vector ring; 57 | uint64_t write_count = 0; 58 | uint64_t read_count = 0; 59 | uint64_t completed_count = 0; 60 | 61 | void thread_loop(); 62 | void teardown_thread(); 63 | #ifdef PARALLEL_RDP_SHADER_DIR 64 | Granite::Global::GlobalManagersHandle global_handles; 65 | #endif 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/load_derived_setup.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LOAD_DERIVED_SETUP_H_ 24 | #define LOAD_DERIVED_SETUP_H_ 25 | 26 | DerivedSetup load_derived_setup(uint index) 27 | { 28 | #if SMALL_TYPES 29 | return derived_setup.elems[index]; 30 | #else 31 | return DerivedSetup( 32 | u8x4(derived_setup.elems[index].constant_muladd0), 33 | u8x4(derived_setup.elems[index].constant_mulsub0), 34 | u8x4(derived_setup.elems[index].constant_mul0), 35 | u8x4(derived_setup.elems[index].constant_add0), 36 | u8x4(derived_setup.elems[index].constant_muladd1), 37 | u8x4(derived_setup.elems[index].constant_mulsub1), 38 | u8x4(derived_setup.elems[index].constant_mul1), 39 | u8x4(derived_setup.elems[index].constant_add1), 40 | u8x4(derived_setup.elems[index].fog_color), 41 | u8x4(derived_setup.elems[index].blend_color), 42 | uint(derived_setup.elems[index].fill_color), 43 | u16(derived_setup.elems[index].dz), 44 | u8(derived_setup.elems[index].dz_compressed), 45 | u8(derived_setup.elems[index].min_lod), 46 | i16x4(derived_setup.elems[index].factors)); 47 | #endif 48 | } 49 | 50 | #endif -------------------------------------------------------------------------------- /vulkan/command_pool.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "vulkan_headers.hpp" 26 | #include 27 | #include 28 | 29 | namespace Vulkan 30 | { 31 | class Device; 32 | class CommandPool 33 | { 34 | public: 35 | CommandPool(Device *device, uint32_t queue_family_index); 36 | ~CommandPool(); 37 | 38 | CommandPool(CommandPool &&) noexcept; 39 | CommandPool &operator=(CommandPool &&) noexcept; 40 | CommandPool(const CommandPool &) = delete; 41 | void operator=(const CommandPool &) = delete; 42 | 43 | void begin(); 44 | void trim(); 45 | VkCommandBuffer request_command_buffer(); 46 | VkCommandBuffer request_secondary_command_buffer(); 47 | void signal_submitted(VkCommandBuffer cmd); 48 | 49 | private: 50 | Device *device; 51 | const VolkDeviceTable *table; 52 | VkCommandPool pool = VK_NULL_HANDLE; 53 | std::vector buffers; 54 | std::vector secondary_buffers; 55 | #ifdef VULKAN_DEBUG 56 | std::unordered_set in_flight; 57 | #endif 58 | unsigned index = 0; 59 | unsigned secondary_index = 0; 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/vi_debug.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef VI_DEBUG_H_ 24 | #define VI_DEBUG_H_ 25 | 26 | #if defined(DEBUG_ENABLE) && DEBUG_ENABLE 27 | #include "debug_channel.h" 28 | 29 | void GENERIC_MESSAGE_(int line) 30 | { 31 | add_debug_message(0, uvec3(gl_FragCoord.xy, 0), line); 32 | } 33 | 34 | void GENERIC_MESSAGE_(int line, uint v) 35 | { 36 | add_debug_message(0, uvec3(gl_FragCoord.xy, 0), uvec2(line, v)); 37 | } 38 | 39 | void GENERIC_MESSAGE_(int line, uvec2 v) 40 | { 41 | add_debug_message(0, uvec3(gl_FragCoord.xy, 0), uvec3(line, v)); 42 | } 43 | 44 | void GENERIC_MESSAGE_(int line, uvec3 v) 45 | { 46 | add_debug_message(0, uvec3(gl_FragCoord.xy, 0), uvec4(line, v)); 47 | } 48 | 49 | #define GENERIC_MESSAGE0() GENERIC_MESSAGE_(__LINE__) 50 | #define GENERIC_MESSAGE1(a) GENERIC_MESSAGE_(__LINE__, a) 51 | #define GENERIC_MESSAGE2(a, b) GENERIC_MESSAGE_(__LINE__, uvec2(a, b)) 52 | #define GENERIC_MESSAGE3(a, b, c) GENERIC_MESSAGE_(__LINE__, uvec3(a, b, c)) 53 | #else 54 | #define GENERIC_MESSAGE0() 55 | #define GENERIC_MESSAGE1(a) 56 | #define GENERIC_MESSAGE2(a, b) 57 | #define GENERIC_MESSAGE3(a, b, c) 58 | #endif 59 | 60 | #endif -------------------------------------------------------------------------------- /util/logging.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "logging.hpp" 24 | 25 | #ifdef _WIN32 26 | #define WIN32_LEAN_AND_MEAN 27 | #include 28 | #endif 29 | 30 | namespace Util 31 | { 32 | static thread_local LoggingInterface *logging_iface; 33 | 34 | bool interface_log(const char *tag, const char *fmt, ...) 35 | { 36 | if (!logging_iface) 37 | return false; 38 | 39 | va_list va; 40 | va_start(va, fmt); 41 | bool ret = logging_iface->log(tag, fmt, va); 42 | va_end(va); 43 | return ret; 44 | } 45 | 46 | void set_thread_logging_interface(LoggingInterface *iface) 47 | { 48 | logging_iface = iface; 49 | } 50 | 51 | #ifdef _WIN32 52 | void debug_output_log(const char *tag, const char *fmt, ...) 53 | { 54 | if (!IsDebuggerPresent()) 55 | return; 56 | 57 | va_list va; 58 | va_start(va, fmt); 59 | auto len = vsnprintf(nullptr, 0, fmt, va); 60 | if (len > 0) 61 | { 62 | size_t tag_len = strlen(tag); 63 | char *buf = new char[len + tag_len + 1]; 64 | memcpy(buf, tag, tag_len); 65 | vsnprintf(buf + tag_len, len + 1, fmt, va); 66 | OutputDebugStringA(buf); 67 | delete[] buf; 68 | } 69 | va_end(va); 70 | } 71 | #endif 72 | } -------------------------------------------------------------------------------- /vulkan/semaphore_manager.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "semaphore_manager.hpp" 24 | #include "device.hpp" 25 | 26 | namespace Vulkan 27 | { 28 | void SemaphoreManager::init(Device *device_) 29 | { 30 | device = device_; 31 | table = &device->get_device_table(); 32 | } 33 | 34 | SemaphoreManager::~SemaphoreManager() 35 | { 36 | for (auto &sem : semaphores) 37 | table->vkDestroySemaphore(device->get_device(), sem, nullptr); 38 | } 39 | 40 | void SemaphoreManager::recycle(VkSemaphore sem) 41 | { 42 | if (sem != VK_NULL_HANDLE) 43 | semaphores.push_back(sem); 44 | } 45 | 46 | VkSemaphore SemaphoreManager::request_cleared_semaphore() 47 | { 48 | if (semaphores.empty()) 49 | { 50 | VkSemaphoreCreateInfo info = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO }; 51 | VkSemaphore semaphore; 52 | 53 | if (table->vkCreateSemaphore(device->get_device(), &info, nullptr, &semaphore) != VK_SUCCESS) 54 | { 55 | LOGE("Failed to create semaphore.\n"); 56 | semaphore = VK_NULL_HANDLE; 57 | } 58 | 59 | return semaphore; 60 | } 61 | else 62 | { 63 | auto sem = semaphores.back(); 64 | semaphores.pop_back(); 65 | return sem; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /util/dynamic_array.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "aligned_alloc.hpp" 26 | #include 27 | #include 28 | #include 29 | 30 | namespace Util 31 | { 32 | template 33 | class DynamicArray 34 | { 35 | public: 36 | // Only POD-like types work here since we don't invoke placement new or delete. 37 | static_assert(std::is_trivially_default_constructible::value, "T must be trivially constructible."); 38 | static_assert(std::is_trivially_destructible::value, "T must be trivially destructible."); 39 | 40 | inline void reserve(size_t n) 41 | { 42 | if (n > N) 43 | { 44 | buffer.reset(static_cast(memalign_alloc(std::max(64, alignof(T)), n * sizeof(T)))); 45 | N = n; 46 | } 47 | } 48 | 49 | inline T &operator[](size_t index) { return buffer.get()[index]; } 50 | inline const T &operator[](size_t index) const { return buffer.get()[index]; } 51 | inline T *data() { return buffer.get(); } 52 | inline const T *data() const { return buffer.get(); } 53 | inline size_t get_capacity() const { return N; } 54 | 55 | private: 56 | std::unique_ptr buffer; 57 | size_t N = 0; 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /util/aligned_alloc.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace Util 30 | { 31 | void *memalign_alloc(size_t boundary, size_t size); 32 | void *memalign_calloc(size_t boundary, size_t size); 33 | void memalign_free(void *ptr); 34 | 35 | struct AlignedDeleter { void operator()(void *ptr) { memalign_free(ptr); }}; 36 | 37 | template 38 | struct AlignedAllocation 39 | { 40 | static void *operator new(size_t size) 41 | { 42 | void *ret = ::Util::memalign_alloc(alignof(T), size); 43 | #ifdef __EXCEPTIONS 44 | if (!ret) throw std::bad_alloc(); 45 | #endif 46 | return ret; 47 | } 48 | 49 | static void *operator new[](size_t size) 50 | { 51 | void *ret = ::Util::memalign_alloc(alignof(T), size); 52 | #ifdef __EXCEPTIONS 53 | if (!ret) throw std::bad_alloc(); 54 | #endif 55 | return ret; 56 | } 57 | 58 | static void operator delete(void *ptr) 59 | { 60 | return ::Util::memalign_free(ptr); 61 | } 62 | 63 | static void operator delete[](void *ptr) 64 | { 65 | return ::Util::memalign_free(ptr); 66 | } 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/masked_rdram_resolve.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | layout(local_size_x_id = 0) in; 25 | layout(constant_id = 1) const int PAGE_STRIDE = 256; 26 | 27 | layout(set = 0, binding = 0, std430) buffer RDRAM 28 | { 29 | uint rdram[]; 30 | }; 31 | 32 | layout(set = 0, binding = 1, std430) readonly buffer StagingRDRAM 33 | { 34 | uint staging_rdram[]; 35 | }; 36 | 37 | layout(set = 0, binding = 2, std430) readonly buffer WriteMaskRDRAM 38 | { 39 | uint writemask[]; 40 | }; 41 | 42 | layout(set = 1, binding = 0, std140) uniform UBO 43 | { 44 | uvec4 offsets[1024]; 45 | }; 46 | 47 | void main() 48 | { 49 | uint offset = offsets[gl_WorkGroupID.x >> 2u][gl_WorkGroupID.x & 3u]; 50 | offset *= PAGE_STRIDE; 51 | offset += gl_LocalInvocationIndex; 52 | uint mask = writemask[offset]; 53 | 54 | if (mask == ~0u) 55 | { 56 | return; 57 | } 58 | else if (mask == 0u) 59 | { 60 | uint staging = staging_rdram[offset]; 61 | rdram[offset] = staging; 62 | } 63 | else 64 | { 65 | uint word = rdram[offset]; 66 | uint staging = staging_rdram[offset]; 67 | word = (word & mask) | (staging & ~mask); 68 | rdram[offset] = word; 69 | } 70 | } -------------------------------------------------------------------------------- /vulkan/event_manager.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "event_manager.hpp" 24 | #include "device.hpp" 25 | 26 | namespace Vulkan 27 | { 28 | EventManager::~EventManager() 29 | { 30 | if (!workaround) 31 | for (auto &event : events) 32 | table->vkDestroyEvent(device->get_device(), event, nullptr); 33 | } 34 | 35 | void EventManager::recycle(VkEvent event) 36 | { 37 | if (!workaround && event != VK_NULL_HANDLE) 38 | { 39 | table->vkResetEvent(device->get_device(), event); 40 | events.push_back(event); 41 | } 42 | } 43 | 44 | VkEvent EventManager::request_cleared_event() 45 | { 46 | if (workaround) 47 | { 48 | // Can't use reinterpret_cast because of MSVC. 49 | return (VkEvent) ++workaround_counter; 50 | } 51 | else if (events.empty()) 52 | { 53 | VkEvent event; 54 | VkEventCreateInfo info = { VK_STRUCTURE_TYPE_EVENT_CREATE_INFO }; 55 | table->vkCreateEvent(device->get_device(), &info, nullptr, &event); 56 | return event; 57 | } 58 | else 59 | { 60 | auto event = events.back(); 61 | events.pop_back(); 62 | return event; 63 | } 64 | } 65 | 66 | void EventManager::init(Device *device_) 67 | { 68 | device = device_; 69 | table = &device->get_device_table(); 70 | workaround = device_->get_workarounds().emulate_event_as_pipeline_barrier; 71 | } 72 | } -------------------------------------------------------------------------------- /parallel-rdp/shaders/noise.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef NOISE_H_ 24 | #define NOISE_H_ 25 | 26 | u16 seeded_noise = U16_C(0); 27 | 28 | // From: https://www.shadertoy.com/view/XlXcW4 with slight modifications. 29 | void reseed_noise(uint x, uint y, uint primitive_offset) 30 | { 31 | const uint NOISE_PRIME = 1103515245u; 32 | uvec3 seed = uvec3(x, y, primitive_offset); 33 | seed = ((seed >> 8u) ^ seed.yzx) * NOISE_PRIME; 34 | seed = ((seed >> 8u) ^ seed.yzx) * NOISE_PRIME; 35 | seed = ((seed >> 8u) ^ seed.yzx) * NOISE_PRIME; 36 | seeded_noise = u16(seed.x >> 16u); 37 | } 38 | 39 | i16 noise_get_combiner() 40 | { 41 | return i16(((seeded_noise & U16_C(7u)) << U16_C(6u)) | U16_C(0x20u)); 42 | } 43 | 44 | int noise_get_dither_alpha() 45 | { 46 | return int(seeded_noise & U16_C(7u)); 47 | } 48 | 49 | int noise_get_dither_color() 50 | { 51 | // 3 bits of noise for RGB separately. 52 | return int(seeded_noise & U16_C(0x1ff)); 53 | } 54 | 55 | u8 noise_get_blend_threshold() 56 | { 57 | return u8(seeded_noise & U16_C(0xffu)); 58 | } 59 | 60 | uvec3 noise_get_full_gamma_dither() 61 | { 62 | uint seed = seeded_noise; 63 | return uvec3(seed & 0x3f, (seed >> 6u) & 0x3f, ((seed >> 9u) & 0x38) | (seed & 7u)); 64 | } 65 | 66 | uvec3 noise_get_partial_gamma_dither() 67 | { 68 | return (uvec3(seeded_noise) >> uvec3(0, 1, 2)) & 1u; 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /vulkan/indirect_layout.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "vulkan_headers.hpp" 26 | #include "vulkan_common.hpp" 27 | #include "cookie.hpp" 28 | 29 | namespace Vulkan 30 | { 31 | class Device; 32 | class PipelineLayout; 33 | 34 | struct IndirectLayoutToken 35 | { 36 | enum class Type 37 | { 38 | Invalid = 0, 39 | Shader, 40 | PushConstant, 41 | VBO, 42 | IBO, 43 | Draw, 44 | DrawIndexed, 45 | MeshTasks, 46 | Dispatch 47 | }; 48 | 49 | Type type = Type::Invalid; 50 | uint32_t offset = 0; 51 | 52 | union 53 | { 54 | struct 55 | { 56 | uint32_t offset; 57 | uint32_t range; 58 | const PipelineLayout *layout; 59 | } push; 60 | 61 | struct 62 | { 63 | uint32_t binding; 64 | } vbo; 65 | } data = {}; 66 | }; 67 | 68 | class IndirectLayout : public HashedObject 69 | { 70 | public: 71 | IndirectLayout(Device *device, const IndirectLayoutToken *token, uint32_t num_tokens, uint32_t stride); 72 | ~IndirectLayout(); 73 | 74 | VkIndirectCommandsLayoutNV get_layout() const 75 | { 76 | return layout; 77 | } 78 | 79 | VkPipelineBindPoint get_bind_point() const 80 | { 81 | return bind_point; 82 | } 83 | 84 | private: 85 | friend class Device; 86 | 87 | Device *device; 88 | VkIndirectCommandsLayoutNV layout; 89 | VkPipelineBindPoint bind_point; 90 | }; 91 | } 92 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/vi_status.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef VI_STATUS_H_ 24 | #define VI_STATUS_H_ 25 | 26 | layout(constant_id = 1) const int VI_STATUS = 0; 27 | const int VI_CONTROL_TYPE_BLANK_BIT = 0 << 0; 28 | const int VI_CONTROL_TYPE_RESERVED_BIT = 1 << 0; 29 | const int VI_CONTROL_TYPE_RGBA5551_BIT = 2 << 0; 30 | const int VI_CONTROL_TYPE_RGBA8888_BIT = 3 << 0; 31 | const int VI_CONTROL_TYPE_MASK = 3 << 0; 32 | const int VI_CONTROL_GAMMA_DITHER_ENABLE_BIT = 1 << 2; 33 | const int VI_CONTROL_GAMMA_ENABLE_BIT = 1 << 3; 34 | const int VI_CONTROL_DIVOT_ENABLE_BIT = 1 << 4; 35 | const int VI_CONTROL_SERRATE_BIT = 1 << 6; 36 | const int VI_CONTROL_DITHER_FILTER_ENABLE_BIT = 1 << 16; 37 | const int VI_CONTROL_META_AA_BIT = 1 << 17; 38 | const int VI_CONTROL_META_SCALE_BIT = 1 << 18; 39 | 40 | const bool FMT_RGBA5551 = (VI_STATUS & VI_CONTROL_TYPE_MASK) == VI_CONTROL_TYPE_RGBA5551_BIT; 41 | const bool FMT_RGBA8888 = (VI_STATUS & VI_CONTROL_TYPE_MASK) == VI_CONTROL_TYPE_RGBA8888_BIT; 42 | const bool DITHER_ENABLE = (VI_STATUS & VI_CONTROL_DITHER_FILTER_ENABLE_BIT) != 0; 43 | const bool FETCH_AA = (VI_STATUS & VI_CONTROL_META_AA_BIT) != 0; 44 | const bool SCALE_AA = (VI_STATUS & VI_CONTROL_META_SCALE_BIT) != 0; 45 | const bool GAMMA_ENABLE = (VI_STATUS & VI_CONTROL_GAMMA_ENABLE_BIT) != 0; 46 | const bool GAMMA_DITHER = (VI_STATUS & VI_CONTROL_GAMMA_DITHER_ENABLE_BIT) != 0; 47 | 48 | #endif -------------------------------------------------------------------------------- /parallel-rdp/rdp_dump_write.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace RDP 30 | { 31 | class RDPDumpWriter 32 | { 33 | public: 34 | ~RDPDumpWriter(); 35 | bool init(const char *path, uint32_t dram_size, uint32_t hidden_dram_size); 36 | void flush_dram(const void *dram, uint32_t size); 37 | void flush_hidden_dram(const void *dram, uint32_t size); 38 | void signal_complete(); 39 | void emit_command(uint32_t command, const uint32_t *cmd_data, uint32_t cmd_words); 40 | void set_vi_register(uint32_t vi_register, uint32_t value); 41 | void end_frame(); 42 | 43 | private: 44 | enum RDPDumpCmd : uint32_t 45 | { 46 | RDP_DUMP_CMD_INVALID = 0, 47 | RDP_DUMP_CMD_UPDATE_DRAM = 1, 48 | RDP_DUMP_CMD_RDP_COMMAND = 2, 49 | RDP_DUMP_CMD_SET_VI_REGISTER = 3, 50 | RDP_DUMP_CMD_END_FRAME = 4, 51 | RDP_DUMP_CMD_SIGNAL_COMPLETE = 5, 52 | RDP_DUMP_CMD_EOF = 6, 53 | RDP_DUMP_CMD_UPDATE_DRAM_FLUSH = 7, 54 | RDP_DUMP_CMD_UPDATE_HIDDEN_DRAM = 8, 55 | RDP_DUMP_CMD_UPDATE_HIDDEN_DRAM_FLUSH = 9, 56 | RDP_DUMP_CMD_INT_MAX = 0x7fffffff 57 | }; 58 | 59 | FILE *file = nullptr; 60 | std::vector rdp_dram_cache; 61 | std::vector rdp_hidden_dram_cache; 62 | void flush(const void *dram_, uint32_t size, RDPDumpCmd block_cmd, RDPDumpCmd flush_cmd, uint8_t *cache); 63 | void end(); 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /vulkan/vulkan_headers.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #if defined(_WIN32) && !defined(VK_USE_PLATFORM_WIN32_KHR) 26 | #define VK_USE_PLATFORM_WIN32_KHR 27 | #endif 28 | 29 | #if defined(VULKAN_H_) || defined(VULKAN_CORE_H_) 30 | #error "Must include vulkan_headers.hpp before Vulkan headers" 31 | #endif 32 | 33 | #include "volk.h" 34 | #include 35 | #include "logging.hpp" 36 | #include 37 | 38 | // Workaround silly Xlib headers that define macros for these globally :( 39 | #ifdef None 40 | #undef None 41 | #endif 42 | #ifdef Bool 43 | #undef Bool 44 | #endif 45 | #ifdef Status 46 | #undef Status 47 | #endif 48 | 49 | #ifdef VULKAN_DEBUG 50 | #define VK_ASSERT(x) \ 51 | do \ 52 | { \ 53 | if (!bool(x)) \ 54 | { \ 55 | LOGE("Vulkan error at %s:%d.\n", __FILE__, __LINE__); \ 56 | abort(); \ 57 | } \ 58 | } while (0) 59 | #else 60 | #define VK_ASSERT(x) ((void)0) 61 | #endif 62 | 63 | namespace Vulkan 64 | { 65 | struct NoCopyNoMove 66 | { 67 | NoCopyNoMove() = default; 68 | NoCopyNoMove(const NoCopyNoMove &) = delete; 69 | void operator=(const NoCopyNoMove &) = delete; 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /vulkan/fence.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "vulkan_common.hpp" 26 | #include "vulkan_headers.hpp" 27 | #include "object_pool.hpp" 28 | #include "cookie.hpp" 29 | #include 30 | 31 | namespace Vulkan 32 | { 33 | class Device; 34 | 35 | class FenceHolder; 36 | struct FenceHolderDeleter 37 | { 38 | void operator()(FenceHolder *fence); 39 | }; 40 | 41 | class FenceHolder : public Util::IntrusivePtrEnabled, public InternalSyncEnabled 42 | { 43 | public: 44 | friend struct FenceHolderDeleter; 45 | friend class WSI; 46 | 47 | ~FenceHolder(); 48 | void wait(); 49 | bool wait_timeout(uint64_t nsec); 50 | 51 | private: 52 | friend class Util::ObjectPool; 53 | FenceHolder(Device *device_, VkFence fence_) 54 | : device(device_), 55 | fence(fence_), 56 | timeline_semaphore(VK_NULL_HANDLE), 57 | timeline_value(0) 58 | { 59 | } 60 | 61 | FenceHolder(Device *device_, uint64_t value, VkSemaphore timeline_semaphore_) 62 | : device(device_), 63 | fence(VK_NULL_HANDLE), 64 | timeline_semaphore(timeline_semaphore_), 65 | timeline_value(value) 66 | { 67 | VK_ASSERT(value > 0); 68 | } 69 | 70 | const VkFence &get_fence() const; 71 | 72 | Device *device; 73 | VkFence fence; 74 | VkSemaphore timeline_semaphore; 75 | uint64_t timeline_value; 76 | bool observed_wait = false; 77 | std::mutex lock; 78 | }; 79 | 80 | using Fence = Util::IntrusivePtr; 81 | } 82 | -------------------------------------------------------------------------------- /vulkan/device_fossilize.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "device.hpp" 26 | #include "thread_group.hpp" 27 | 28 | namespace Vulkan 29 | { 30 | struct Device::RecorderState 31 | { 32 | RecorderState(); 33 | ~RecorderState(); 34 | 35 | std::unique_ptr db; 36 | Fossilize::StateRecorder recorder; 37 | std::atomic_bool recorder_ready; 38 | }; 39 | 40 | static constexpr unsigned NumTasks = 4; 41 | struct Device::ReplayerState 42 | { 43 | ReplayerState(); 44 | ~ReplayerState(); 45 | 46 | std::vector module_hashes; 47 | std::vector graphics_hashes; 48 | std::vector compute_hashes; 49 | 50 | Fossilize::StateReplayer base_replayer; 51 | Fossilize::StateReplayer graphics_replayer; 52 | Fossilize::StateReplayer compute_replayer; 53 | Fossilize::FeatureFilter *feature_filter = nullptr; 54 | std::unique_ptr db; 55 | Granite::TaskGroupHandle complete; 56 | Granite::TaskGroupHandle module_ready; 57 | Granite::TaskGroupHandle pipeline_ready; 58 | std::vector> graphics_pipelines; 59 | std::vector> compute_pipelines; 60 | 61 | struct 62 | { 63 | std::atomic_uint32_t pipelines; 64 | std::atomic_uint32_t modules; 65 | std::atomic_uint32_t prepare; 66 | uint32_t num_pipelines = 0; 67 | uint32_t num_modules = 0; 68 | } progress; 69 | }; 70 | } 71 | -------------------------------------------------------------------------------- /vulkan/buffer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "buffer.hpp" 24 | #include "device.hpp" 25 | 26 | namespace Vulkan 27 | { 28 | Buffer::Buffer(Device *device_, VkBuffer buffer_, const DeviceAllocation &alloc_, const BufferCreateInfo &info_, 29 | VkDeviceAddress bda_) 30 | : Cookie(device_) 31 | , device(device_) 32 | , buffer(buffer_) 33 | , alloc(alloc_) 34 | , info(info_) 35 | , bda(bda_) 36 | { 37 | } 38 | 39 | ExternalHandle Buffer::export_handle() 40 | { 41 | return alloc.export_handle(*device); 42 | } 43 | 44 | Buffer::~Buffer() 45 | { 46 | if (internal_sync) 47 | { 48 | device->destroy_buffer_nolock(buffer); 49 | device->free_memory_nolock(alloc); 50 | } 51 | else 52 | { 53 | device->destroy_buffer(buffer); 54 | device->free_memory(alloc); 55 | } 56 | } 57 | 58 | void BufferDeleter::operator()(Buffer *buffer) 59 | { 60 | buffer->device->handle_pool.buffers.free(buffer); 61 | } 62 | 63 | BufferView::BufferView(Device *device_, VkBufferView view_, const BufferViewCreateInfo &create_info_) 64 | : Cookie(device_) 65 | , device(device_) 66 | , view(view_) 67 | , info(create_info_) 68 | { 69 | } 70 | 71 | BufferView::~BufferView() 72 | { 73 | if (view != VK_NULL_HANDLE) 74 | { 75 | if (internal_sync) 76 | device->destroy_buffer_view_nolock(view); 77 | else 78 | device->destroy_buffer_view(view); 79 | } 80 | } 81 | 82 | void BufferViewDeleter::operator()(BufferView *view) 83 | { 84 | view->device->handle_pool.buffer_views.free(view); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /vulkan-headers/include/vk_video/vulkan_video_codec_h265std_decode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 2 | #define VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codec_h265std_decode is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codec_h265std_decode 1 24 | #include "vulkan_video_codec_h265std.h" 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 27 | 28 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_API_VERSION_1_0_0 29 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h265_decode" 30 | #define STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE 8 31 | typedef struct StdVideoDecodeH265PictureInfoFlags { 32 | uint32_t IrapPicFlag : 1; 33 | uint32_t IdrPicFlag : 1; 34 | uint32_t IsReference : 1; 35 | uint32_t short_term_ref_pic_set_sps_flag : 1; 36 | } StdVideoDecodeH265PictureInfoFlags; 37 | 38 | typedef struct StdVideoDecodeH265PictureInfo { 39 | StdVideoDecodeH265PictureInfoFlags flags; 40 | uint8_t sps_video_parameter_set_id; 41 | uint8_t pps_seq_parameter_set_id; 42 | uint8_t pps_pic_parameter_set_id; 43 | uint8_t NumDeltaPocsOfRefRpsIdx; 44 | int32_t PicOrderCntVal; 45 | uint16_t NumBitsForSTRefPicSetInSlice; 46 | uint16_t reserved; 47 | uint8_t RefPicSetStCurrBefore[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 48 | uint8_t RefPicSetStCurrAfter[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 49 | uint8_t RefPicSetLtCurr[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 50 | } StdVideoDecodeH265PictureInfo; 51 | 52 | typedef struct StdVideoDecodeH265ReferenceInfoFlags { 53 | uint32_t used_for_long_term_reference : 1; 54 | uint32_t unused_for_reference : 1; 55 | } StdVideoDecodeH265ReferenceInfoFlags; 56 | 57 | typedef struct StdVideoDecodeH265ReferenceInfo { 58 | StdVideoDecodeH265ReferenceInfoFlags flags; 59 | int32_t PicOrderCntVal; 60 | } StdVideoDecodeH265ReferenceInfo; 61 | 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/clamping.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef CLAMPING_H_ 24 | #define CLAMPING_H_ 25 | 26 | #if SMALL_TYPES && 0 27 | // This path is buggy on RADV LLVM, disable for time being. 28 | i16x4 clamp_9bit_notrunc(i16x4 color) 29 | { 30 | // [-129, -256] should clamp to 0xff, subtracting by 0x80 will underflow back to positive numbers. 31 | // [-128, -1] should clamp to 0. 32 | color -= I16_C(0x80); 33 | // Sign-extend to 9-bit. 34 | color <<= I16_C(7); 35 | color >>= I16_C(7); 36 | color += I16_C(0x80); 37 | return clamp(color, i16x4(0), i16x4(0xff)); 38 | } 39 | #else 40 | i16x4 clamp_9bit_notrunc(ivec4 color) 41 | { 42 | // [-129, -256] should clamp to 0xff, subtracting by 0x80 will underflow back to positive numbers. 43 | // [-128, -1] should clamp to 0. 44 | color -= 0x80; 45 | // Sign-extend to 9-bit. 46 | color = bitfieldExtract(color, 0, 9); 47 | color += 0x80; 48 | return i16x4(clamp(color, ivec4(0), ivec4(0xff))); 49 | } 50 | #endif 51 | 52 | u8x4 clamp_9bit(i16x4 color) 53 | { 54 | return u8x4(clamp_9bit_notrunc(color)); 55 | } 56 | 57 | int clamp_9bit(int color) 58 | { 59 | return clamp(bitfieldExtract(color - 0x80, 0, 9) + 0x80, 0, 0xff); 60 | } 61 | 62 | // Returns 18-bit UNORM depth. 63 | int clamp_z(int z) 64 | { 65 | // Similar to RGBA, we reserve an extra bit to deal with overflow and underflow. 66 | z -= (1 << 17); 67 | z <<= (31 - 18); 68 | z >>= (31 - 18); 69 | z += (1 << 17); 70 | 71 | // [0x00000, 0x3ffff] maps to self. 72 | // [0x40000, 0x5ffff] maps to 0x3ffff. 73 | // [0x60000, 0x7ffff] maps to 0. 74 | 75 | return clamp(z, 0, 0x3ffff); 76 | } 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /util/hash.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | #include 25 | #include 26 | 27 | namespace Util 28 | { 29 | using Hash = uint64_t; 30 | 31 | class Hasher 32 | { 33 | public: 34 | explicit Hasher(Hash h_) 35 | : h(h_) 36 | { 37 | } 38 | 39 | Hasher() = default; 40 | 41 | template 42 | inline void data(const T *data_, size_t size) 43 | { 44 | size /= sizeof(*data_); 45 | for (size_t i = 0; i < size; i++) 46 | h = (h * 0x100000001b3ull) ^ data_[i]; 47 | } 48 | 49 | inline void u32(uint32_t value) 50 | { 51 | h = (h * 0x100000001b3ull) ^ value; 52 | } 53 | 54 | inline void s32(int32_t value) 55 | { 56 | u32(uint32_t(value)); 57 | } 58 | 59 | inline void f32(float value) 60 | { 61 | union 62 | { 63 | float f32; 64 | uint32_t u32; 65 | } u; 66 | u.f32 = value; 67 | u32(u.u32); 68 | } 69 | 70 | inline void u64(uint64_t value) 71 | { 72 | u32(value & 0xffffffffu); 73 | u32(value >> 32); 74 | } 75 | 76 | template 77 | inline void pointer(T *ptr) 78 | { 79 | u64(reinterpret_cast(ptr)); 80 | } 81 | 82 | inline void string(const char *str) 83 | { 84 | char c; 85 | u32(0xff); 86 | while ((c = *str++) != '\0') 87 | u32(uint8_t(c)); 88 | } 89 | 90 | inline void string(const std::string &str) 91 | { 92 | u32(0xff); 93 | for (auto &c : str) 94 | u32(uint8_t(c)); 95 | } 96 | 97 | inline Hash get() const 98 | { 99 | return h; 100 | } 101 | 102 | private: 103 | Hash h = 0xcbf29ce484222325ull; 104 | }; 105 | } 106 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/coverage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef COVERAGE_H_ 24 | #define COVERAGE_H_ 25 | 26 | #include "data_structures.h" 27 | 28 | const int SUBPIXELS_LOG2 = 2; 29 | const int SUBPIXELS = 1 << SUBPIXELS_LOG2; 30 | 31 | u8 compute_coverage(u16x4 xleft, u16x4 xright, int x) 32 | { 33 | u16x4 xshift = u16x4(0, 4, 2, 6) + (u16(x) << U16_C(3)); 34 | bvec4 clip_lo_x01 = lessThan(xshift, xleft.xxyy); 35 | bvec4 clip_lo_x23 = lessThan(xshift, xleft.zzww); 36 | bvec4 clip_hi_x01 = greaterThanEqual(xshift, xright.xxyy); 37 | bvec4 clip_hi_x23 = greaterThanEqual(xshift, xright.zzww); 38 | 39 | u8x4 clip_x0 = u8x4(clip_lo_x01) | u8x4(clip_hi_x01); 40 | u8x4 clip_x1 = u8x4(clip_lo_x23) | u8x4(clip_hi_x23); 41 | u8x4 clip_x = clip_x0 * u8x4(1, 2, 4, 8) + clip_x1 * u8x4(16, 32, 64, 128); 42 | u8 clip_coverage = (clip_x.x | clip_x.y) | (clip_x.z | clip_x.w); 43 | return ~clip_coverage & U8_C(0xff); 44 | } 45 | 46 | const int COVERAGE_CLAMP = 0; 47 | const int COVERAGE_WRAP = 1; 48 | const int COVERAGE_ZAP = 2; 49 | const int COVERAGE_SAVE = 3; 50 | 51 | int blend_coverage(int coverage, int memory_coverage, bool blend_en, int mode) 52 | { 53 | int res = 0; 54 | switch (mode) 55 | { 56 | case COVERAGE_CLAMP: 57 | { 58 | if (blend_en) 59 | res = min(7, memory_coverage + coverage); // image_read_en to read memory coverage, otherwise, it's 7. 60 | else 61 | res = (coverage - 1) & 7; 62 | break; 63 | } 64 | 65 | case COVERAGE_WRAP: 66 | res = (coverage + memory_coverage) & 7; 67 | break; 68 | 69 | case COVERAGE_ZAP: 70 | res = 7; 71 | break; 72 | 73 | case COVERAGE_SAVE: 74 | res = memory_coverage; 75 | break; 76 | } 77 | 78 | return res; 79 | } 80 | 81 | #endif -------------------------------------------------------------------------------- /util/aligned_alloc.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "aligned_alloc.hpp" 24 | #include 25 | #include 26 | #include 27 | #ifdef _WIN32 28 | #include 29 | #endif 30 | 31 | namespace Util 32 | { 33 | void *memalign_alloc(size_t boundary, size_t size) 34 | { 35 | #if defined(_WIN32) 36 | return _aligned_malloc(size, boundary); 37 | #elif defined(_ISOC11_SOURCE) 38 | return aligned_alloc(boundary, (size + boundary - 1) & ~(boundary - 1)); 39 | #elif (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600) 40 | void *ptr = nullptr; 41 | if (posix_memalign(&ptr, boundary, size) < 0) 42 | return nullptr; 43 | return ptr; 44 | #else 45 | // Align stuff ourselves. Kinda ugly, but will work anywhere. 46 | void **place; 47 | uintptr_t addr = 0; 48 | void *ptr = malloc(boundary + size + sizeof(uintptr_t)); 49 | 50 | if (ptr == nullptr) 51 | return nullptr; 52 | 53 | addr = ((uintptr_t)ptr + sizeof(uintptr_t) + boundary) & ~(boundary - 1); 54 | place = (void **) addr; 55 | place[-1] = ptr; 56 | 57 | return (void *) addr; 58 | #endif 59 | } 60 | 61 | void *memalign_calloc(size_t boundary, size_t size) 62 | { 63 | void *ret = memalign_alloc(boundary, size); 64 | if (ret) 65 | memset(ret, 0, size); 66 | return ret; 67 | } 68 | 69 | void memalign_free(void *ptr) 70 | { 71 | #if defined(_WIN32) 72 | _aligned_free(ptr); 73 | #elif !defined(_ISOC11_SOURCE) && !((_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600)) 74 | if (ptr != nullptr) 75 | { 76 | void **p = (void **) ptr; 77 | free(p[-1]); 78 | } 79 | #else 80 | free(ptr); 81 | #endif 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /util/environment.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifdef _WIN32 24 | #define WIN32_LEAN_AND_MEAN 25 | #include 26 | #endif 27 | 28 | #include "environment.hpp" 29 | #include 30 | #include 31 | 32 | namespace Util 33 | { 34 | bool get_environment(const char *env, std::string &str) 35 | { 36 | #ifdef _WIN32 37 | char buf[4096]; 38 | DWORD count = GetEnvironmentVariableA(env, buf, sizeof(buf)); 39 | if (count) 40 | { 41 | str = { buf, buf + count }; 42 | return true; 43 | } 44 | else 45 | return false; 46 | #else 47 | if (const char *v = getenv(env)) 48 | { 49 | str = v; 50 | return true; 51 | } 52 | else 53 | return false; 54 | #endif 55 | } 56 | 57 | void set_environment(const char *env, const char *value) 58 | { 59 | #ifdef _WIN32 60 | SetEnvironmentVariableA(env, value); 61 | #else 62 | setenv(env, value, 1); 63 | #endif 64 | } 65 | 66 | std::string get_environment_string(const char *env, const char *default_value) 67 | { 68 | std::string v; 69 | if (!get_environment(env, v)) 70 | v = default_value; 71 | return v; 72 | } 73 | 74 | unsigned get_environment_uint(const char *env, unsigned default_value) 75 | { 76 | unsigned value = default_value; 77 | std::string v; 78 | if (get_environment(env, v)) 79 | value = unsigned(std::stoul(v)); 80 | return value; 81 | } 82 | 83 | int get_environment_int(const char *env, int default_value) 84 | { 85 | int value = default_value; 86 | std::string v; 87 | if (get_environment(env, v)) 88 | value = int(std::stol(v)); 89 | return value; 90 | } 91 | 92 | bool get_environment_bool(const char *env, bool default_value) 93 | { 94 | return get_environment_int(env, int(default_value)) != 0; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /config.mk: -------------------------------------------------------------------------------- 1 | # For use in standalone implementations. 2 | 3 | PARALLEL_RDP_CFLAGS := 4 | PARALLEL_RDP_CXXFLAGS := 5 | 6 | PARALLEL_RDP_SOURCES_CXX := \ 7 | $(wildcard $(PARALLEL_RDP_IMPLEMENTATION)/parallel-rdp/*.cpp) \ 8 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/buffer.cpp \ 9 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/buffer_pool.cpp \ 10 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/command_buffer.cpp \ 11 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/command_pool.cpp \ 12 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/context.cpp \ 13 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/cookie.cpp \ 14 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/descriptor_set.cpp \ 15 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/device.cpp \ 16 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/event_manager.cpp \ 17 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/fence.cpp \ 18 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/fence_manager.cpp \ 19 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/image.cpp \ 20 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/indirect_layout.cpp \ 21 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/memory_allocator.cpp \ 22 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/pipeline_event.cpp \ 23 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/query_pool.cpp \ 24 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/render_pass.cpp \ 25 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/sampler.cpp \ 26 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/semaphore.cpp \ 27 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/semaphore_manager.cpp \ 28 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/shader.cpp \ 29 | $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/texture/texture_format.cpp \ 30 | $(PARALLEL_RDP_IMPLEMENTATION)/util/arena_allocator.cpp \ 31 | $(PARALLEL_RDP_IMPLEMENTATION)/util/logging.cpp \ 32 | $(PARALLEL_RDP_IMPLEMENTATION)/util/thread_id.cpp \ 33 | $(PARALLEL_RDP_IMPLEMENTATION)/util/aligned_alloc.cpp \ 34 | $(PARALLEL_RDP_IMPLEMENTATION)/util/timer.cpp \ 35 | $(PARALLEL_RDP_IMPLEMENTATION)/util/timeline_trace_file.cpp \ 36 | $(PARALLEL_RDP_IMPLEMENTATION)/util/environment.cpp \ 37 | $(PARALLEL_RDP_IMPLEMENTATION)/util/thread_name.cpp 38 | 39 | PARALLEL_RDP_SOURCES_C := \ 40 | $(PARALLEL_RDP_IMPLEMENTATION)/volk/volk.c 41 | 42 | PARALLEL_RDP_INCLUDE_DIRS := \ 43 | -I$(PARALLEL_RDP_IMPLEMENTATION)/parallel-rdp \ 44 | -I$(PARALLEL_RDP_IMPLEMENTATION)/volk \ 45 | -I$(PARALLEL_RDP_IMPLEMENTATION)/vulkan \ 46 | -I$(PARALLEL_RDP_IMPLEMENTATION)/vulkan-headers/include \ 47 | -I$(PARALLEL_RDP_IMPLEMENTATION)/util 48 | 49 | PARALLEL_RDP_LDFLAGS := -pthread 50 | ifeq (,$(findstring win,$(platform))) 51 | PARALLEL_RDP_LDFLAGS += -ldl 52 | else 53 | PARALLEL_RDP_CFLAGS += -DVK_USE_PLATFORM_WIN32_KHR 54 | PARALLEL_RDP_LDFLAGS += -lwinmm 55 | endif 56 | 57 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/dither.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef DITHER_H_ 24 | #define DITHER_H_ 25 | 26 | const u8 dither_matrices[2][16] = u8[][]( 27 | u8[](U8_C(0), U8_C(6), U8_C(1), U8_C(7), U8_C(4), U8_C(2), U8_C(5), U8_C(3), U8_C(3), U8_C(5), U8_C(2), U8_C(4), U8_C(7), U8_C(1), U8_C(6), U8_C(0)), 28 | u8[](U8_C(0), U8_C(4), U8_C(1), U8_C(5), U8_C(4), U8_C(0), U8_C(5), U8_C(1), U8_C(3), U8_C(7), U8_C(2), U8_C(6), U8_C(7), U8_C(3), U8_C(6), U8_C(2))); 29 | 30 | u8x3 rgb_dither(ivec3 orig_rgb, int dith) 31 | { 32 | ivec3 rgb_dith = (ivec3(dith) >> ivec3(0, 3, 6)) & 7; 33 | ivec3 rgb = mix((orig_rgb & 0xf8) + 8, ivec3(255), greaterThan(orig_rgb, ivec3(247))); 34 | ivec3 replace_sign = (rgb_dith - (orig_rgb & 7)) >> 31; 35 | ivec3 dither_diff = rgb - orig_rgb; 36 | rgb = orig_rgb + (dither_diff & replace_sign); 37 | return u8x3(rgb & 0xff); 38 | } 39 | 40 | void dither_coefficients(int x, int y, int dither_mode_rgb, int dither_mode_alpha, out int rgb_dither, out int alpha_dither) 41 | { 42 | const int DITHER_SPLAT = (1 << 0) | (1 << 3) | (1 << 6); 43 | 44 | if (dither_mode_rgb < 2) 45 | rgb_dither = int(dither_matrices[dither_mode_rgb][(y & 3) * 4 + (x & 3)]) * DITHER_SPLAT; 46 | else if (dither_mode_rgb == 2) 47 | rgb_dither = noise_get_dither_color(); 48 | else 49 | rgb_dither = 0; 50 | 51 | if (dither_mode_alpha == 3) 52 | alpha_dither = 0; 53 | else 54 | { 55 | if (dither_mode_alpha == 2) 56 | { 57 | alpha_dither = noise_get_dither_alpha(); 58 | } 59 | else 60 | { 61 | alpha_dither = dither_mode_rgb >= 2 ? 62 | int(dither_matrices[dither_mode_rgb & 1][(y & 3) * 4 + (x & 3)]) : (rgb_dither & 7); 63 | 64 | if (dither_mode_alpha == 1) 65 | alpha_dither = ~alpha_dither & 7; 66 | } 67 | } 68 | } 69 | 70 | #endif -------------------------------------------------------------------------------- /vulkan-headers/include/vk_video/vulkan_video_codec_h264std_decode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 2 | #define VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codec_h264std_decode is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codec_h264std_decode 1 24 | #include "vulkan_video_codec_h264std.h" 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 27 | 28 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_API_VERSION_1_0_0 29 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h264_decode" 30 | #define STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE 2 31 | 32 | typedef enum StdVideoDecodeH264FieldOrderCount { 33 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_TOP = 0, 34 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_BOTTOM = 1, 35 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_INVALID = 0x7FFFFFFF, 36 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_MAX_ENUM = 0x7FFFFFFF 37 | } StdVideoDecodeH264FieldOrderCount; 38 | typedef struct StdVideoDecodeH264PictureInfoFlags { 39 | uint32_t field_pic_flag : 1; 40 | uint32_t is_intra : 1; 41 | uint32_t IdrPicFlag : 1; 42 | uint32_t bottom_field_flag : 1; 43 | uint32_t is_reference : 1; 44 | uint32_t complementary_field_pair : 1; 45 | } StdVideoDecodeH264PictureInfoFlags; 46 | 47 | typedef struct StdVideoDecodeH264PictureInfo { 48 | StdVideoDecodeH264PictureInfoFlags flags; 49 | uint8_t seq_parameter_set_id; 50 | uint8_t pic_parameter_set_id; 51 | uint8_t reserved1; 52 | uint8_t reserved2; 53 | uint16_t frame_num; 54 | uint16_t idr_pic_id; 55 | int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; 56 | } StdVideoDecodeH264PictureInfo; 57 | 58 | typedef struct StdVideoDecodeH264ReferenceInfoFlags { 59 | uint32_t top_field_flag : 1; 60 | uint32_t bottom_field_flag : 1; 61 | uint32_t used_for_long_term_reference : 1; 62 | uint32_t is_non_existing : 1; 63 | } StdVideoDecodeH264ReferenceInfoFlags; 64 | 65 | typedef struct StdVideoDecodeH264ReferenceInfo { 66 | StdVideoDecodeH264ReferenceInfoFlags flags; 67 | uint16_t FrameNum; 68 | uint16_t reserved; 69 | int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; 70 | } StdVideoDecodeH264ReferenceInfo; 71 | 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /vulkan-headers/include/vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright 2014-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | 11 | #ifndef VK_PLATFORM_H_ 12 | #define VK_PLATFORM_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif // __cplusplus 18 | 19 | /* 20 | *************************************************************************************************** 21 | * Platform-specific directives and type declarations 22 | *************************************************************************************************** 23 | */ 24 | 25 | /* Platform-specific calling convention macros. 26 | * 27 | * Platforms should define these so that Vulkan clients call Vulkan commands 28 | * with the same calling conventions that the Vulkan implementation expects. 29 | * 30 | * VKAPI_ATTR - Placed before the return type in function declarations. 31 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 32 | * VKAPI_CALL - Placed after the return type in function declarations. 33 | * Useful for MSVC-style calling convention syntax. 34 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 35 | * 36 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 37 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 38 | */ 39 | #if defined(_WIN32) 40 | // On Windows, Vulkan commands use the stdcall convention 41 | #define VKAPI_ATTR 42 | #define VKAPI_CALL __stdcall 43 | #define VKAPI_PTR VKAPI_CALL 44 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 45 | #error "Vulkan is not supported for the 'armeabi' NDK ABI" 46 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 47 | // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" 48 | // calling convention, i.e. float parameters are passed in registers. This 49 | // is true even if the rest of the application passes floats on the stack, 50 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 51 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 52 | #define VKAPI_CALL 53 | #define VKAPI_PTR VKAPI_ATTR 54 | #else 55 | // On other platforms, use the default calling convention 56 | #define VKAPI_ATTR 57 | #define VKAPI_CALL 58 | #define VKAPI_PTR 59 | #endif 60 | 61 | #if !defined(VK_NO_STDDEF_H) 62 | #include 63 | #endif // !defined(VK_NO_STDDEF_H) 64 | 65 | #if !defined(VK_NO_STDINT_H) 66 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 67 | typedef signed __int8 int8_t; 68 | typedef unsigned __int8 uint8_t; 69 | typedef signed __int16 int16_t; 70 | typedef unsigned __int16 uint16_t; 71 | typedef signed __int32 int32_t; 72 | typedef unsigned __int32 uint32_t; 73 | typedef signed __int64 int64_t; 74 | typedef unsigned __int64 uint64_t; 75 | #else 76 | #include 77 | #endif 78 | #endif // !defined(VK_NO_STDINT_H) 79 | 80 | #ifdef __cplusplus 81 | } // extern "C" 82 | #endif // __cplusplus 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /vulkan/buffer_pool.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "vulkan_headers.hpp" 26 | #include "intrusive.hpp" 27 | #include 28 | #include 29 | 30 | namespace Vulkan 31 | { 32 | class Device; 33 | class Buffer; 34 | 35 | struct BufferBlockAllocation 36 | { 37 | uint8_t *host; 38 | Util::IntrusivePtr buffer; 39 | VkDeviceSize offset; 40 | VkDeviceSize padded_size; 41 | }; 42 | 43 | class BufferBlock 44 | { 45 | public: 46 | ~BufferBlock(); 47 | 48 | BufferBlockAllocation allocate(VkDeviceSize allocate_size); 49 | inline bool is_mapped() const { return mapped != nullptr; } 50 | const Buffer &get_buffer() const { return *buffer; } 51 | void unmap(Device &device); 52 | 53 | inline VkDeviceSize get_offset() const { return offset; } 54 | inline VkDeviceSize get_size() const { return size; } 55 | 56 | private: 57 | friend class BufferPool; 58 | Util::IntrusivePtr buffer; 59 | VkDeviceSize offset = 0; 60 | VkDeviceSize alignment = 0; 61 | VkDeviceSize size = 0; 62 | VkDeviceSize spill_size = 0; 63 | uint8_t *mapped = nullptr; 64 | }; 65 | 66 | class BufferPool 67 | { 68 | public: 69 | ~BufferPool(); 70 | void init(Device *device, VkDeviceSize block_size, VkDeviceSize alignment, VkBufferUsageFlags usage); 71 | void reset(); 72 | 73 | // Used for allocating UBOs, where we want to specify a fixed size for range, 74 | // and we need to make sure we don't allocate beyond the block. 75 | void set_spill_region_size(VkDeviceSize spill_size); 76 | void set_max_retained_blocks(size_t max_blocks); 77 | 78 | VkDeviceSize get_block_size() const 79 | { 80 | return block_size; 81 | } 82 | 83 | BufferBlock request_block(VkDeviceSize minimum_size); 84 | void recycle_block(BufferBlock &block); 85 | 86 | private: 87 | Device *device = nullptr; 88 | VkDeviceSize block_size = 0; 89 | VkDeviceSize alignment = 0; 90 | VkDeviceSize spill_size = 0; 91 | VkBufferUsageFlags usage = 0; 92 | size_t max_retained_blocks = 0; 93 | std::vector blocks; 94 | BufferBlock allocate_block(VkDeviceSize size); 95 | }; 96 | } -------------------------------------------------------------------------------- /parallel-rdp/shaders/slangmosh.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [ "../../Granite/assets/shaders/inc" ], 3 | "shaders": [ 4 | { 5 | "name": "tmem_update", 6 | "compute": true, 7 | "path": "tmem_update.comp" 8 | }, 9 | { 10 | 11 | "name": "span_setup", 12 | "compute": true, 13 | "path": "span_setup.comp" 14 | }, 15 | { 16 | "name": "clear_indirect_buffer", 17 | "compute": true, 18 | "path": "clear_indirect_buffer.comp" 19 | }, 20 | { 21 | "name": "tile_binning_combined", 22 | "compute": true, 23 | "path": "tile_binning_combined.comp", 24 | "variants": [ 25 | { "define": "SUBGROUP", "count": 2, "resolve": true }, 26 | { "define": "UBERSHADER", "count": 2, "resolve": true }, 27 | { "define": "SMALL_TYPES", "count": 2, "resolve": true } 28 | ] 29 | }, 30 | { 31 | "name": "ubershader", 32 | "path": "ubershader.comp", 33 | "compute": true, 34 | "variants": [ 35 | { "define": "SUBGROUP", "count": 2, "resolve": true }, 36 | { "define": "SMALL_TYPES", "count": 2, "resolve": true } 37 | ] 38 | }, 39 | { 40 | "name": "depth_blend", 41 | "path": "depth_blend.comp", 42 | "compute": true, 43 | "variants": [ 44 | { "define": "SUBGROUP", "count": 2, "resolve": true }, 45 | { "define": "SMALL_TYPES", "count": 2, "resolve": true } 46 | ] 47 | }, 48 | { 49 | "name": "rasterizer", 50 | "path": "rasterizer.comp", 51 | "compute": true, 52 | "variants": [ 53 | { "define": "SMALL_TYPES", "count": 2, "resolve": true } 54 | ] 55 | }, 56 | { 57 | "name": "fullscreen", 58 | "path": "fullscreen.vert" 59 | }, 60 | { 61 | "name": "vi_scale", 62 | "path": "vi_scale.frag" 63 | }, 64 | { 65 | "name": "vi_divot", 66 | "path": "vi_divot.frag", 67 | "variants": [ 68 | { "define": "FETCH_BUG", "count": 2 } 69 | ] 70 | }, 71 | { 72 | "name": "vi_fetch", 73 | "path": "vi_fetch.frag", 74 | "variants": [ 75 | { "define": "FETCH_BUG", "count": 2 } 76 | ] 77 | }, 78 | { 79 | "name": "vi_blend_fields", 80 | "path": "vi_blend_fields.frag" 81 | }, 82 | { 83 | "name": "extract_vram", 84 | "path": "extract_vram.comp", 85 | "compute": true 86 | }, 87 | { 88 | "name": "masked_rdram_resolve", 89 | "path": "masked_rdram_resolve.comp", 90 | "compute": true 91 | }, 92 | { 93 | "name": "clear_write_mask", 94 | "path": "clear_write_mask.comp", 95 | "compute": true 96 | }, 97 | { 98 | "name": "update_upscaled_domain_post", 99 | "path": "update_upscaled_domain_post.comp", 100 | "compute": true 101 | }, 102 | { 103 | "name": "update_upscaled_domain_pre", 104 | "path": "update_upscaled_domain_pre.comp", 105 | "compute": true 106 | }, 107 | { 108 | "name": "update_upscaled_domain_resolve", 109 | "path": "update_upscaled_domain_resolve.comp", 110 | "compute": true 111 | }, 112 | { 113 | "name": "clear_super_sampled_write_mask", 114 | "path": "clear_super_sampled_write_mask.comp", 115 | "compute": true 116 | }, 117 | { 118 | "name": "vi_deinterlace_vert", 119 | "path": "vi_deinterlace.vert" 120 | }, 121 | { 122 | "name": "vi_deinterlace_frag", 123 | "path": "vi_deinterlace.frag" 124 | } 125 | ] 126 | } 127 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/vi_divot.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | #extension GL_EXT_samplerless_texture_functions : require 24 | 25 | #include "vi_debug.h" 26 | 27 | layout(location = 0) out uvec4 FragColor; 28 | #if defined(FETCH_BUG) && FETCH_BUG 29 | layout(location = 1) out uvec4 FragColorFetchBug; 30 | #endif 31 | 32 | layout(set = 0, binding = 0) uniform mediump utexture2DArray uFetchCache; 33 | 34 | void swap(inout uint a, inout uint b) 35 | { 36 | uint tmp = a; 37 | a = b; 38 | b = tmp; 39 | } 40 | 41 | // Workaround Metal using median3. 42 | uint Median3(uint left, uint center, uint right) 43 | { 44 | if (left < center) 45 | swap(left, center); 46 | if (center < right) 47 | swap(center, right); 48 | if (left < center) 49 | swap(left, center); 50 | 51 | return center; 52 | } 53 | 54 | void main() 55 | { 56 | ivec2 pix = ivec2(gl_FragCoord.xy); 57 | 58 | uvec4 left = texelFetch(uFetchCache, ivec3(pix, 0), 0); 59 | uvec4 mid = texelFetchOffset(uFetchCache, ivec3(pix, 0), 0, ivec2(1, 0)); 60 | uvec4 right = texelFetchOffset(uFetchCache, ivec3(pix, 0), 0, ivec2(2, 0)); 61 | 62 | if ((left.a & mid.a & right.a) == 7u) 63 | { 64 | FragColor = mid; 65 | } 66 | else 67 | { 68 | // Median filter. TODO: Optimize with mid3? 69 | uint r = Median3(left.r, mid.r, right.r); 70 | uint g = Median3(left.g, mid.g, right.g); 71 | uint b = Median3(left.b, mid.b, right.b); 72 | FragColor = uvec4(r, g, b, mid.a); 73 | } 74 | 75 | #if defined(FETCH_BUG) && FETCH_BUG 76 | left = texelFetch(uFetchCache, ivec3(pix, 1), 0); 77 | mid = texelFetchOffset(uFetchCache, ivec3(pix, 1), 0, ivec2(1, 0)); 78 | right = texelFetchOffset(uFetchCache, ivec3(pix, 1), 0, ivec2(2, 0)); 79 | 80 | if ((left.a & mid.a & right.a) == 7u) 81 | { 82 | FragColorFetchBug = mid; 83 | } 84 | else 85 | { 86 | // Median filter. TODO: Optimize with mid3? 87 | uint r = Median3(left.r, mid.r, right.r); 88 | uint g = Median3(left.g, mid.g, right.g); 89 | uint b = Median3(left.b, mid.b, right.b); 90 | FragColorFetchBug = uvec4(r, g, b, mid.a); 91 | } 92 | #endif 93 | } 94 | -------------------------------------------------------------------------------- /util/timeline_trace_file.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "object_pool.hpp" 32 | 33 | namespace Util 34 | { 35 | class TimelineTraceFile 36 | { 37 | public: 38 | explicit TimelineTraceFile(const std::string &path); 39 | ~TimelineTraceFile(); 40 | 41 | static void set_tid(const char *tid); 42 | static TimelineTraceFile *get_per_thread(); 43 | static void set_per_thread(TimelineTraceFile *file); 44 | 45 | struct Event 46 | { 47 | char desc[256]; 48 | char tid[32]; 49 | uint32_t pid; 50 | uint64_t start_ns, end_ns; 51 | 52 | void set_desc(const char *desc); 53 | void set_tid(const char *tid); 54 | }; 55 | Event *begin_event(const char *desc, uint32_t pid = 0); 56 | void end_event(Event *e); 57 | 58 | Event *allocate_event(); 59 | void submit_event(Event *e); 60 | 61 | struct ScopedEvent 62 | { 63 | ScopedEvent(TimelineTraceFile *file, const char *tag, uint32_t pid = 0); 64 | ScopedEvent() = default; 65 | ~ScopedEvent(); 66 | void operator=(const ScopedEvent &) = delete; 67 | ScopedEvent(const ScopedEvent &) = delete; 68 | ScopedEvent(ScopedEvent &&other) noexcept; 69 | ScopedEvent &operator=(ScopedEvent &&other) noexcept; 70 | TimelineTraceFile *file = nullptr; 71 | Event *event = nullptr; 72 | }; 73 | 74 | private: 75 | void looper(std::string path); 76 | std::thread thr; 77 | std::mutex lock; 78 | std::condition_variable cond; 79 | 80 | ThreadSafeObjectPool event_pool; 81 | std::queue queued_events; 82 | }; 83 | 84 | #ifndef GRANITE_SHIPPING 85 | 86 | #define GRANITE_MACRO_CONCAT_IMPL(a, b) a##b 87 | #define GRANITE_MACRO_CONCAT(a, b) GRANITE_MACRO_CONCAT_IMPL(a, b) 88 | #define GRANITE_SCOPED_TIMELINE_EVENT(str) \ 89 | ::Util::TimelineTraceFile::ScopedEvent GRANITE_MACRO_CONCAT(_timeline_scoped_count_, __COUNTER__){GRANITE_THREAD_GROUP() ? GRANITE_THREAD_GROUP()->get_timeline_trace_file() : nullptr, str} 90 | #define GRANITE_SCOPED_TIMELINE_EVENT_FILE(file, str) \ 91 | ::Util::TimelineTraceFile::ScopedEvent GRANITE_MACRO_CONCAT(_timeline_scoped_count_, __COUNTER__){file, str} 92 | #else 93 | #define GRANITE_SCOPED_TIMELINE_EVENT(...) ((void)0) 94 | #define GRANITE_SCOPED_TIMELINE_EVENT_FILE(...) ((void)0) 95 | #endif 96 | } 97 | -------------------------------------------------------------------------------- /util/timer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "timer.hpp" 24 | 25 | #ifdef _WIN32 26 | #define WIN32_LEAN_AND_MEAN 27 | #include 28 | #else 29 | #include 30 | #endif 31 | 32 | namespace Util 33 | { 34 | FrameTimer::FrameTimer() 35 | { 36 | reset(); 37 | } 38 | 39 | void FrameTimer::reset() 40 | { 41 | start = get_time(); 42 | last = start; 43 | last_period = 0; 44 | } 45 | 46 | void FrameTimer::enter_idle() 47 | { 48 | idle_start = get_time(); 49 | } 50 | 51 | void FrameTimer::leave_idle() 52 | { 53 | auto idle_end = get_time(); 54 | idle_time += idle_end - idle_start; 55 | } 56 | 57 | double FrameTimer::get_frame_time() const 58 | { 59 | return double(last_period) * 1e-9; 60 | } 61 | 62 | double FrameTimer::frame() 63 | { 64 | auto new_time = get_time() - idle_time; 65 | last_period = new_time - last; 66 | last = new_time; 67 | return double(last_period) * 1e-9; 68 | } 69 | 70 | double FrameTimer::frame(double frame_time) 71 | { 72 | last_period = int64_t(frame_time * 1e9); 73 | last += last_period; 74 | return frame_time; 75 | } 76 | 77 | double FrameTimer::get_elapsed() const 78 | { 79 | return double(last - start) * 1e-9; 80 | } 81 | 82 | int64_t FrameTimer::get_time() 83 | { 84 | return get_current_time_nsecs(); 85 | } 86 | 87 | #ifdef _WIN32 88 | struct QPCFreq 89 | { 90 | QPCFreq() 91 | { 92 | LARGE_INTEGER freq; 93 | QueryPerformanceFrequency(&freq); 94 | inv_freq = 1e9 / double(freq.QuadPart); 95 | } 96 | 97 | double inv_freq; 98 | } static static_qpc_freq; 99 | #endif 100 | 101 | int64_t get_current_time_nsecs() 102 | { 103 | #ifdef _WIN32 104 | LARGE_INTEGER li; 105 | if (!QueryPerformanceCounter(&li)) 106 | return 0; 107 | return int64_t(double(li.QuadPart) * static_qpc_freq.inv_freq); 108 | #else 109 | struct timespec ts = {}; 110 | #if defined(ANDROID) || defined(__FreeBSD__) 111 | constexpr auto timebase = CLOCK_MONOTONIC; 112 | #else 113 | constexpr auto timebase = CLOCK_MONOTONIC_RAW; 114 | #endif 115 | if (clock_gettime(timebase, &ts) < 0) 116 | return 0; 117 | return ts.tv_sec * 1000000000ll + ts.tv_nsec; 118 | #endif 119 | } 120 | 121 | void Timer::start() 122 | { 123 | t = get_current_time_nsecs(); 124 | } 125 | 126 | double Timer::end() 127 | { 128 | auto nt = get_current_time_nsecs(); 129 | return double(nt - t) * 1e-9; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /util/object_pool.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "aligned_alloc.hpp" 31 | 32 | //#define OBJECT_POOL_DEBUG 33 | 34 | namespace Util 35 | { 36 | template 37 | class ObjectPool 38 | { 39 | public: 40 | template 41 | T *allocate(P &&... p) 42 | { 43 | #ifndef OBJECT_POOL_DEBUG 44 | if (vacants.empty()) 45 | { 46 | unsigned num_objects = 64u << memory.size(); 47 | T *ptr = static_cast(memalign_alloc(std::max(64, alignof(T)), 48 | num_objects * sizeof(T))); 49 | if (!ptr) 50 | return nullptr; 51 | 52 | for (unsigned i = 0; i < num_objects; i++) 53 | vacants.push_back(&ptr[i]); 54 | 55 | memory.emplace_back(ptr); 56 | } 57 | 58 | T *ptr = vacants.back(); 59 | vacants.pop_back(); 60 | new(ptr) T(std::forward

(p)...); 61 | return ptr; 62 | #else 63 | return new T(std::forward

(p)...); 64 | #endif 65 | } 66 | 67 | void free(T *ptr) 68 | { 69 | #ifndef OBJECT_POOL_DEBUG 70 | ptr->~T(); 71 | vacants.push_back(ptr); 72 | #else 73 | delete ptr; 74 | #endif 75 | } 76 | 77 | void clear() 78 | { 79 | #ifndef OBJECT_POOL_DEBUG 80 | vacants.clear(); 81 | memory.clear(); 82 | #endif 83 | } 84 | 85 | protected: 86 | #ifndef OBJECT_POOL_DEBUG 87 | std::vector vacants; 88 | 89 | struct MallocDeleter 90 | { 91 | void operator()(T *ptr) 92 | { 93 | memalign_free(ptr); 94 | } 95 | }; 96 | 97 | std::vector> memory; 98 | #endif 99 | }; 100 | 101 | template 102 | class ThreadSafeObjectPool : private ObjectPool 103 | { 104 | public: 105 | template 106 | T *allocate(P &&... p) 107 | { 108 | std::lock_guard holder{lock}; 109 | return ObjectPool::allocate(std::forward

(p)...); 110 | } 111 | 112 | void free(T *ptr) 113 | { 114 | #ifndef OBJECT_POOL_DEBUG 115 | ptr->~T(); 116 | std::lock_guard holder{lock}; 117 | this->vacants.push_back(ptr); 118 | #else 119 | delete ptr; 120 | #endif 121 | } 122 | 123 | void clear() 124 | { 125 | std::lock_guard holder{lock}; 126 | ObjectPool::clear(); 127 | } 128 | 129 | private: 130 | std::mutex lock; 131 | }; 132 | } 133 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/small_types.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | // Utility header to smooth over the difference between 24 | // 8/16-bit integer arithmetic vs. just 8/16-bit storage. 25 | 26 | #ifndef SMALL_INTEGERS_H_ 27 | #define SMALL_INTEGERS_H_ 28 | 29 | #extension GL_EXT_shader_16bit_storage : require 30 | #extension GL_EXT_shader_8bit_storage : require 31 | 32 | #if SMALL_TYPES 33 | #extension GL_EXT_shader_explicit_arithmetic_types_int8 : require 34 | #extension GL_EXT_shader_explicit_arithmetic_types_int16 : require 35 | 36 | #define mem_u8 uint8_t 37 | #define mem_u16 uint16_t 38 | #define mem_u8x2 u8vec2 39 | #define mem_u16x2 u16vec2 40 | #define mem_u8x3 u8vec3 41 | #define mem_u16x3 u16vec3 42 | #define mem_u8x4 u8vec4 43 | #define mem_u16x4 u16vec4 44 | 45 | #define mem_i8 int8_t 46 | #define mem_i16 int16_t 47 | #define mem_i8x2 i8vec2 48 | #define mem_i16x2 i16vec2 49 | #define mem_i8x3 i8vec3 50 | #define mem_i16x3 i16vec3 51 | #define mem_i8x4 i8vec4 52 | #define mem_i16x4 i16vec4 53 | 54 | #define u8 uint8_t 55 | #define u16 uint16_t 56 | #define u8x2 u8vec2 57 | #define u16x2 u16vec2 58 | #define u8x3 u8vec3 59 | #define u16x3 u16vec3 60 | #define u8x4 u8vec4 61 | #define u16x4 u16vec4 62 | 63 | #define i8 int8_t 64 | #define i16 int16_t 65 | #define i8x2 i8vec2 66 | #define i16x2 i16vec2 67 | #define i8x3 i8vec3 68 | #define i16x3 i16vec3 69 | #define i8x4 i8vec4 70 | #define i16x4 i16vec4 71 | 72 | #define U8_C(x) uint8_t(x) 73 | #define I8_C(x) int8_t(x) 74 | #define U16_C(x) uint16_t(x) 75 | #define I16_C(x) int16_t(x) 76 | 77 | #else 78 | 79 | #define mem_u8 uint8_t 80 | #define mem_u16 uint16_t 81 | #define mem_u8x2 u8vec2 82 | #define mem_u16x2 u16vec2 83 | #define mem_u8x3 u8vec3 84 | #define mem_u16x3 u16vec3 85 | #define mem_u8x4 u8vec4 86 | #define mem_u16x4 u16vec4 87 | 88 | #define mem_i8 int8_t 89 | #define mem_i16 int16_t 90 | #define mem_i8x2 i8vec2 91 | #define mem_i16x2 i16vec2 92 | #define mem_i8x3 i8vec3 93 | #define mem_i16x3 i16vec3 94 | #define mem_i8x4 i8vec4 95 | #define mem_i16x4 i16vec4 96 | 97 | #define u8 int 98 | #define u16 int 99 | #define u8x2 ivec2 100 | #define u16x2 ivec2 101 | #define u8x3 ivec3 102 | #define u16x3 ivec3 103 | #define u8x4 ivec4 104 | #define u16x4 ivec4 105 | 106 | #define i8 int 107 | #define i16 int 108 | #define i8x2 ivec2 109 | #define i16x2 ivec2 110 | #define i8x3 ivec3 111 | #define i16x3 ivec3 112 | #define i8x4 ivec4 113 | #define i16x4 ivec4 114 | 115 | #define U8_C(x) int(x) 116 | #define I8_C(x) int(x) 117 | #define U16_C(x) int(x) 118 | #define I16_C(x) int(x) 119 | 120 | #endif 121 | #endif -------------------------------------------------------------------------------- /parallel-rdp/worker_thread.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 Themaister 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "thread_id.hpp" 31 | 32 | #ifdef PARALLEL_RDP_SHADER_DIR 33 | #include "global_managers.hpp" 34 | #endif 35 | 36 | namespace RDP 37 | { 38 | template 39 | class WorkerThread 40 | { 41 | public: 42 | explicit WorkerThread( 43 | #ifdef PARALLEL_RDP_SHADER_DIR 44 | Granite::Global::GlobalManagersHandle globals, 45 | #endif 46 | Executor exec) 47 | : executor(std::move(exec)) 48 | #ifdef PARALLEL_RDP_SHADER_DIR 49 | , handles(std::move(globals)) 50 | #endif 51 | { 52 | thr = std::thread(&WorkerThread::main_loop, this); 53 | } 54 | 55 | ~WorkerThread() 56 | { 57 | if (thr.joinable()) 58 | { 59 | { 60 | std::lock_guard holder{to_thread_mutex}; 61 | work_queue.push({}); 62 | to_thread_cond.notify_one(); 63 | } 64 | thr.join(); 65 | } 66 | } 67 | 68 | template 69 | void wait(Cond &&cond) 70 | { 71 | std::unique_lock holder{to_main_mutex}; 72 | to_main_cond.wait(holder, std::forward(cond)); 73 | } 74 | 75 | void push(T &&t) 76 | { 77 | std::lock_guard holder{to_thread_mutex}; 78 | work_queue.push(std::move(t)); 79 | to_thread_cond.notify_one(); 80 | } 81 | 82 | private: 83 | std::thread thr; 84 | std::mutex to_thread_mutex; 85 | std::condition_variable to_thread_cond; 86 | std::mutex to_main_mutex; 87 | std::condition_variable to_main_cond; 88 | std::queue work_queue; 89 | Executor executor; 90 | 91 | #ifdef PARALLEL_RDP_SHADER_DIR 92 | Granite::Global::GlobalManagersHandle handles; 93 | #endif 94 | 95 | void main_loop() 96 | { 97 | #ifdef PARALLEL_RDP_SHADER_DIR 98 | Granite::Global::set_thread_context(*handles); 99 | handles.reset(); 100 | #endif 101 | 102 | // Avoid benign errors in logging. 103 | // This thread never actually needs the thread ID. 104 | Util::register_thread_index(0); 105 | 106 | for (;;) 107 | { 108 | T value; 109 | 110 | { 111 | std::unique_lock holder{to_thread_mutex}; 112 | to_thread_cond.wait(holder, [this]() { return !work_queue.empty(); }); 113 | value = std::move(work_queue.front()); 114 | work_queue.pop(); 115 | } 116 | 117 | if (executor.is_sentinel(value)) 118 | break; 119 | 120 | executor.perform_work(value); 121 | std::lock_guard holder{to_main_mutex}; 122 | executor.notify_work_locked(value); 123 | to_main_cond.notify_one(); 124 | } 125 | } 126 | }; 127 | } -------------------------------------------------------------------------------- /parallel-rdp/shaders/extract_vram.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | #include "small_types.h" 24 | layout(local_size_x = 16, local_size_y = 8) in; 25 | 26 | // Copies VRAM into a texture which is then consumed by VI scanout. 27 | 28 | layout(set = 0, binding = 0, rgba8ui) uniform writeonly uimage2D uAAInput; 29 | layout(set = 0, binding = 1, std430) readonly buffer RDRAM16 30 | { 31 | mem_u16 elems[]; 32 | } vram16; 33 | 34 | layout(set = 0, binding = 1, std430) readonly buffer RDRAM32 35 | { 36 | uint elems[]; 37 | } vram32; 38 | 39 | layout(set = 0, binding = 2, std430) readonly buffer HiddenRDRAM 40 | { 41 | mem_u8 elems[]; 42 | } hidden_vram; 43 | 44 | layout(push_constant, std430) uniform Registers 45 | { 46 | int fb_offset; 47 | int fb_width; 48 | ivec2 offset; 49 | ivec2 resolution; 50 | } registers; 51 | 52 | layout(constant_id = 0) const int RDRAM_SIZE = 0; 53 | const int RDRAM_MASK_8 = RDRAM_SIZE - 1; 54 | const int RDRAM_MASK_16 = RDRAM_MASK_8 >> 1; 55 | const int RDRAM_MASK_32 = RDRAM_MASK_16 >> 1; 56 | layout(constant_id = 2) const int SCALING_LOG2 = 0; 57 | const int SCALING_FACTOR = 1 << SCALING_LOG2; 58 | 59 | #include "vi_status.h" 60 | 61 | uvec4 fetch_color(ivec2 coord) 62 | { 63 | ivec2 slice2d = coord & (SCALING_FACTOR - 1); 64 | coord >>= SCALING_LOG2; 65 | int slice = slice2d.y * SCALING_FACTOR + slice2d.x; 66 | 67 | uvec4 color; 68 | if (FMT_RGBA8888) 69 | { 70 | int linear_coord = coord.y * registers.fb_width + coord.x + registers.fb_offset; 71 | linear_coord &= RDRAM_MASK_32; 72 | linear_coord += slice * (RDRAM_SIZE >> 2); 73 | uint word = uint(vram32.elems[linear_coord]); 74 | color = (uvec4(word) >> uvec4(24, 16, 8, 5)) & uvec4(0xff, 0xff, 0xff, 7); 75 | } 76 | else if (FMT_RGBA5551) 77 | { 78 | int linear_coord = coord.y * registers.fb_width + coord.x + registers.fb_offset; 79 | linear_coord &= RDRAM_MASK_16; 80 | linear_coord += slice * (RDRAM_SIZE >> 1); 81 | uint word = uint(vram16.elems[linear_coord ^ 1]); 82 | uint hidden_word = uint(hidden_vram.elems[linear_coord]); 83 | 84 | uint r = (word >> 8u) & 0xf8u; 85 | uint g = (word >> 3u) & 0xf8u; 86 | uint b = (word << 2u) & 0xf8u; 87 | uint a = ((word & 1u) << 2u) | hidden_word; 88 | color = uvec4(r, g, b, a); 89 | } 90 | else 91 | color = uvec4(0); 92 | 93 | if (!FETCH_AA) 94 | color.a = 7u; 95 | 96 | return color; 97 | } 98 | 99 | void main() 100 | { 101 | if (any(greaterThanEqual(gl_GlobalInvocationID.xy, registers.resolution))) 102 | return; 103 | 104 | ivec2 coord = ivec2(gl_GlobalInvocationID.xy) + registers.offset; 105 | uvec4 col = fetch_color(coord); 106 | imageStore(uAAInput, ivec2(gl_GlobalInvocationID.xy), col); 107 | } -------------------------------------------------------------------------------- /parallel-rdp/shaders/update_upscaled_domain_post.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "small_types.h" 25 | #include "fb_formats.h" 26 | 27 | layout(local_size_x_id = 3) in; 28 | 29 | layout(constant_id = 0) const int RDRAM_SIZE = 8 * 1024 * 1024; 30 | const int RDRAM_MASK_8 = RDRAM_SIZE - 1; 31 | const int RDRAM_MASK_16 = RDRAM_MASK_8 >> 1; 32 | const int RDRAM_MASK_32 = RDRAM_MASK_8 >> 2; 33 | layout(constant_id = 1) const int FB_SIZE_LOG2 = 0; 34 | layout(constant_id = 2) const bool COLOR_DEPTH_ALIAS = false; 35 | layout(constant_id = 4) const int NUM_SAMPLES = 1; 36 | 37 | layout(push_constant) uniform Registers 38 | { 39 | uint num_pixels, fb_addr, fb_depth_addr; 40 | } registers; 41 | 42 | layout(set = 0, binding = 0) readonly buffer RDRAMSingleSampled8 43 | { 44 | uint8_t elems[]; 45 | } vram8; 46 | 47 | layout(set = 0, binding = 0) readonly buffer RDRAMSingleSampled16 48 | { 49 | uint16_t elems[]; 50 | } vram16; 51 | 52 | layout(set = 0, binding = 0) readonly buffer RDRAMSingleSampled32 53 | { 54 | uint elems[]; 55 | } vram32; 56 | 57 | layout(set = 0, binding = 2) buffer RDRAMUpscalingReference8 58 | { 59 | uint8_t elems[]; 60 | } vram_reference8; 61 | 62 | layout(set = 0, binding = 2) buffer RDRAMUpscalingReference16 63 | { 64 | uint16_t elems[]; 65 | } vram_reference16; 66 | 67 | layout(set = 0, binding = 2) buffer RDRAMUpscalingReference32 68 | { 69 | uint elems[]; 70 | } vram_reference32; 71 | 72 | void copy_rdram_8(uint index) 73 | { 74 | index &= RDRAM_MASK_8; 75 | uint real_word = uint(vram8.elems[index]); 76 | vram_reference8.elems[index] = uint8_t(real_word); 77 | } 78 | 79 | void copy_rdram_16(uint index) 80 | { 81 | index &= RDRAM_MASK_16; 82 | uint real_word = uint(vram16.elems[index]); 83 | vram_reference16.elems[index] = uint16_t(real_word); 84 | } 85 | 86 | void copy_rdram_32(uint index) 87 | { 88 | index &= RDRAM_MASK_32; 89 | uint real_word = vram32.elems[index]; 90 | vram_reference32.elems[index] = real_word; 91 | } 92 | 93 | void main() 94 | { 95 | uint index = gl_GlobalInvocationID.x; 96 | if (index >= registers.num_pixels) 97 | return; 98 | 99 | uint depth_index = index + registers.fb_depth_addr; 100 | uint color_index = index + registers.fb_addr; 101 | 102 | switch (FB_SIZE_LOG2) 103 | { 104 | case 0: 105 | copy_rdram_8(color_index); 106 | break; 107 | 108 | case 1: 109 | copy_rdram_16(color_index); 110 | break; 111 | 112 | case 2: 113 | copy_rdram_32(color_index); 114 | break; 115 | } 116 | 117 | if (!COLOR_DEPTH_ALIAS) 118 | copy_rdram_16(depth_index); 119 | } -------------------------------------------------------------------------------- /util/logging.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace Util 30 | { 31 | class LoggingInterface 32 | { 33 | public: 34 | virtual ~LoggingInterface() = default; 35 | virtual bool log(const char *tag, const char *fmt, va_list va) = 0; 36 | }; 37 | 38 | bool interface_log(const char *tag, const char *fmt, ...); 39 | void set_thread_logging_interface(LoggingInterface *iface); 40 | } 41 | 42 | #if defined(_WIN32) 43 | namespace Util 44 | { 45 | void debug_output_log(const char *tag, const char *fmt, ...); 46 | } 47 | 48 | #define LOGE_FALLBACK(...) do { \ 49 | fprintf(stderr, "[ERROR]: " __VA_ARGS__); \ 50 | fflush(stderr); \ 51 | ::Util::debug_output_log("[ERROR]: ", __VA_ARGS__); \ 52 | } while(false) 53 | 54 | #define LOGW_FALLBACK(...) do { \ 55 | fprintf(stderr, "[WARN]: " __VA_ARGS__); \ 56 | fflush(stderr); \ 57 | ::Util::debug_output_log("[WARN]: ", __VA_ARGS__); \ 58 | } while(false) 59 | 60 | #define LOGI_FALLBACK(...) do { \ 61 | fprintf(stderr, "[INFO]: " __VA_ARGS__); \ 62 | fflush(stderr); \ 63 | ::Util::debug_output_log("[INFO]: ", __VA_ARGS__); \ 64 | } while(false) 65 | #elif defined(ANDROID) 66 | #include 67 | #define LOGE_FALLBACK(...) do { __android_log_print(ANDROID_LOG_ERROR, "Granite", __VA_ARGS__); } while(0) 68 | #define LOGW_FALLBACK(...) do { __android_log_print(ANDROID_LOG_WARN, "Granite", __VA_ARGS__); } while(0) 69 | #define LOGI_FALLBACK(...) do { __android_log_print(ANDROID_LOG_INFO, "Granite", __VA_ARGS__); } while(0) 70 | #else 71 | #define LOGE_FALLBACK(...) \ 72 | do \ 73 | { \ 74 | fprintf(stderr, "[ERROR]: " __VA_ARGS__); \ 75 | fflush(stderr); \ 76 | } while (false) 77 | 78 | #define LOGW_FALLBACK(...) \ 79 | do \ 80 | { \ 81 | fprintf(stderr, "[WARN]: " __VA_ARGS__); \ 82 | fflush(stderr); \ 83 | } while (false) 84 | 85 | #define LOGI_FALLBACK(...) \ 86 | do \ 87 | { \ 88 | fprintf(stderr, "[INFO]: " __VA_ARGS__); \ 89 | fflush(stderr); \ 90 | } while (false) 91 | #endif 92 | 93 | #define LOGE(...) do { if (!::Util::interface_log("[ERROR]: ", __VA_ARGS__)) { LOGE_FALLBACK(__VA_ARGS__); }} while(0) 94 | #define LOGW(...) do { if (!::Util::interface_log("[WARN]: ", __VA_ARGS__)) { LOGW_FALLBACK(__VA_ARGS__); }} while(0) 95 | #define LOGI(...) do { if (!::Util::interface_log("[INFO]: ", __VA_ARGS__)) { LOGI_FALLBACK(__VA_ARGS__); }} while(0) 96 | 97 | -------------------------------------------------------------------------------- /util/read_write_lock.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | #ifdef __SSE2__ 28 | #include 29 | #endif 30 | 31 | namespace Util 32 | { 33 | class RWSpinLock 34 | { 35 | public: 36 | enum { Reader = 2, Writer = 1 }; 37 | RWSpinLock() 38 | { 39 | counter.store(0); 40 | } 41 | 42 | inline void lock_read() 43 | { 44 | unsigned v = counter.fetch_add(Reader, std::memory_order_acquire); 45 | while ((v & Writer) != 0) 46 | { 47 | #ifdef __SSE2__ 48 | _mm_pause(); 49 | #endif 50 | v = counter.load(std::memory_order_acquire); 51 | } 52 | } 53 | 54 | inline bool try_lock_read() 55 | { 56 | unsigned v = counter.fetch_add(Reader, std::memory_order_acquire); 57 | if ((v & Writer) != 0) 58 | { 59 | unlock_read(); 60 | return false; 61 | } 62 | 63 | return true; 64 | } 65 | 66 | inline void unlock_read() 67 | { 68 | counter.fetch_sub(Reader, std::memory_order_release); 69 | } 70 | 71 | inline void lock_write() 72 | { 73 | uint32_t expected = 0; 74 | while (!counter.compare_exchange_weak(expected, Writer, 75 | std::memory_order_acquire, 76 | std::memory_order_relaxed)) 77 | { 78 | #ifdef __SSE2__ 79 | _mm_pause(); 80 | #endif 81 | expected = 0; 82 | } 83 | } 84 | 85 | inline bool try_lock_write() 86 | { 87 | uint32_t expected = 0; 88 | return counter.compare_exchange_strong(expected, Writer, 89 | std::memory_order_acquire, 90 | std::memory_order_relaxed); 91 | } 92 | 93 | inline void unlock_write() 94 | { 95 | counter.fetch_and(~Writer, std::memory_order_release); 96 | } 97 | 98 | inline void promote_reader_to_writer() 99 | { 100 | uint32_t expected = Reader; 101 | if (!counter.compare_exchange_strong(expected, Writer, 102 | std::memory_order_acquire, 103 | std::memory_order_relaxed)) 104 | { 105 | unlock_read(); 106 | lock_write(); 107 | } 108 | } 109 | 110 | private: 111 | std::atomic_uint32_t counter; 112 | }; 113 | 114 | class RWSpinLockReadHolder 115 | { 116 | public: 117 | explicit RWSpinLockReadHolder(RWSpinLock &lock_) 118 | : lock(lock_) 119 | { 120 | lock.lock_read(); 121 | } 122 | 123 | ~RWSpinLockReadHolder() 124 | { 125 | lock.unlock_read(); 126 | } 127 | 128 | private: 129 | RWSpinLock &lock; 130 | }; 131 | 132 | class RWSpinLockWriteHolder 133 | { 134 | public: 135 | explicit RWSpinLockWriteHolder(RWSpinLock &lock_) 136 | : lock(lock_) 137 | { 138 | lock.lock_write(); 139 | } 140 | 141 | ~RWSpinLockWriteHolder() 142 | { 143 | lock.unlock_write(); 144 | } 145 | 146 | private: 147 | RWSpinLock &lock; 148 | }; 149 | } 150 | -------------------------------------------------------------------------------- /vulkan/renderdoc_capture.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "device.hpp" 24 | #include "renderdoc_app.h" 25 | #include 26 | 27 | #ifdef _WIN32 28 | #define WIN32_LEAN_AND_MEAN 29 | #include 30 | #else 31 | #include 32 | #endif 33 | 34 | namespace Vulkan 35 | { 36 | static std::mutex module_lock; 37 | #ifdef _WIN32 38 | static HMODULE renderdoc_module; 39 | #else 40 | static void *renderdoc_module; 41 | #endif 42 | 43 | static RENDERDOC_API_1_0_0 *renderdoc_api; 44 | 45 | bool Device::init_renderdoc_capture() 46 | { 47 | std::lock_guard holder{module_lock}; 48 | if (renderdoc_module) 49 | return true; 50 | 51 | #ifdef _WIN32 52 | renderdoc_module = GetModuleHandleA("renderdoc.dll"); 53 | #elif defined(ANDROID) 54 | renderdoc_module = dlopen("libVkLayer_GLES_RenderDoc.so", RTLD_NOW | RTLD_NOLOAD); 55 | #else 56 | renderdoc_module = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD); 57 | #endif 58 | 59 | if (!renderdoc_module) 60 | { 61 | LOGE("Failed to load RenderDoc, make sure RenderDoc started the application in capture mode.\n"); 62 | return false; 63 | } 64 | 65 | #ifdef _WIN32 66 | // Workaround GCC warning about FARPROC mismatch. 67 | auto *gpa = GetProcAddress(renderdoc_module, "RENDERDOC_GetAPI"); 68 | pRENDERDOC_GetAPI func; 69 | memcpy(&func, &gpa, sizeof(func)); 70 | 71 | if (!func) 72 | { 73 | LOGE("Failed to load RENDERDOC_GetAPI function.\n"); 74 | return false; 75 | } 76 | #else 77 | auto *func = reinterpret_cast(dlsym(renderdoc_module, "RENDERDOC_GetAPI")); 78 | if (!func) 79 | { 80 | LOGE("Failed to load RENDERDOC_GetAPI function.\n"); 81 | return false; 82 | } 83 | #endif 84 | 85 | if (!func(eRENDERDOC_API_Version_1_0_0, reinterpret_cast(&renderdoc_api))) 86 | { 87 | LOGE("Failed to obtain RenderDoc 1.0.0 API.\n"); 88 | return false; 89 | } 90 | else 91 | { 92 | int major, minor, patch; 93 | renderdoc_api->GetAPIVersion(&major, &minor, &patch); 94 | LOGI("Initialized RenderDoc API %d.%d.%d.\n", major, minor, patch); 95 | } 96 | 97 | return true; 98 | } 99 | 100 | void Device::begin_renderdoc_capture() 101 | { 102 | std::lock_guard holder{module_lock}; 103 | if (!renderdoc_api) 104 | { 105 | LOGE("RenderDoc API is not loaded, cannot trigger capture.\n"); 106 | return; 107 | } 108 | next_frame_context(); 109 | 110 | LOGI("Starting RenderDoc frame capture.\n"); 111 | renderdoc_api->StartFrameCapture(nullptr, nullptr); 112 | } 113 | 114 | void Device::end_renderdoc_capture() 115 | { 116 | std::lock_guard holder{module_lock}; 117 | if (!renderdoc_api) 118 | { 119 | LOGE("RenderDoc API is not loaded, cannot trigger capture.\n"); 120 | return; 121 | } 122 | next_frame_context(); 123 | renderdoc_api->EndFrameCapture(nullptr, nullptr); 124 | LOGI("Ended RenderDoc frame capture.\n"); 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /parallel-rdp/shaders/ubershader.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | /* Copyright (c) 2020 Themaister 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | // RIP to any GPU which attempts to execute this monstrosity :) 25 | 26 | #if SUBGROUP 27 | #extension GL_KHR_shader_subgroup_basic : require 28 | #extension GL_KHR_shader_subgroup_vote : require 29 | #extension GL_KHR_shader_subgroup_ballot : require 30 | #extension GL_KHR_shader_subgroup_arithmetic : require 31 | #endif 32 | #include "small_types.h" 33 | 34 | layout(local_size_x_id = 3, local_size_y_id = 4) in; 35 | 36 | #include "debug.h" 37 | #include "data_structures_buffers.h" 38 | 39 | #include "noise.h" 40 | #include "memory_interfacing.h" 41 | #include "shading.h" 42 | 43 | layout(push_constant, std430) uniform Registers 44 | { 45 | uint fb_addr_index; 46 | uint fb_depth_addr_index; 47 | uint fb_width; 48 | uint fb_height; 49 | uint group_mask; 50 | } registers; 51 | 52 | layout(constant_id = 5) const int MAX_PRIMITIVES = 256; 53 | layout(constant_id = 6) const int MAX_WIDTH = 1024; 54 | 55 | const int TILE_BINNING_STRIDE = MAX_PRIMITIVES / 32; 56 | const int MAX_TILES_X = MAX_WIDTH / int(gl_WorkGroupSize.x); 57 | 58 | void main() 59 | { 60 | int x = int(gl_GlobalInvocationID.x); 61 | int y = int(gl_GlobalInvocationID.y); 62 | ivec2 tile = ivec2(gl_WorkGroupID.xy); 63 | 64 | int linear_tile = tile.x + tile.y * MAX_TILES_X; 65 | int linear_tile_base = linear_tile * TILE_BINNING_STRIDE; 66 | 67 | uint coarse_binned = tile_binning_coarse.elems[linear_tile] & registers.group_mask; 68 | if (coarse_binned == 0u) 69 | return; 70 | 71 | init_tile(gl_GlobalInvocationID.xy, 72 | registers.fb_width, registers.fb_height, 73 | registers.fb_addr_index, registers.fb_depth_addr_index); 74 | 75 | while (coarse_binned != 0u) 76 | { 77 | int mask_index = findLSB(coarse_binned); 78 | coarse_binned &= ~uint(1 << mask_index); 79 | 80 | uint binned = tile_binning.elems[linear_tile_base + mask_index]; 81 | while (binned != 0u) 82 | { 83 | int i = findLSB(binned); 84 | binned &= ~uint(1 << i); 85 | uint primitive_index = uint(i + 32 * mask_index); 86 | 87 | ShadedData shaded; 88 | if (shade_pixel(x, y, primitive_index, shaded)) 89 | { 90 | if ((shaded.coverage_count & COVERAGE_FILL_BIT) != 0) 91 | fill_color(derived_setup.elems[primitive_index].fill_color); 92 | else if ((shaded.coverage_count & COVERAGE_COPY_BIT) != 0) 93 | copy_pipeline(shaded.z_dith, primitive_index); 94 | else 95 | depth_blend(x, y, primitive_index, shaded); 96 | } 97 | } 98 | } 99 | 100 | finish_tile(gl_GlobalInvocationID.xy, 101 | registers.fb_width, registers.fb_height, 102 | registers.fb_addr_index, registers.fb_depth_addr_index); 103 | } 104 | -------------------------------------------------------------------------------- /vulkan/type_to_string.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace Vulkan 28 | { 29 | static inline const char *layout_to_string(VkImageLayout layout) 30 | { 31 | switch (layout) 32 | { 33 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: 34 | return "SHADER_READ_ONLY"; 35 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: 36 | return "DS_READ_ONLY"; 37 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: 38 | return "DS"; 39 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: 40 | return "COLOR"; 41 | case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: 42 | return "TRANSFER_DST"; 43 | case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: 44 | return "TRANSFER_SRC"; 45 | case VK_IMAGE_LAYOUT_GENERAL: 46 | return "GENERAL"; 47 | case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: 48 | return "PRESENT"; 49 | default: 50 | return "UNDEFINED"; 51 | } 52 | } 53 | 54 | static inline std::string access_flags_to_string(VkAccessFlags2 flags) 55 | { 56 | std::string result; 57 | 58 | if (flags & VK_ACCESS_SHADER_READ_BIT) 59 | result += "SHADER_READ "; 60 | if (flags & VK_ACCESS_SHADER_WRITE_BIT) 61 | result += "SHADER_WRITE "; 62 | if (flags & VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT) 63 | result += "DS_WRITE "; 64 | if (flags & VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT) 65 | result += "DS_READ "; 66 | if (flags & VK_ACCESS_COLOR_ATTACHMENT_READ_BIT) 67 | result += "COLOR_READ "; 68 | if (flags & VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT) 69 | result += "COLOR_WRITE "; 70 | if (flags & VK_ACCESS_INPUT_ATTACHMENT_READ_BIT) 71 | result += "INPUT_READ "; 72 | if (flags & VK_ACCESS_TRANSFER_WRITE_BIT) 73 | result += "TRANSFER_WRITE "; 74 | if (flags & VK_ACCESS_TRANSFER_READ_BIT) 75 | result += "TRANSFER_READ "; 76 | if (flags & VK_ACCESS_UNIFORM_READ_BIT) 77 | result += "UNIFORM_READ "; 78 | 79 | if (!result.empty()) 80 | result.pop_back(); 81 | else 82 | result = "NONE"; 83 | 84 | return result; 85 | } 86 | 87 | static inline std::string stage_flags_to_string(VkPipelineStageFlags2 flags) 88 | { 89 | std::string result; 90 | 91 | if (flags & VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT) 92 | result += "GRAPHICS "; 93 | if (flags & (VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT)) 94 | result += "DEPTH "; 95 | if (flags & VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT) 96 | result += "COLOR "; 97 | if (flags & VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT) 98 | result += "FRAGMENT "; 99 | if (flags & VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT) 100 | result += "COMPUTE "; 101 | if (flags & VK_PIPELINE_STAGE_TRANSFER_BIT) 102 | result += "TRANSFER "; 103 | if (flags & (VK_PIPELINE_STAGE_VERTEX_INPUT_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT)) 104 | result += "VERTEX "; 105 | 106 | if (!result.empty()) 107 | result.pop_back(); 108 | else 109 | result = "NONE"; 110 | 111 | return result; 112 | } 113 | } -------------------------------------------------------------------------------- /vulkan/vulkan_common.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "intrusive.hpp" 26 | #include "object_pool.hpp" 27 | #include "intrusive_hash_map.hpp" 28 | #include "vulkan_headers.hpp" 29 | 30 | namespace Vulkan 31 | { 32 | using HandleCounter = Util::MultiThreadCounter; 33 | 34 | template 35 | using VulkanObjectPool = Util::ThreadSafeObjectPool; 36 | template 37 | using VulkanCache = Util::ThreadSafeIntrusiveHashMapReadCached; 38 | template 39 | using VulkanCacheReadWrite = Util::ThreadSafeIntrusiveHashMap; 40 | 41 | enum QueueIndices 42 | { 43 | QUEUE_INDEX_GRAPHICS, 44 | QUEUE_INDEX_COMPUTE, 45 | QUEUE_INDEX_TRANSFER, 46 | QUEUE_INDEX_VIDEO_DECODE, 47 | QUEUE_INDEX_VIDEO_ENCODE, 48 | QUEUE_INDEX_COUNT 49 | }; 50 | 51 | struct ExternalHandle 52 | { 53 | #ifdef _WIN32 54 | using NativeHandle = void *; 55 | NativeHandle handle = nullptr; 56 | #else 57 | using NativeHandle = int; 58 | NativeHandle handle = -1; 59 | #endif 60 | 61 | VkExternalMemoryHandleTypeFlagBits memory_handle_type = get_opaque_memory_handle_type(); 62 | VkExternalSemaphoreHandleTypeFlagBits semaphore_handle_type = get_opaque_semaphore_handle_type(); 63 | 64 | constexpr static VkExternalMemoryHandleTypeFlagBits get_opaque_memory_handle_type() 65 | { 66 | #ifdef _WIN32 67 | return VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT; 68 | #else 69 | return VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT; 70 | #endif 71 | } 72 | 73 | constexpr static VkExternalSemaphoreHandleTypeFlagBits get_opaque_semaphore_handle_type() 74 | { 75 | #ifdef _WIN32 76 | return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT; 77 | #else 78 | return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT; 79 | #endif 80 | } 81 | 82 | inline explicit operator bool() const 83 | { 84 | #ifdef _WIN32 85 | return handle != nullptr; 86 | #else 87 | return handle >= 0; 88 | #endif 89 | } 90 | 91 | static bool memory_handle_type_imports_by_reference(VkExternalMemoryHandleTypeFlagBits type) 92 | { 93 | VK_ASSERT(type == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT || 94 | type == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT || 95 | type == VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT || 96 | type == VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT || 97 | type == VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT); 98 | return type != VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT; 99 | } 100 | 101 | static bool semaphore_handle_type_imports_by_reference(VkExternalSemaphoreHandleTypeFlagBits type) 102 | { 103 | VK_ASSERT(type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT || 104 | type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT || 105 | type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT); 106 | 107 | // D3D11 fence aliases D3D12 fence. It's basically the same thing, just D3D11.3. 108 | return type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT; 109 | } 110 | }; 111 | } 112 | -------------------------------------------------------------------------------- /vulkan/fence.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2023 Hans-Kristian Arntzen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining 4 | * a copy of this software and associated documentation files (the 5 | * "Software"), to deal in the Software without restriction, including 6 | * without limitation the rights to use, copy, modify, merge, publish, 7 | * distribute, sublicense, and/or sell copies of the Software, and to 8 | * permit persons to whom the Software is furnished to do so, subject to 9 | * the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be 12 | * included in all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "fence.hpp" 24 | #include "device.hpp" 25 | 26 | namespace Vulkan 27 | { 28 | FenceHolder::~FenceHolder() 29 | { 30 | if (fence != VK_NULL_HANDLE) 31 | { 32 | if (internal_sync) 33 | device->reset_fence_nolock(fence, observed_wait); 34 | else 35 | device->reset_fence(fence, observed_wait); 36 | } 37 | } 38 | 39 | const VkFence &FenceHolder::get_fence() const 40 | { 41 | return fence; 42 | } 43 | 44 | void FenceHolder::wait() 45 | { 46 | auto &table = device->get_device_table(); 47 | 48 | // Waiting for the same VkFence in parallel is not allowed, and there seems to be some shenanigans on Intel 49 | // when waiting for a timeline semaphore in parallel with same value as well. 50 | std::lock_guard holder{lock}; 51 | 52 | if (observed_wait) 53 | return; 54 | 55 | if (timeline_value != 0) 56 | { 57 | VK_ASSERT(timeline_semaphore); 58 | VkSemaphoreWaitInfo info = { VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO }; 59 | info.semaphoreCount = 1; 60 | info.pSemaphores = &timeline_semaphore; 61 | info.pValues = &timeline_value; 62 | if (table.vkWaitSemaphores(device->get_device(), &info, UINT64_MAX) != VK_SUCCESS) 63 | LOGE("Failed to wait for timeline semaphore!\n"); 64 | else 65 | observed_wait = true; 66 | } 67 | else 68 | { 69 | if (table.vkWaitForFences(device->get_device(), 1, &fence, VK_TRUE, UINT64_MAX) != VK_SUCCESS) 70 | LOGE("Failed to wait for fence!\n"); 71 | else 72 | observed_wait = true; 73 | } 74 | } 75 | 76 | bool FenceHolder::wait_timeout(uint64_t timeout) 77 | { 78 | bool ret; 79 | auto &table = device->get_device_table(); 80 | 81 | // Waiting for the same VkFence in parallel is not allowed, and there seems to be some shenanigans on Intel 82 | // when waiting for a timeline semaphore in parallel with same value as well. 83 | std::lock_guard holder{lock}; 84 | 85 | if (observed_wait) 86 | return true; 87 | 88 | if (timeline_value != 0) 89 | { 90 | VK_ASSERT(timeline_semaphore); 91 | 92 | if (timeout == 0) 93 | { 94 | uint64_t current_value = 0; 95 | ret = table.vkGetSemaphoreCounterValue(device->get_device(), timeline_semaphore, ¤t_value) == VK_SUCCESS && 96 | current_value >= timeline_value; 97 | } 98 | else 99 | { 100 | VkSemaphoreWaitInfo info = {VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO}; 101 | info.semaphoreCount = 1; 102 | info.pSemaphores = &timeline_semaphore; 103 | info.pValues = &timeline_value; 104 | ret = table.vkWaitSemaphores(device->get_device(), &info, timeout) == VK_SUCCESS; 105 | } 106 | } 107 | else 108 | { 109 | if (timeout == 0) 110 | ret = table.vkGetFenceStatus(device->get_device(), fence) == VK_SUCCESS; 111 | else 112 | ret = table.vkWaitForFences(device->get_device(), 1, &fence, VK_TRUE, timeout) == VK_SUCCESS; 113 | } 114 | 115 | if (ret) 116 | observed_wait = true; 117 | return ret; 118 | } 119 | 120 | void FenceHolderDeleter::operator()(Vulkan::FenceHolder *fence) 121 | { 122 | fence->device->handle_pool.fences.free(fence); 123 | } 124 | } 125 | --------------------------------------------------------------------------------