diff options
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/gles3/shaders/stdlib_inc.glsl | 18 | ||||
| -rw-r--r-- | drivers/gles3/storage/mesh_storage.cpp | 1 | ||||
| -rw-r--r-- | drivers/gles3/storage/texture_storage.cpp | 22 | ||||
| -rw-r--r-- | drivers/metal/rendering_context_driver_metal.h | 145 | ||||
| -rw-r--r-- | drivers/metal/rendering_context_driver_metal.mm | 99 | ||||
| -rw-r--r-- | drivers/unix/file_access_unix.cpp | 93 | ||||
| -rw-r--r-- | drivers/unix/file_access_unix.h | 8 | ||||
| -rw-r--r-- | drivers/unix/file_access_unix_pipe.cpp | 25 | ||||
| -rw-r--r-- | drivers/unix/file_access_unix_pipe.h | 2 | ||||
| -rw-r--r-- | drivers/vulkan/rendering_device_driver_vulkan.cpp | 11 | ||||
| -rw-r--r-- | drivers/windows/file_access_windows.cpp | 165 | ||||
| -rw-r--r-- | drivers/windows/file_access_windows.h | 8 | ||||
| -rw-r--r-- | drivers/windows/file_access_windows_pipe.cpp | 24 | ||||
| -rw-r--r-- | drivers/windows/file_access_windows_pipe.h | 2 |
14 files changed, 192 insertions, 431 deletions
diff --git a/drivers/gles3/shaders/stdlib_inc.glsl b/drivers/gles3/shaders/stdlib_inc.glsl index 029084c34c..f88c218506 100644 --- a/drivers/gles3/shaders/stdlib_inc.glsl +++ b/drivers/gles3/shaders/stdlib_inc.glsl @@ -9,19 +9,17 @@ // Floating point pack/unpack functions are part of the GLSL ES 300 specification used by web and mobile. uint float2half(uint f) { - uint e = f & uint(0x7f800000); - if (e <= uint(0x38000000)) { - return uint(0); - } else { - return ((f >> uint(16)) & uint(0x8000)) | - (((e - uint(0x38000000)) >> uint(13)) & uint(0x7c00)) | - ((f >> uint(13)) & uint(0x03ff)); - } + uint b = f + uint(0x00001000); + uint e = (b & uint(0x7F800000)) >> 23; + uint m = b & uint(0x007FFFFF); + return (b & uint(0x80000000)) >> uint(16) | uint(e > uint(112)) * ((((e - uint(112)) << uint(10)) & uint(0x7C00)) | m >> uint(13)) | (uint(e < uint(113)) & uint(e > uint(101))) * ((((uint(0x007FF000) + m) >> (uint(125) - e)) + uint(1)) >> uint(1)) | uint(e > uint(143)) * uint(0x7FFF); } uint half2float(uint h) { - uint h_e = h & uint(0x7c00); - return ((h & uint(0x8000)) << uint(16)) | uint((h_e >> uint(10)) != uint(0)) * (((h_e + uint(0x1c000)) << uint(13)) | ((h & uint(0x03ff)) << uint(13))); + uint e = (h & uint(0x7C00)) >> uint(10); + uint m = (h & uint(0x03FF)) << uint(13); + uint v = m >> uint(23); + return (h & uint(0x8000)) << uint(16) | uint(e != uint(0)) * ((e + uint(112)) << uint(23) | m) | (uint(e == uint(0)) & uint(m != uint(0))) * ((v - uint(37)) << uint(23) | ((m << (uint(150) - v)) & uint(0x007FE000))); } uint godot_packHalf2x16(vec2 v) { diff --git a/drivers/gles3/storage/mesh_storage.cpp b/drivers/gles3/storage/mesh_storage.cpp index b55a2e0a8a..de82d74aff 100644 --- a/drivers/gles3/storage/mesh_storage.cpp +++ b/drivers/gles3/storage/mesh_storage.cpp @@ -743,6 +743,7 @@ String MeshStorage::mesh_get_path(RID p_mesh) const { } void MeshStorage::mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) { + ERR_FAIL_COND_MSG(p_mesh == p_shadow_mesh, "Cannot set a mesh as its own shadow mesh."); Mesh *mesh = mesh_owner.get_or_null(p_mesh); ERR_FAIL_NULL(mesh); diff --git a/drivers/gles3/storage/texture_storage.cpp b/drivers/gles3/storage/texture_storage.cpp index 57fe96fb6f..36393dde86 100644 --- a/drivers/gles3/storage/texture_storage.cpp +++ b/drivers/gles3/storage/texture_storage.cpp @@ -1389,8 +1389,22 @@ void TextureStorage::texture_debug_usage(List<RS::TextureInfo> *r_info) { tinfo.format = t->format; tinfo.width = t->alloc_width; tinfo.height = t->alloc_height; - tinfo.depth = t->depth; tinfo.bytes = t->total_data_size; + + switch (t->type) { + case Texture::TYPE_3D: + tinfo.depth = t->depth; + break; + + case Texture::TYPE_LAYERED: + tinfo.depth = t->layers; + break; + + default: + tinfo.depth = 0; + break; + } + r_info->push_back(tinfo); } } @@ -1521,7 +1535,11 @@ void TextureStorage::_texture_set_data(RID p_texture, const Ref<Image> &p_image, h = MAX(1, h >> 1); } - texture->total_data_size = tsize; + if (texture->target == GL_TEXTURE_CUBE_MAP || texture->target == GL_TEXTURE_2D_ARRAY) { + texture->total_data_size = tsize * texture->layers; + } else { + texture->total_data_size = tsize; + } texture->stored_cube_sides |= (1 << p_layer); diff --git a/drivers/metal/rendering_context_driver_metal.h b/drivers/metal/rendering_context_driver_metal.h index 0363ab111a..7e0b09186d 100644 --- a/drivers/metal/rendering_context_driver_metal.h +++ b/drivers/metal/rendering_context_driver_metal.h @@ -33,22 +33,36 @@ #ifdef METAL_ENABLED -#import "rendering_device_driver_metal.h" - #import "servers/rendering/rendering_context_driver.h" +#import "servers/rendering/rendering_device_driver.h" #import <CoreGraphics/CGGeometry.h> + +#ifdef __OBJC__ +#import "metal_objects.h" + #import <Metal/Metal.h> #import <QuartzCore/CALayer.h> @class CAMetalLayer; @protocol CAMetalDrawable; +#else +typedef enum MTLPixelFormat { + MTLPixelFormatBGRA8Unorm = 80, +} MTLPixelFormat; +class MDCommandBuffer; +#endif + class PixelFormats; class MDResourceCache; class API_AVAILABLE(macos(11.0), ios(14.0)) RenderingContextDriverMetal : public RenderingContextDriver { protected: - id<MTLDevice> metal_device = nil; +#ifdef __OBJC__ + id<MTLDevice> metal_device = nullptr; +#else + void *metal_device = nullptr; +#endif Device device; // There is only one device on Apple Silicon. public: @@ -73,12 +87,20 @@ public: // Platform-specific data for the Windows embedded in this driver. struct WindowPlatformData { +#ifdef __OBJC__ CAMetalLayer *__unsafe_unretained layer; +#else + void *layer; +#endif }; - class Surface { + class API_AVAILABLE(macos(11.0), ios(14.0)) Surface { protected: +#ifdef __OBJC__ id<MTLDevice> device; +#else + void *device; +#endif public: uint32_t width = 0; @@ -86,8 +108,15 @@ public: DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED; bool needs_resize = false; - Surface(id<MTLDevice> p_device) : - device(p_device) {} + Surface( +#ifdef __OBJC__ + id<MTLDevice> p_device +#else + void *p_device +#endif + ) : + device(p_device) { + } virtual ~Surface() = default; MTLPixelFormat get_pixel_format() const { return MTLPixelFormatBGRA8Unorm; } @@ -96,104 +125,14 @@ public: virtual void present(MDCommandBuffer *p_cmd_buffer) = 0; }; - class SurfaceLayer : public Surface { - CAMetalLayer *__unsafe_unretained layer = nil; - LocalVector<MDFrameBuffer> frame_buffers; - LocalVector<id<MTLDrawable>> drawables; - uint32_t rear = -1; - uint32_t front = 0; - uint32_t count = 0; - - public: - SurfaceLayer(CAMetalLayer *p_layer, id<MTLDevice> p_device) : - Surface(p_device), layer(p_layer) { - layer.allowsNextDrawableTimeout = YES; - layer.framebufferOnly = YES; - layer.opaque = OS::get_singleton()->is_layered_allowed() ? NO : YES; - layer.pixelFormat = get_pixel_format(); - layer.device = p_device; - } - - ~SurfaceLayer() override { - layer = nil; - } - - Error resize(uint32_t p_desired_framebuffer_count) override final { - if (width == 0 || height == 0) { - // Very likely the window is minimized, don't create a swap chain. - return ERR_SKIP; - } - - CGSize drawableSize = CGSizeMake(width, height); - CGSize current = layer.drawableSize; - if (!CGSizeEqualToSize(current, drawableSize)) { - layer.drawableSize = drawableSize; - } - - // Metal supports a maximum of 3 drawables. - p_desired_framebuffer_count = MIN(3U, p_desired_framebuffer_count); - layer.maximumDrawableCount = p_desired_framebuffer_count; - -#if TARGET_OS_OSX - // Display sync is only supported on macOS. - switch (vsync_mode) { - case DisplayServer::VSYNC_MAILBOX: - case DisplayServer::VSYNC_ADAPTIVE: - case DisplayServer::VSYNC_ENABLED: - layer.displaySyncEnabled = YES; - break; - case DisplayServer::VSYNC_DISABLED: - layer.displaySyncEnabled = NO; - break; - } +#ifdef __OBJC__ + id<MTLDevice> +#else + void * #endif - drawables.resize(p_desired_framebuffer_count); - frame_buffers.resize(p_desired_framebuffer_count); - for (uint32_t i = 0; i < p_desired_framebuffer_count; i++) { - // Reserve space for the drawable texture. - frame_buffers[i].textures.resize(1); - } - - return OK; - } - - RDD::FramebufferID acquire_next_frame_buffer() override final { - if (count == frame_buffers.size()) { - return RDD::FramebufferID(); - } - - rear = (rear + 1) % frame_buffers.size(); - count++; - - MDFrameBuffer &frame_buffer = frame_buffers[rear]; - frame_buffer.size = Size2i(width, height); - - id<CAMetalDrawable> drawable = layer.nextDrawable; - ERR_FAIL_NULL_V_MSG(drawable, RDD::FramebufferID(), "no drawable available"); - drawables[rear] = drawable; - frame_buffer.textures.write[0] = drawable.texture; - - return RDD::FramebufferID(&frame_buffer); - } - - void present(MDCommandBuffer *p_cmd_buffer) override final { - if (count == 0) { - return; - } - - // Release texture and drawable. - frame_buffers[front].textures.write[0] = nil; - id<MTLDrawable> drawable = drawables[front]; - drawables[front] = nil; - - count--; - front = (front + 1) % frame_buffers.size(); - - [p_cmd_buffer->get_command_buffer() presentDrawable:drawable]; - } - }; - - id<MTLDevice> get_metal_device() const { return metal_device; } + get_metal_device() const { + return metal_device; + } #pragma mark - Initialization diff --git a/drivers/metal/rendering_context_driver_metal.mm b/drivers/metal/rendering_context_driver_metal.mm index b257d7142a..b97b586352 100644 --- a/drivers/metal/rendering_context_driver_metal.mm +++ b/drivers/metal/rendering_context_driver_metal.mm @@ -30,6 +30,8 @@ #import "rendering_context_driver_metal.h" +#import "rendering_device_driver_metal.h" + @protocol MTLDeviceEx <MTLDevice> #if TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED < 130300 - (void)setShouldMaximizeConcurrentCompilation:(BOOL)v; @@ -77,6 +79,103 @@ void RenderingContextDriverMetal::driver_free(RenderingDeviceDriver *p_driver) { memdelete(p_driver); } +class API_AVAILABLE(macos(11.0), ios(14.0)) SurfaceLayer : public RenderingContextDriverMetal::Surface { + CAMetalLayer *__unsafe_unretained layer = nil; + LocalVector<MDFrameBuffer> frame_buffers; + LocalVector<id<MTLDrawable>> drawables; + uint32_t rear = -1; + uint32_t front = 0; + uint32_t count = 0; + +public: + SurfaceLayer(CAMetalLayer *p_layer, id<MTLDevice> p_device) : + Surface(p_device), layer(p_layer) { + layer.allowsNextDrawableTimeout = YES; + layer.framebufferOnly = YES; + layer.opaque = OS::get_singleton()->is_layered_allowed() ? NO : YES; + layer.pixelFormat = get_pixel_format(); + layer.device = p_device; + } + + ~SurfaceLayer() override { + layer = nil; + } + + Error resize(uint32_t p_desired_framebuffer_count) override final { + if (width == 0 || height == 0) { + // Very likely the window is minimized, don't create a swap chain. + return ERR_SKIP; + } + + CGSize drawableSize = CGSizeMake(width, height); + CGSize current = layer.drawableSize; + if (!CGSizeEqualToSize(current, drawableSize)) { + layer.drawableSize = drawableSize; + } + + // Metal supports a maximum of 3 drawables. + p_desired_framebuffer_count = MIN(3U, p_desired_framebuffer_count); + layer.maximumDrawableCount = p_desired_framebuffer_count; + +#if TARGET_OS_OSX + // Display sync is only supported on macOS. + switch (vsync_mode) { + case DisplayServer::VSYNC_MAILBOX: + case DisplayServer::VSYNC_ADAPTIVE: + case DisplayServer::VSYNC_ENABLED: + layer.displaySyncEnabled = YES; + break; + case DisplayServer::VSYNC_DISABLED: + layer.displaySyncEnabled = NO; + break; + } +#endif + drawables.resize(p_desired_framebuffer_count); + frame_buffers.resize(p_desired_framebuffer_count); + for (uint32_t i = 0; i < p_desired_framebuffer_count; i++) { + // Reserve space for the drawable texture. + frame_buffers[i].textures.resize(1); + } + + return OK; + } + + RDD::FramebufferID acquire_next_frame_buffer() override final { + if (count == frame_buffers.size()) { + return RDD::FramebufferID(); + } + + rear = (rear + 1) % frame_buffers.size(); + count++; + + MDFrameBuffer &frame_buffer = frame_buffers[rear]; + frame_buffer.size = Size2i(width, height); + + id<CAMetalDrawable> drawable = layer.nextDrawable; + ERR_FAIL_NULL_V_MSG(drawable, RDD::FramebufferID(), "no drawable available"); + drawables[rear] = drawable; + frame_buffer.textures.write[0] = drawable.texture; + + return RDD::FramebufferID(&frame_buffer); + } + + void present(MDCommandBuffer *p_cmd_buffer) override final { + if (count == 0) { + return; + } + + // Release texture and drawable. + frame_buffers[front].textures.write[0] = nil; + id<MTLDrawable> drawable = drawables[front]; + drawables[front] = nil; + + count--; + front = (front + 1) % frame_buffers.size(); + + [p_cmd_buffer->get_command_buffer() presentDrawable:drawable]; + } +}; + RenderingContextDriver::SurfaceID RenderingContextDriverMetal::surface_create(const void *p_platform_data) { const WindowPlatformData *wpd = (const WindowPlatformData *)(p_platform_data); Surface *surface = memnew(SurfaceLayer(wpd->layer, metal_device)); diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index ea8b42b2e4..32f2d7dd79 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -218,67 +218,13 @@ bool FileAccessUnix::eof_reached() const { return last_error == ERR_FILE_EOF; } -uint8_t FileAccessUnix::get_8() const { - ERR_FAIL_NULL_V_MSG(f, 0, "File must be opened before use."); - uint8_t b; - if (fread(&b, 1, 1, f) == 0) { - check_errors(); - b = '\0'; - } - return b; -} - -uint16_t FileAccessUnix::get_16() const { - ERR_FAIL_NULL_V_MSG(f, 0, "File must be opened before use."); - - uint16_t b = 0; - if (fread(&b, 1, 2, f) != 2) { - check_errors(); - } - - if (big_endian) { - b = BSWAP16(b); - } - - return b; -} - -uint32_t FileAccessUnix::get_32() const { - ERR_FAIL_NULL_V_MSG(f, 0, "File must be opened before use."); - - uint32_t b = 0; - if (fread(&b, 1, 4, f) != 4) { - check_errors(); - } - - if (big_endian) { - b = BSWAP32(b); - } - - return b; -} - -uint64_t FileAccessUnix::get_64() const { - ERR_FAIL_NULL_V_MSG(f, 0, "File must be opened before use."); - - uint64_t b = 0; - if (fread(&b, 1, 8, f) != 8) { - check_errors(); - } - - if (big_endian) { - b = BSWAP64(b); - } - - return b; -} - uint64_t FileAccessUnix::get_buffer(uint8_t *p_dst, uint64_t p_length) const { - ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); ERR_FAIL_NULL_V_MSG(f, -1, "File must be opened before use."); + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); uint64_t read = fread(p_dst, 1, p_length, f); check_errors(); + return read; } @@ -308,41 +254,6 @@ void FileAccessUnix::flush() { fflush(f); } -void FileAccessUnix::store_8(uint8_t p_dest) { - ERR_FAIL_NULL_MSG(f, "File must be opened before use."); - ERR_FAIL_COND(fwrite(&p_dest, 1, 1, f) != 1); -} - -void FileAccessUnix::store_16(uint16_t p_dest) { - ERR_FAIL_NULL_MSG(f, "File must be opened before use."); - - if (big_endian) { - p_dest = BSWAP16(p_dest); - } - - ERR_FAIL_COND(fwrite(&p_dest, 1, 2, f) != 2); -} - -void FileAccessUnix::store_32(uint32_t p_dest) { - ERR_FAIL_NULL_MSG(f, "File must be opened before use."); - - if (big_endian) { - p_dest = BSWAP32(p_dest); - } - - ERR_FAIL_COND(fwrite(&p_dest, 1, 4, f) != 4); -} - -void FileAccessUnix::store_64(uint64_t p_dest) { - ERR_FAIL_NULL_MSG(f, "File must be opened before use."); - - if (big_endian) { - p_dest = BSWAP64(p_dest); - } - - ERR_FAIL_COND(fwrite(&p_dest, 1, 8, f) != 8); -} - void FileAccessUnix::store_buffer(const uint8_t *p_src, uint64_t p_length) { ERR_FAIL_NULL_MSG(f, "File must be opened before use."); ERR_FAIL_COND(!p_src && p_length > 0); diff --git a/drivers/unix/file_access_unix.h b/drivers/unix/file_access_unix.h index c0286dbff3..76f629f7c2 100644 --- a/drivers/unix/file_access_unix.h +++ b/drivers/unix/file_access_unix.h @@ -67,20 +67,12 @@ public: virtual bool eof_reached() const override; ///< reading passed EOF - virtual uint8_t get_8() const override; ///< get a byte - virtual uint16_t get_16() const override; - virtual uint32_t get_32() const override; - virtual uint64_t get_64() const override; virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const override; virtual Error get_error() const override; ///< get last error virtual Error resize(int64_t p_length) override; virtual void flush() override; - virtual void store_8(uint8_t p_dest) override; ///< store a byte - virtual void store_16(uint16_t p_dest) override; - virtual void store_32(uint32_t p_dest) override; - virtual void store_64(uint64_t p_dest) override; virtual void store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes virtual bool file_exists(const String &p_path) override; ///< return true if a file exists diff --git a/drivers/unix/file_access_unix_pipe.cpp b/drivers/unix/file_access_unix_pipe.cpp index 5d9a27ad05..34758e8c7d 100644 --- a/drivers/unix/file_access_unix_pipe.cpp +++ b/drivers/unix/file_access_unix_pipe.cpp @@ -125,22 +125,9 @@ String FileAccessUnixPipe::get_path_absolute() const { return path_src; } -uint8_t FileAccessUnixPipe::get_8() const { - ERR_FAIL_COND_V_MSG(fd[0] < 0, 0, "Pipe must be opened before use."); - - uint8_t b; - if (::read(fd[0], &b, 1) == 0) { - last_error = ERR_FILE_CANT_READ; - b = '\0'; - } else { - last_error = OK; - } - return b; -} - uint64_t FileAccessUnixPipe::get_buffer(uint8_t *p_dst, uint64_t p_length) const { - ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); ERR_FAIL_COND_V_MSG(fd[0] < 0, -1, "Pipe must be opened before use."); + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); uint64_t read = ::read(fd[0], p_dst, p_length); if (read == p_length) { @@ -155,18 +142,10 @@ Error FileAccessUnixPipe::get_error() const { return last_error; } -void FileAccessUnixPipe::store_8(uint8_t p_src) { - ERR_FAIL_COND_MSG(fd[1] < 0, "Pipe must be opened before use."); - if (::write(fd[1], &p_src, 1) != 1) { - last_error = ERR_FILE_CANT_WRITE; - } else { - last_error = OK; - } -} - void FileAccessUnixPipe::store_buffer(const uint8_t *p_src, uint64_t p_length) { ERR_FAIL_COND_MSG(fd[1] < 0, "Pipe must be opened before use."); ERR_FAIL_COND(!p_src && p_length > 0); + if (::write(fd[1], p_src, p_length) != (ssize_t)p_length) { last_error = ERR_FILE_CANT_WRITE; } else { diff --git a/drivers/unix/file_access_unix_pipe.h b/drivers/unix/file_access_unix_pipe.h index 8e7988791b..19acdb5a37 100644 --- a/drivers/unix/file_access_unix_pipe.h +++ b/drivers/unix/file_access_unix_pipe.h @@ -65,14 +65,12 @@ public: virtual bool eof_reached() const override { return false; } - virtual uint8_t get_8() const override; ///< get a byte virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const override; virtual Error get_error() const override; ///< get last error virtual Error resize(int64_t p_length) override { return ERR_UNAVAILABLE; } virtual void flush() override {} - virtual void store_8(uint8_t p_src) override; ///< store a byte virtual void store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes virtual bool file_exists(const String &p_path) override { return false; } diff --git a/drivers/vulkan/rendering_device_driver_vulkan.cpp b/drivers/vulkan/rendering_device_driver_vulkan.cpp index 2ba353868b..4ea46e8214 100644 --- a/drivers/vulkan/rendering_device_driver_vulkan.cpp +++ b/drivers/vulkan/rendering_device_driver_vulkan.cpp @@ -497,6 +497,7 @@ Error RenderingDeviceDriverVulkan::_initialize_device_extensions() { _register_requested_device_extension(VK_KHR_MAINTENANCE_2_EXTENSION_NAME, false); _register_requested_device_extension(VK_EXT_PIPELINE_CREATION_CACHE_CONTROL_EXTENSION_NAME, false); _register_requested_device_extension(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME, false); + _register_requested_device_extension(VK_EXT_ASTC_DECODE_MODE_EXTENSION_NAME, false); if (Engine::get_singleton()->is_generate_spirv_debug_info_enabled()) { _register_requested_device_extension(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, true); @@ -1705,6 +1706,16 @@ RDD::TextureID RenderingDeviceDriverVulkan::texture_create(const TextureFormat & image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; } + VkImageViewASTCDecodeModeEXT decode_mode; + if (enabled_device_extension_names.has(VK_EXT_ASTC_DECODE_MODE_EXTENSION_NAME)) { + if (image_view_create_info.format >= VK_FORMAT_ASTC_4x4_UNORM_BLOCK && image_view_create_info.format <= VK_FORMAT_ASTC_12x12_SRGB_BLOCK) { + decode_mode.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_ASTC_DECODE_MODE_EXT; + decode_mode.pNext = nullptr; + decode_mode.decodeMode = VK_FORMAT_R8G8B8A8_UNORM; + image_view_create_info.pNext = &decode_mode; + } + } + VkImageView vk_image_view = VK_NULL_HANDLE; err = vkCreateImageView(vk_device, &image_view_create_info, VKC::get_allocation_callbacks(VK_OBJECT_TYPE_IMAGE_VIEW), &vk_image_view); if (err) { diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index f6f721639c..0243d863f8 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -323,93 +323,9 @@ bool FileAccessWindows::eof_reached() const { return last_error == ERR_FILE_EOF; } -uint8_t FileAccessWindows::get_8() const { - ERR_FAIL_NULL_V(f, 0); - - if (flags == READ_WRITE || flags == WRITE_READ) { - if (prev_op == WRITE) { - fflush(f); - } - prev_op = READ; - } - uint8_t b; - if (fread(&b, 1, 1, f) == 0) { - check_errors(); - b = '\0'; - } - - return b; -} - -uint16_t FileAccessWindows::get_16() const { - ERR_FAIL_NULL_V(f, 0); - - if (flags == READ_WRITE || flags == WRITE_READ) { - if (prev_op == WRITE) { - fflush(f); - } - prev_op = READ; - } - - uint16_t b = 0; - if (fread(&b, 1, 2, f) != 2) { - check_errors(); - } - - if (big_endian) { - b = BSWAP16(b); - } - - return b; -} - -uint32_t FileAccessWindows::get_32() const { - ERR_FAIL_NULL_V(f, 0); - - if (flags == READ_WRITE || flags == WRITE_READ) { - if (prev_op == WRITE) { - fflush(f); - } - prev_op = READ; - } - - uint32_t b = 0; - if (fread(&b, 1, 4, f) != 4) { - check_errors(); - } - - if (big_endian) { - b = BSWAP32(b); - } - - return b; -} - -uint64_t FileAccessWindows::get_64() const { - ERR_FAIL_NULL_V(f, 0); - - if (flags == READ_WRITE || flags == WRITE_READ) { - if (prev_op == WRITE) { - fflush(f); - } - prev_op = READ; - } - - uint64_t b = 0; - if (fread(&b, 1, 8, f) != 8) { - check_errors(); - } - - if (big_endian) { - b = BSWAP64(b); - } - - return b; -} - uint64_t FileAccessWindows::get_buffer(uint8_t *p_dst, uint64_t p_length) const { - ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); ERR_FAIL_NULL_V(f, -1); + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); if (flags == READ_WRITE || flags == WRITE_READ) { if (prev_op == WRITE) { @@ -417,8 +333,10 @@ uint64_t FileAccessWindows::get_buffer(uint8_t *p_dst, uint64_t p_length) const } prev_op = READ; } + uint64_t read = fread(p_dst, 1, p_length, f); check_errors(); + return read; } @@ -453,77 +371,6 @@ void FileAccessWindows::flush() { } } -void FileAccessWindows::store_8(uint8_t p_dest) { - ERR_FAIL_NULL(f); - - if (flags == READ_WRITE || flags == WRITE_READ) { - if (prev_op == READ) { - if (last_error != ERR_FILE_EOF) { - fseek(f, 0, SEEK_CUR); - } - } - prev_op = WRITE; - } - fwrite(&p_dest, 1, 1, f); -} - -void FileAccessWindows::store_16(uint16_t p_dest) { - ERR_FAIL_NULL(f); - - if (flags == READ_WRITE || flags == WRITE_READ) { - if (prev_op == READ) { - if (last_error != ERR_FILE_EOF) { - fseek(f, 0, SEEK_CUR); - } - } - prev_op = WRITE; - } - - if (big_endian) { - p_dest = BSWAP16(p_dest); - } - - fwrite(&p_dest, 1, 2, f); -} - -void FileAccessWindows::store_32(uint32_t p_dest) { - ERR_FAIL_NULL(f); - - if (flags == READ_WRITE || flags == WRITE_READ) { - if (prev_op == READ) { - if (last_error != ERR_FILE_EOF) { - fseek(f, 0, SEEK_CUR); - } - } - prev_op = WRITE; - } - - if (big_endian) { - p_dest = BSWAP32(p_dest); - } - - fwrite(&p_dest, 1, 4, f); -} - -void FileAccessWindows::store_64(uint64_t p_dest) { - ERR_FAIL_NULL(f); - - if (flags == READ_WRITE || flags == WRITE_READ) { - if (prev_op == READ) { - if (last_error != ERR_FILE_EOF) { - fseek(f, 0, SEEK_CUR); - } - } - prev_op = WRITE; - } - - if (big_endian) { - p_dest = BSWAP64(p_dest); - } - - fwrite(&p_dest, 1, 8, f); -} - void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) { ERR_FAIL_NULL(f); ERR_FAIL_COND(!p_src && p_length > 0); @@ -536,6 +383,7 @@ void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) { } prev_op = WRITE; } + ERR_FAIL_COND(fwrite(p_src, 1, p_length, f) != (size_t)p_length); } @@ -559,11 +407,10 @@ uint64_t FileAccessWindows::_get_modified_time(const String &p_file) { return 0; } - String file = p_file; - if (file.ends_with("/") && file != "/") { + String file = fix_path(p_file); + if (file.ends_with("\\") && file != "\\") { file = file.substr(0, file.length() - 1); } - file = fix_path(file); struct _stat st; int rv = _wstat((LPCWSTR)(file.utf16().get_data()), &st); diff --git a/drivers/windows/file_access_windows.h b/drivers/windows/file_access_windows.h index a25bbcfb3a..f458ff9c6c 100644 --- a/drivers/windows/file_access_windows.h +++ b/drivers/windows/file_access_windows.h @@ -69,20 +69,12 @@ public: virtual bool eof_reached() const override; ///< reading passed EOF - virtual uint8_t get_8() const override; ///< get a byte - virtual uint16_t get_16() const override; - virtual uint32_t get_32() const override; - virtual uint64_t get_64() const override; virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const override; virtual Error get_error() const override; ///< get last error virtual Error resize(int64_t p_length) override; virtual void flush() override; - virtual void store_8(uint8_t p_dest) override; ///< store a byte - virtual void store_16(uint16_t p_dest) override; - virtual void store_32(uint32_t p_dest) override; - virtual void store_64(uint64_t p_dest) override; virtual void store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes virtual bool file_exists(const String &p_name) override; ///< return true if a file exists diff --git a/drivers/windows/file_access_windows_pipe.cpp b/drivers/windows/file_access_windows_pipe.cpp index 7902c8e1d8..0c953b14aa 100644 --- a/drivers/windows/file_access_windows_pipe.cpp +++ b/drivers/windows/file_access_windows_pipe.cpp @@ -96,22 +96,9 @@ String FileAccessWindowsPipe::get_path_absolute() const { return path_src; } -uint8_t FileAccessWindowsPipe::get_8() const { - ERR_FAIL_COND_V_MSG(fd[0] == 0, 0, "Pipe must be opened before use."); - - uint8_t b; - if (!ReadFile(fd[0], &b, 1, nullptr, nullptr)) { - last_error = ERR_FILE_CANT_READ; - b = '\0'; - } else { - last_error = OK; - } - return b; -} - uint64_t FileAccessWindowsPipe::get_buffer(uint8_t *p_dst, uint64_t p_length) const { - ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); ERR_FAIL_COND_V_MSG(fd[0] == 0, -1, "Pipe must be opened before use."); + ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); DWORD read = -1; if (!ReadFile(fd[0], p_dst, p_length, &read, nullptr) || read != p_length) { @@ -126,15 +113,6 @@ Error FileAccessWindowsPipe::get_error() const { return last_error; } -void FileAccessWindowsPipe::store_8(uint8_t p_src) { - ERR_FAIL_COND_MSG(fd[1] == 0, "Pipe must be opened before use."); - if (!WriteFile(fd[1], &p_src, 1, nullptr, nullptr)) { - last_error = ERR_FILE_CANT_WRITE; - } else { - last_error = OK; - } -} - void FileAccessWindowsPipe::store_buffer(const uint8_t *p_src, uint64_t p_length) { ERR_FAIL_COND_MSG(fd[1] == 0, "Pipe must be opened before use."); ERR_FAIL_COND(!p_src && p_length > 0); diff --git a/drivers/windows/file_access_windows_pipe.h b/drivers/windows/file_access_windows_pipe.h index b885ef78e6..4e9bd036ae 100644 --- a/drivers/windows/file_access_windows_pipe.h +++ b/drivers/windows/file_access_windows_pipe.h @@ -64,14 +64,12 @@ public: virtual bool eof_reached() const override { return false; } - virtual uint8_t get_8() const override; ///< get a byte virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const override; virtual Error get_error() const override; ///< get last error virtual Error resize(int64_t p_length) override { return ERR_UNAVAILABLE; } virtual void flush() override {} - virtual void store_8(uint8_t p_src) override; ///< store a byte virtual void store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes virtual bool file_exists(const String &p_name) override { return false; } |
