From 27df2cc871f712e283324a014a5867ba49119ced Mon Sep 17 00:00:00 2001 From: Ravbug Date: Wed, 21 Feb 2024 14:21:40 -0500 Subject: [PATCH 1/2] Sync with RavEngine --- CMakeLists.txt | 10 ++++---- include/RGL/CommandBuffer.hpp | 2 ++ include/RGL/Texture.hpp | 16 ++++++++++++- include/RGL/Types.hpp | 10 ++++++++ src/D3D12CommandBuffer.cpp | 4 ++-- src/D3D12Texture.cpp | 14 ++++++++--- src/D3D12Texture.hpp | 6 +++++ src/MTLCommandBuffer.mm | 2 +- src/MTLTexture.hpp | 7 ++++++ src/MTLTexture.mm | 16 ++++++++++++- src/VkBuffer.cpp | 2 +- src/VkCommandBuffer.cpp | 31 ++++++++++++++++++------ src/VkCommandBuffer.hpp | 3 ++- src/VkCommandQueue.cpp | 2 +- src/VkSurface.cpp | 14 +++++++++-- src/VkSwapchain.cpp | 4 ++-- src/VkTexture.cpp | 44 +++++++++++++++++++++++++++++++---- src/VkTexture.hpp | 15 +++++++++++- src/WGDevice.cpp | 2 +- src/WGShaderLibrary.cpp | 4 +++- src/WGTexture.cpp | 6 ++++- src/WGTexture.hpp | 3 ++- tools/librglc/librglc.cpp | 8 ++++--- 23 files changed, 187 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24d67bc..9b566c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ option(RGL_DISABLE_DX "Force-disable the D3D12 backend" OFF) option(RGL_DISABLE_WEBGPU "Force-disable the WebGPU backend" OFF) option(RGL_ENABLE_WEBGPU "Force-enable the WebGPU backend" OFF) option(RGL_RUNTIME_COMPILATION "Enable runtime shader compilation" OFF) +option(RGL_SKIP_BACKEND_CHECK "Skip the SDK check" OFF) option(RGL_IDE_ROOT "IDE parent folder for targets" "RGL") if (NOT RGL_IDE_ROOT) set(RGL_IDE_ROOT "RGL") # CMake sets this to "OFF" for some insane reason @@ -260,8 +261,9 @@ if (RGL_DX12_AVAILABLE) endif() - -if (RGL_VK_AVAILABLE OR RGL_DX12_AVAILABLE OR RGL_MTL_AVAILABLE OR RGL_WEBGPU_AVAILABLE) -else() -message(FATAL_ERROR "No backends are enabled! Check that all required SDKs are installed.") +if (NOT RGL_SKIP_BACKEND_CHECK) + if (RGL_VK_AVAILABLE OR RGL_DX12_AVAILABLE OR RGL_MTL_AVAILABLE OR RGL_WEBGPU_AVAILABLE) + else() + message(FATAL_ERROR "No backends are enabled! Check that all required SDKs are installed.") + endif() endif() diff --git a/include/RGL/CommandBuffer.hpp b/include/RGL/CommandBuffer.hpp index a1c00a6..992dd39 100644 --- a/include/RGL/CommandBuffer.hpp +++ b/include/RGL/CommandBuffer.hpp @@ -143,6 +143,8 @@ struct TextureView; struct TextureCopyConfig{ TextureView texture; + uint32_t mip = 0; + uint32_t layer = 0; }; virtual void CopyTextureToTexture(const TextureCopyConfig& from, const TextureCopyConfig& to) = 0; diff --git a/include/RGL/Texture.hpp b/include/RGL/Texture.hpp index 0038636..589d70e 100644 --- a/include/RGL/Texture.hpp +++ b/include/RGL/Texture.hpp @@ -1,6 +1,8 @@ #pragma once +#include "Types.hpp" #include #include +#include #include "TextureFormat.hpp" #include "SubresourceRange.hpp" @@ -118,6 +120,7 @@ namespace RGL { TextureView() {} }; + struct TextureConfig { TextureUsage usage; TextureAspect aspect; @@ -128,7 +131,17 @@ namespace RGL { ResourceLayout initialLayout = ResourceLayout::Undefined; bool isCubemap = false; bool readbackEnabled = false; - const char* debugName = nullptr; + std::string_view debugName; + }; + + class ICustomTextureView { + + virtual TextureView GetView() const = 0; + }; + + struct CustomTextureViewConfig { + uint32_t mip = 0; + uint32_t layer = 0; }; class ITexture { @@ -139,6 +152,7 @@ namespace RGL { virtual Dimension GetSize() const = 0; virtual TextureView GetDefaultView() const = 0; virtual TextureView GetViewForMip(uint32_t mip) const = 0; + virtual RGLCustomTextureViewPtr MakeCustomTextureView(const CustomTextureViewConfig& config) const = 0; }; } diff --git a/include/RGL/Types.hpp b/include/RGL/Types.hpp index cd5dc0b..ce8b1a3 100644 --- a/include/RGL/Types.hpp +++ b/include/RGL/Types.hpp @@ -29,6 +29,7 @@ namespace RGL { struct ISwapchain; struct IRenderPass; struct IComputePipeline; + struct ICustomTextureView; } #if RGL_SINGLE_BACKEND @@ -52,6 +53,7 @@ namespace RGL { struct CommandBufferMTL; struct RenderPassMTL; struct ComputePipelineMTL; + struct CustomTextureViewMTL; } using RGLDevicePtr = std::shared_ptr; @@ -69,6 +71,8 @@ using RGLCommandQueuePtr = std::shared_ptr; using RGLCommandBufferPtr = std::shared_ptr; using RGLRenderPassPtr = std::shared_ptr; using RGLComputePipelinePtr = std::shared_ptr; +using RGLCustomTextureViewPtr = std::shared_ptr; + #elif RGL_VK_AVAILABLE namespace RGL { @@ -89,6 +93,7 @@ namespace RGL { struct CommandQueueVk; struct CommandBufferVk; struct ComputePipelineVk; + struct CustomTextureViewVk; } using RGLDevicePtr = std::shared_ptr; @@ -105,6 +110,8 @@ using RGLSamplerPtr = std::shared_ptr; using RGLCommandQueuePtr = std::shared_ptr; using RGLCommandBufferPtr = std::shared_ptr; using RGLComputePipelinePtr = std::shared_ptr; +using RGLCustomTextureViewPtr = std::shared_ptr; + #elif RGL_DX12_AVAILABLE namespace RGL { struct SwapchainD3D12; @@ -124,6 +131,7 @@ namespace RGL { struct CommandQueueD3D12; struct CommandBufferD3D12; struct ComputePipelineD3D12; + struct CustomTextureViewD3D12; } using RGLDevicePtr = std::shared_ptr; @@ -141,6 +149,7 @@ using RGLCommandQueuePtr = std::shared_ptr; using RGLCommandBufferPtr = std::shared_ptr; using RGLRenderPassPtr = std::shared_ptr; using RGLComputePipelinePtr = std::shared_ptr; +using RGLCustomTextureViewPtr = std::shared_ptr; #endif #else @@ -153,6 +162,7 @@ using RGLComputePipelinePtr = std::shared_ptr; using RGLBufferPtr = std::shared_ptr; using RGLFencePtr = std::shared_ptr; using RGLTexturePtr = std::shared_ptr; + using RGLCustomTextureViewPtr = std::shared_ptr; using RGLSamplerPtr = std::shared_ptr; using RGLCommandQueuePtr = std::shared_ptr; using RGLCommandBufferPtr = std::shared_ptr; diff --git a/src/D3D12CommandBuffer.cpp b/src/D3D12CommandBuffer.cpp index 84d0aa7..1a57ebc 100644 --- a/src/D3D12CommandBuffer.cpp +++ b/src/D3D12CommandBuffer.cpp @@ -433,13 +433,13 @@ namespace RGL { D3D12_TEXTURE_COPY_LOCATION srcLocation = {}; srcLocation.pResource = from.texture.texture.dx.parentResource->texture.Get(); srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; - srcLocation.SubresourceIndex = 0; + srcLocation.SubresourceIndex = from.texture.texture.dx.parentResource->SubresourceIndexForMipLayer(from.mip, from.layer); // Create a destination texture location D3D12_TEXTURE_COPY_LOCATION dstLocation = {}; dstLocation.pResource = to.texture.texture.dx.parentResource->texture.Get(); dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; - dstLocation.SubresourceIndex = 0; + dstLocation.SubresourceIndex = to.texture.texture.dx.parentResource->SubresourceIndexForMipLayer(to.mip, to.layer); // Create a box that specifies the region to copy D3D12_BOX box = {}; diff --git a/src/D3D12Texture.cpp b/src/D3D12Texture.cpp index f179541..2995c0f 100644 --- a/src/D3D12Texture.cpp +++ b/src/D3D12Texture.cpp @@ -143,11 +143,11 @@ namespace RGL { &allocation, IID_PPV_ARGS(&texture)); std::wstring wide; - wide.resize(config.debugName == nullptr? 0 : strlen(config.debugName)); - MultiByteToWideChar(CP_UTF8, 0, config.debugName, -1, wide.data(), wide.size()); + wide.resize(config.debugName.data() == nullptr ? 0 : config.debugName.length()); + MultiByteToWideChar(CP_UTF8, 0, config.debugName.data(), -1, wide.data(), wide.size()); texture->SetName(wide.data()); - if (config.debugName != nullptr) { + if (config.debugName.data() != nullptr) { debugName = config.debugName; } @@ -269,6 +269,10 @@ namespace RGL { .coveredLayers = ALL_LAYERS, } }; } + RGLCustomTextureViewPtr TextureD3D12::MakeCustomTextureView(const CustomTextureViewConfig& config) const + { + return RGLCustomTextureViewPtr(); + } Dimension TextureD3D12::GetSize() const { return size; @@ -302,5 +306,9 @@ namespace RGL { owningDevice->CBV_SRV_UAVHeap->DeallocateSingle(handle); } } + TextureView CustomTextureViewD3D12::GetView() const + { + return TextureView(); + } } #endif \ No newline at end of file diff --git a/src/D3D12Texture.hpp b/src/D3D12Texture.hpp index 20c03a0..62be175 100644 --- a/src/D3D12Texture.hpp +++ b/src/D3D12Texture.hpp @@ -55,6 +55,7 @@ namespace RGL { TextureView GetDefaultView() const final; TextureView GetViewForMip(uint32_t mip) const final; + RGLCustomTextureViewPtr MakeCustomTextureView(const CustomTextureViewConfig& config) const; Dimension GetSize() const final; virtual ~TextureD3D12(); @@ -65,4 +66,9 @@ namespace RGL { std::string debugName; }; + + struct CustomTextureViewD3D12 : public ICustomTextureView { + + TextureView GetView() const; + }; } \ No newline at end of file diff --git a/src/MTLCommandBuffer.mm b/src/MTLCommandBuffer.mm index 8387712..6ffaf04 100644 --- a/src/MTLCommandBuffer.mm +++ b/src/MTLCommandBuffer.mm @@ -347,7 +347,7 @@ uint32_t bytesPerPixel(MTLPixelFormat format){ auto blitEncoder = [currentCommandBuffer blitCommandEncoder]; auto fromTexture = TextureMTL::ViewToTexture(from.texture); auto toTexture = TextureMTL::ViewToTexture(to.texture); - [blitEncoder copyFromTexture:fromTexture toTexture:toTexture]; + [blitEncoder copyFromTexture:fromTexture sourceSlice:from.layer sourceLevel:from.mip toTexture:toTexture destinationSlice:to.layer destinationLevel:to.mip sliceCount:1 levelCount:1]; [blitEncoder endEncoding]; } diff --git a/src/MTLTexture.hpp b/src/MTLTexture.hpp index 0770463..cf4d7c7 100644 --- a/src/MTLTexture.hpp +++ b/src/MTLTexture.hpp @@ -27,8 +27,15 @@ struct TextureMTL : public ITexture{ TextureView GetDefaultView() const final; TextureView GetViewForMip(uint32_t mip) const final; + + RGLCustomTextureViewPtr MakeCustomTextureView(const CustomTextureViewConfig& config) const; std::vector mipTextures; }; +struct CustomTextureViewMTL : public ICustomTextureView { + + TextureView GetView() const; +}; + } diff --git a/src/MTLTexture.mm b/src/MTLTexture.mm index 8a751f3..e21e7a3 100644 --- a/src/MTLTexture.mm +++ b/src/MTLTexture.mm @@ -31,7 +31,7 @@ desc.mipmapLevelCount = config.mipLevels; auto usage = rgl2mtlTextureUsage(config.usage); desc.usage = usage; - desc.storageMode = (config.aspect.HasDepth || config.aspect.HasStencil) ? MTLStorageModePrivate : + desc.storageMode = (config.aspect.HasDepth || config.aspect.HasStencil || config.usage.ColorAttachment) ? MTLStorageModePrivate : #if TARGET_OS_IPHONE MTLStorageModeShared; #else @@ -39,6 +39,10 @@ #endif texture = [owningDevice->device newTextureWithDescriptor:desc]; + if (config.debugName.data() != nullptr){ + [texture setLabel:[NSString stringWithUTF8String:config.debugName.data()]]; + } + mipTextures.reserve(config.mipLevels - 1); for(int i = 1; i < config.mipLevels; i++){ auto tex = [texture newTextureViewWithPixelFormat:format textureType:MTLTextureType2D levels:NSMakeRange(i, 1) slices:NSMakeRange(0, 1)]; @@ -77,6 +81,11 @@ return TextureView::NativeHandles::mtl_t{this, mip}; } +RGLCustomTextureViewPtr TextureMTL::MakeCustomTextureView(const CustomTextureViewConfig& config) const +{ + return RGLCustomTextureViewPtr(); +} + id TextureMTL::ViewToTexture(const TextureView& view){ if (view.texture.mtl.mip == TextureView::NativeHandles::mtl_t::ALL_MIPS){ return view.texture.mtl.texture->texture; @@ -86,5 +95,10 @@ } } +TextureView RGL::CustomTextureViewMTL::GetView() const +{ + return TextureView(); +} + } #endif diff --git a/src/VkBuffer.cpp b/src/VkBuffer.cpp index 75e8a48..86ce412 100644 --- a/src/VkBuffer.cpp +++ b/src/VkBuffer.cpp @@ -52,7 +52,7 @@ namespace RGL { allocation = createBuffer(owningDevice.get(), config.nElements * config.stride, usage, memprop, buffer); if (config.options.debugName) { - owningDevice->SetDebugNameForResource(buffer, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, config.options.debugName); + owningDevice->SetDebugNameForResource((void*)buffer, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, config.options.debugName); #ifndef NDEBUG debugName = config.options.debugName; #endif diff --git a/src/VkCommandBuffer.cpp b/src/VkCommandBuffer.cpp index 8242140..4bb4c27 100644 --- a/src/VkCommandBuffer.cpp +++ b/src/VkCommandBuffer.cpp @@ -11,6 +11,7 @@ #include "VkComputePipeline.hpp" #include #include +#include namespace RGL { VkAttachmentLoadOp RGL2LoadOp(LoadAccessOperation op) { @@ -276,9 +277,24 @@ namespace RGL { } void CommandBufferVk::CopyTextureToTexture(const TextureCopyConfig& from, const TextureCopyConfig& to) { - RecordTextureBinding(from.texture, {}, true); - RecordTextureBinding(to.texture, {}, true); - EncodeCommand(CmdCopyTextureToTexture{ from,to }); + auto fromCpy = from.texture; + fromCpy.texture.vk.coveredLayers = MakeMipMaskForIndex(from.layer); + fromCpy.texture.vk.coveredMips = MakeMipMaskForIndex(from.mip); + + auto toCpy = to.texture; + toCpy.texture.vk.coveredLayers = MakeMipMaskForIndex(to.layer); + toCpy.texture.vk.coveredMips = MakeMipMaskForIndex(to.mip); + + RecordTextureBinding(fromCpy, {VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL}, false); + RecordTextureBinding(toCpy, { VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL }, false); + + auto fromcnfcpy = from; + fromcnfcpy.texture = fromCpy; + + auto tocnfcpy = to; + tocnfcpy.texture = toCpy; + + EncodeCommand(CmdCopyTextureToTexture{ fromcnfcpy, tocnfcpy, from.mip, from.layer, to.mip, to.layer }); } void CommandBufferVk::SetViewport(const Viewport& viewport) { @@ -803,7 +819,7 @@ namespace RGL { auto dst = static_cast(arg.to.texture.parent); auto& srcLayout = activeTextures.at(TextureLastUseKey{src, arg.from.texture.texture.vk.coveredMips, arg.from.texture.texture.vk.coveredLayers }); - auto& dstLayout = activeTextures.at(TextureLastUseKey{ src,arg.to.texture.texture.vk.coveredMips, arg.to.texture.texture.vk.coveredLayers }); + auto& dstLayout = activeTextures.at(TextureLastUseKey{ dst, arg.to.texture.texture.vk.coveredMips, arg.to.texture.texture.vk.coveredLayers }); auto dim = src->GetSize(); VkImageCopy2 region{ @@ -811,14 +827,15 @@ namespace RGL { .pNext = nullptr, .srcSubresource = { .aspectMask = src->createdAspectVk, - .mipLevel = 0, - .baseArrayLayer = 0, + .mipLevel = arg.fromMip, + .baseArrayLayer = arg.fromLayer, .layerCount = 1 }, .srcOffset = {0,0,0}, .dstSubresource = { .aspectMask = dst->createdAspectVk, - .baseArrayLayer = 0, + .mipLevel = arg.toMip, + .baseArrayLayer = arg.toLayer, .layerCount = 1 }, .dstOffset = {0,0,0}, diff --git a/src/VkCommandBuffer.hpp b/src/VkCommandBuffer.hpp index 1d3f999..b2d25f5 100644 --- a/src/VkCommandBuffer.hpp +++ b/src/VkCommandBuffer.hpp @@ -5,7 +5,7 @@ #include "RGLVk.hpp" #include #include -#include "SubresourceRange.hpp" +#include namespace RGL { struct TextureLastUseKey { @@ -170,6 +170,7 @@ namespace RGL { struct CmdCopyTextureToTexture { TextureCopyConfig from, to; + uint32_t fromMip, fromLayer, toMip, toLayer; }; std::vector < std::variant < diff --git a/src/VkCommandQueue.cpp b/src/VkCommandQueue.cpp index b334d20..efaca5d 100644 --- a/src/VkCommandQueue.cpp +++ b/src/VkCommandQueue.cpp @@ -42,7 +42,7 @@ namespace RGL { if (config.signalFence) { fence = std::static_pointer_cast(config.signalFence); } - VK_CHECK(vkQueueSubmit(queue, 1, &submitInfo, fence ? fence->fence : nullptr)); + VK_CHECK(vkQueueSubmit(queue, 1, &submitInfo, fence ? fence->fence : VK_NULL_HANDLE)); VK_CHECK(vkQueueSubmit(queue,0, nullptr, internalFence)); } RGLCommandBufferPtr CommandQueueVk::CreateCommandBuffer() diff --git a/src/VkSurface.cpp b/src/VkSurface.cpp index 389faf1..45771af 100644 --- a/src/VkSurface.cpp +++ b/src/VkSurface.cpp @@ -6,12 +6,14 @@ #define WIN32_LEAN_AND_MEAN #include #include -#elif __linux__ +#elif __linux__ && !__ANDROID__ #include #include #include #include #include +#elif __ANDROID__ +#include #endif using namespace RGL; @@ -29,7 +31,7 @@ RGLSurfacePtr RGL::CreateVKSurfaceFromPlatformData(const CreateSurfaceConfig& co VK_CHECK(vkCreateWin32SurfaceKHR(instance, &createInfo, nullptr, &surface)); -#elif defined __linux__ +#elif defined __linux__ && !__ANDROID__ if (config.isWayland) { VkWaylandSurfaceCreateInfoKHR createInfo{ .sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR, @@ -50,6 +52,14 @@ RGLSurfacePtr RGL::CreateVKSurfaceFromPlatformData(const CreateSurfaceConfig& co }; VK_CHECK(vkCreateXlibSurfaceKHR(instance, &createInfo, nullptr, &surface)); } +#elif __ANDROID__ + VkAndroidSurfaceCreateInfoKHR createInfo{ + .sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR, + .pNext = nullptr, + .flags = 0, + .window = const_cast(static_cast(config.pointer)) + }; + VK_CHECK(vkCreateAndroidSurfaceKHR(instance, &createInfo, nullptr, &surface)); #endif return std::make_shared(surface); diff --git a/src/VkSwapchain.cpp b/src/VkSwapchain.cpp index 004df2c..b91a2cf 100644 --- a/src/VkSwapchain.cpp +++ b/src/VkSwapchain.cpp @@ -149,13 +149,13 @@ void RGL::SwapchainVK::Resize(uint32_t width, uint32_t height) auto debugName = std::string("swapchain ") + std::to_string(i); - owningDevice->SetDebugNameForResource(createInfo.image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, debugName.c_str()); + owningDevice->SetDebugNameForResource((void*)createInfo.image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, debugName.c_str()); VK_CHECK(vkCreateImageView(owningDevice->device, &createInfo, nullptr, &swapChainImageViews[i])); auto viewDebugName = std::string("swapchain image view ") + std::to_string(i); - owningDevice->SetDebugNameForResource(swapChainImageViews[i], VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, viewDebugName.c_str()); + owningDevice->SetDebugNameForResource((void*)swapChainImageViews[i], VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, viewDebugName.c_str()); auto& texture = RGLTextureResources.emplace_back(owningDevice, swapChainImageViews[i], swapChainImages[i], Dimension{ width,height }); texture.owningSwapchain = this; diff --git a/src/VkTexture.cpp b/src/VkTexture.cpp index 373aed4..13d810d 100644 --- a/src/VkTexture.cpp +++ b/src/VkTexture.cpp @@ -234,11 +234,11 @@ namespace RGL { createdAspectVk = rgl2vkAspectFlags(config.aspect); - if (config.debugName) { - owningDevice->SetDebugNameForResource(vkImage, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, config.debugName); - owningDevice->SetDebugNameForResource(vkImageView, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, config.debugName); + if (config.debugName.data() != nullptr) { + owningDevice->SetDebugNameForResource((void*)vkImage, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, config.debugName.data()); + owningDevice->SetDebugNameForResource((void*)vkImageView, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, config.debugName.data()); for (int i = 0; i < mipViews.size(); i++) { - owningDevice->SetDebugNameForResource(mipViews[i].texture.vk.view, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, config.debugName); + owningDevice->SetDebugNameForResource((void*)mipViews[i].texture.vk.view, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, config.debugName.data()); } debugName = config.debugName; } @@ -284,6 +284,42 @@ namespace RGL { { return mipViews.at(mip); } + RGLCustomTextureViewPtr TextureVk::MakeCustomTextureView(const CustomTextureViewConfig& config) const + { + return std::make_shared(shared_from_this(), config); + } + CustomTextureViewVk::CustomTextureViewVk(decltype(owningTexture) owning, const CustomTextureViewConfig& config) : owningTexture(owning), config(config) + { + VkImageViewCreateInfo createInfo{ + .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, + .image = owningTexture->vkImage, + .viewType = VK_IMAGE_VIEW_TYPE_2D, + .format = owningTexture->format, + .components{ + .r = VK_COMPONENT_SWIZZLE_IDENTITY, // we don't want any swizzling + .g = VK_COMPONENT_SWIZZLE_IDENTITY, + .b = VK_COMPONENT_SWIZZLE_IDENTITY, + .a = VK_COMPONENT_SWIZZLE_IDENTITY + }, + .subresourceRange{ + .aspectMask = rgl2vkAspectFlags(owningTexture->createdConfig.aspect), + .baseMipLevel = config.mip, + .levelCount = 1, + .baseArrayLayer = config.layer, + .layerCount = 1 + } + }; + + VK_CHECK(vkCreateImageView(owningTexture->owningDevice->device, &createInfo, nullptr, &imageView)); + } + CustomTextureViewVk::~CustomTextureViewVk() + { + vkDestroyImageView(owningTexture->owningDevice->device, imageView, nullptr); + } + TextureView CustomTextureViewVk::GetView() const + { + return TextureView(); + } } #endif \ No newline at end of file diff --git a/src/VkTexture.hpp b/src/VkTexture.hpp index 9660674..e5a9df4 100644 --- a/src/VkTexture.hpp +++ b/src/VkTexture.hpp @@ -10,7 +10,7 @@ namespace RGL { struct DeviceVk; - struct TextureVk : public ITexture { + struct TextureVk : public ITexture, public std::enable_shared_from_this { VkImageView vkImageView = VK_NULL_HANDLE; VkImage vkImage = VK_NULL_HANDLE; struct SwapchainVK* owningSwapchain = nullptr; // will remain null if the texture is not created by a swapchain @@ -33,9 +33,22 @@ namespace RGL { TextureView GetDefaultView() const final; TextureView GetViewForMip(uint32_t mip) const final; + RGLCustomTextureViewPtr MakeCustomTextureView(const CustomTextureViewConfig& config) const; + std::vector mipViews; std::string debugName; }; + struct CustomTextureViewVk : public ICustomTextureView { + const std::shared_ptr owningTexture = nullptr; + const CustomTextureViewConfig config; + CustomTextureViewVk(decltype(owningTexture) owning, const CustomTextureViewConfig& config); + + VkImageView imageView = VK_NULL_HANDLE; + + ~CustomTextureViewVk(); + + TextureView GetView() const; + }; } \ No newline at end of file diff --git a/src/WGDevice.cpp b/src/WGDevice.cpp index eecaa50..365df8b 100644 --- a/src/WGDevice.cpp +++ b/src/WGDevice.cpp @@ -122,7 +122,7 @@ namespace RGL{ WGPUDeviceDescriptor deviceDesc{ .nextInChain = nullptr, .label = "RGL WGPU device", - .requiredFeaturesCount = 0, + .requiredFeatureCount = 0, .defaultQueue = { .nextInChain = nullptr, .label = "RGL Default queue" diff --git a/src/WGShaderLibrary.cpp b/src/WGShaderLibrary.cpp index 95d903e..ea19bef 100644 --- a/src/WGShaderLibrary.cpp +++ b/src/WGShaderLibrary.cpp @@ -1,6 +1,8 @@ #if RGL_WEBGPU_AVAILABLE #include "WGShaderLibrary.hpp" +#if RGL_RUNTIME_COMPILATION #include +#endif #include #include #include "WGDevice.hpp" @@ -42,4 +44,4 @@ namespace RGL{ } } -#endif \ No newline at end of file +#endif diff --git a/src/WGTexture.cpp b/src/WGTexture.cpp index 1a78cbb..b674755 100644 --- a/src/WGTexture.cpp +++ b/src/WGTexture.cpp @@ -30,6 +30,10 @@ TextureView TextureWG::GetViewForMip(uint32_t mip) const{ return TextureView{mipViews.at(mip)}; } +RGLCustomTextureViewPtr TextureWG::MakeCustomTextureView(const CustomTextureViewConfig& config) const{ + return RGLCustomTextureViewPtr{}; } -#endif \ No newline at end of file +} + +#endif diff --git a/src/WGTexture.hpp b/src/WGTexture.hpp index 44fbf96..4060708 100644 --- a/src/WGTexture.hpp +++ b/src/WGTexture.hpp @@ -22,10 +22,11 @@ struct TextureWG : public ITexture{ TextureView GetDefaultView() const final; TextureView GetViewForMip(uint32_t mip) const final; + virtual RGLCustomTextureViewPtr MakeCustomTextureView(const CustomTextureViewConfig& config) const; std::vector mipViews; Dimension GetSize() const; }; -} \ No newline at end of file +} diff --git a/tools/librglc/librglc.cpp b/tools/librglc/librglc.cpp index cb22a26..d4fbc4e 100644 --- a/tools/librglc/librglc.cpp +++ b/tools/librglc/librglc.cpp @@ -29,9 +29,7 @@ shadert::TargetAPI rgl2shadert_binary(librglc::API api) { #if _WIN32 case decltype(api)::Direct3D12: return TargetAPI::DXIL; #endif -#if _WIN32 || __linux__ case decltype(api)::Vulkan: return TargetAPI::Vulkan; -#endif #ifdef __APPLE__ case decltype(api)::Metal: return TargetAPI::MetalBinary; #endif @@ -49,18 +47,22 @@ namespace librglc { opt.entryPoint = config.entrypointOutputName; if (toAPI == API::Vulkan) { opt.version = 15; + opt.preambleContent = "#define RGL_SL_VK 1"; } else if (toAPI == API::Direct3D12) { opt.version = 64; + opt.preambleContent = "#define RGL_SL_DX 1"; } else if (toAPI == API::Metal) { opt.version = 30; opt.pushConstantSettings.firstIndex = MTL_FIRST_BUFFER; // the [[stage_input]] consumes slot 0, extra vertex buffers consume the next slots + opt.preambleContent = "#define RGL_SL_MTL 1"; } else if (toAPI == API::WebGPU) { opt.version = 13; + opt.preambleContent = "#define RGL_SL_WGSL 1"; } - + ShaderTranspiler s; auto result = s.CompileTo(task, config.outputBinary ? rgl2shadert_binary(toAPI) : rgl2shadert_source(toAPI), opt); From 3c89b1aa3fec3a8b097b7d293f34c85ed7d815c8 Mon Sep 17 00:00:00 2001 From: Ravbug Date: Wed, 21 Feb 2024 14:27:19 -0500 Subject: [PATCH 2/2] Add Android build --- .github/workflows/build.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f1a98e6..07492a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,6 +73,31 @@ jobs: cd build cmake --build . --config Release --target RGL -- -quiet + build-android: + name: Android Compile Check + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + arch: [x86, x86_64, arm64-v8a, armeabi-v7a] + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: recursive + - name: Install deps + run: | + sudo apt update + sudo apt install ninja-build -y + - name: Configure + run: | + mkdir build + cd build + cmake -G "Ninja" -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=33 -DCMAKE_ANDROID_ARCH_ABI="${{ matrix.arch }}" -DCMAKE_ANDROID_ARM_NEON=ON .. + - name: Build + run: cmake --build build --parallel + + build-web: name: Web Compile Check runs-on: ubuntu-latest