From 796acfa98bc69f525d658fc61724195dbb688d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Sat, 12 Dec 2020 10:04:14 -0800 Subject: [PATCH] Added Attachment.numLayers needed for viewport layer array support. --- bindings/bf/bgfx.bf | 13 ++++-- bindings/cs/bgfx.cs | 13 ++++-- bindings/d/funcs.d | 10 +++-- bindings/d/types.d | 8 ++-- include/bgfx/bgfx.h | 7 +++- include/bgfx/c99/bgfx.h | 10 +++-- include/bgfx/defines.h | 5 ++- scripts/bgfx.idl | 20 ++++++---- src/bgfx.cpp | 15 +++---- src/bgfx.idl.inl | 4 +- src/renderer_d3d11.cpp | 16 ++++---- src/renderer_d3d12.cpp | 20 +++++----- src/renderer_vk.cpp | 87 +++++++++++++++++++++++++++++++---------- 13 files changed, 151 insertions(+), 77 deletions(-) diff --git a/bindings/bf/bgfx.bf b/bindings/bf/bgfx.bf index 20d2e124b..1a2f7e1cc 100644 --- a/bindings/bf/bgfx.bf +++ b/bindings/bf/bgfx.bf @@ -1030,7 +1030,7 @@ public static class bgfx DrawIndirect = 0x0000000000000010, /// - /// Fragment depth is accessible in fragment shader. + /// Fragment depth is available in fragment shader. /// FragmentDepth = 0x0000000000000020, @@ -1135,6 +1135,11 @@ public static class bgfx /// VertexId = 0x0000000004000000, + /// + /// Viewport layer is available in vertex shader. + /// + ViewportLayerArray = 0x0000000008000000, + /// /// All texture compare modes are supported. /// @@ -2122,6 +2127,7 @@ public static class bgfx public TextureHandle handle; public uint16 mip; public uint16 layer; + public uint16 numLayers; public uint8 resolve; } @@ -2287,12 +2293,13 @@ public static class bgfx /// /// Render target texture handle. /// Access. See `Access::Enum`. - /// Cubemap side or depth layer/slice. + /// Cubemap side or depth layer/slice to use. + /// Number of texture layer/slice(s) in array to use. /// Mip level. /// Resolve flags. See: `BGFX_RESOLVE_*` /// [LinkName("bgfx_attachment_init")] - public static extern void attachment_init(Attachment* _this, TextureHandle _handle, Access _access, uint16 _layer, uint16 _mip, uint8 _resolve); + public static extern void attachment_init(Attachment* _this, TextureHandle _handle, Access _access, uint16 _layer, uint16 _numLayers, uint16 _mip, uint8 _resolve); /// /// Start VertexLayout. diff --git a/bindings/cs/bgfx.cs b/bindings/cs/bgfx.cs index 0f88dce7d..679fb416d 100644 --- a/bindings/cs/bgfx.cs +++ b/bindings/cs/bgfx.cs @@ -1031,7 +1031,7 @@ public static partial class bgfx DrawIndirect = 0x0000000000000010, /// - /// Fragment depth is accessible in fragment shader. + /// Fragment depth is available in fragment shader. /// FragmentDepth = 0x0000000000000020, @@ -1136,6 +1136,11 @@ public static partial class bgfx /// VertexId = 0x0000000004000000, + /// + /// Viewport layer is available in vertex shader. + /// + ViewportLayerArray = 0x0000000008000000, + /// /// All texture compare modes are supported. /// @@ -2094,6 +2099,7 @@ public static partial class bgfx public TextureHandle handle; public ushort mip; public ushort layer; + public ushort numLayers; public byte resolve; } @@ -2241,12 +2247,13 @@ public static partial class bgfx /// /// Render target texture handle. /// Access. See `Access::Enum`. - /// Cubemap side or depth layer/slice. + /// Cubemap side or depth layer/slice to use. + /// Number of texture layer/slice(s) in array to use. /// Mip level. /// Resolve flags. See: `BGFX_RESOLVE_*` /// [DllImport(DllName, EntryPoint="bgfx_attachment_init", CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe void attachment_init(Attachment* _this, TextureHandle _handle, Access _access, ushort _layer, ushort _mip, byte _resolve); + public static extern unsafe void attachment_init(Attachment* _this, TextureHandle _handle, Access _access, ushort _layer, ushort _numLayers, ushort _mip, byte _resolve); /// /// Start VertexLayout. diff --git a/bindings/d/funcs.d b/bindings/d/funcs.d index ce0c0dbee..890382fca 100644 --- a/bindings/d/funcs.d +++ b/bindings/d/funcs.d @@ -17,11 +17,12 @@ version(BindBgfx_Static) * Params: * _handle = Render target texture handle. * _access = Access. See `Access::Enum`. - * _layer = Cubemap side or depth layer/slice. + * _layer = Cubemap side or depth layer/slice to use. + * _numLayers = Number of texture layer/slice(s) in array to use. * _mip = Mip level. * _resolve = Resolve flags. See: `BGFX_RESOLVE_*` */ - void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, ushort _layer, ushort _mip, byte _resolve); + void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, ushort _layer, ushort _numLayers, ushort _mip, byte _resolve); /** * Start VertexLayout. @@ -2149,11 +2150,12 @@ else * Params: * _handle = Render target texture handle. * _access = Access. See `Access::Enum`. - * _layer = Cubemap side or depth layer/slice. + * _layer = Cubemap side or depth layer/slice to use. + * _numLayers = Number of texture layer/slice(s) in array to use. * _mip = Mip level. * _resolve = Resolve flags. See: `BGFX_RESOLVE_*` */ - alias da_bgfx_attachment_init = void function(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, ushort _layer, ushort _mip, byte _resolve); + alias da_bgfx_attachment_init = void function(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, ushort _layer, ushort _numLayers, ushort _mip, byte _resolve); da_bgfx_attachment_init bgfx_attachment_init; /** diff --git a/bindings/d/types.d b/bindings/d/types.d index 4ae6394fd..e4b5e44b2 100644 --- a/bindings/d/types.d +++ b/bindings/d/types.d @@ -10,7 +10,7 @@ public import core.stdc.stdarg : va_list; extern(C) @nogc nothrow: -enum uint BGFX_API_VERSION = 110; +enum uint BGFX_API_VERSION = 111; alias bgfx_view_id_t = ushort; @@ -352,7 +352,7 @@ enum ulong BGFX_CAPS_BLEND_INDEPENDENT = 0x0000000000000002; /// Blend independe enum ulong BGFX_CAPS_COMPUTE = 0x0000000000000004; /// Compute shaders are supported. enum ulong BGFX_CAPS_CONSERVATIVE_RASTER = 0x0000000000000008; /// Conservative rasterization is supported. enum ulong BGFX_CAPS_DRAW_INDIRECT = 0x0000000000000010; /// Draw indirect is supported. -enum ulong BGFX_CAPS_FRAGMENT_DEPTH = 0x0000000000000020; /// Fragment depth is accessible in fragment shader. +enum ulong BGFX_CAPS_FRAGMENT_DEPTH = 0x0000000000000020; /// Fragment depth is available in fragment shader. enum ulong BGFX_CAPS_FRAGMENT_ORDERING = 0x0000000000000040; /// Fragment ordering is available in fragment shader. enum ulong BGFX_CAPS_GRAPHICS_DEBUGGER = 0x0000000000000080; /// Graphics debugger is present. enum ulong BGFX_CAPS_HDR10 = 0x0000000000000100; /// HDR10 rendering is supported. @@ -374,6 +374,7 @@ enum ulong BGFX_CAPS_TEXTURE_READ_BACK = 0x0000000000800000; /// Read-back textu enum ulong BGFX_CAPS_VERTEX_ATTRIB_HALF = 0x0000000001000000; /// Vertex attribute half-float is supported. enum ulong BGFX_CAPS_VERTEX_ATTRIB_UINT10 = 0x0000000002000000; /// Vertex attribute 10_10_10_2 is supported. enum ulong BGFX_CAPS_VERTEX_ID = 0x0000000004000000; /// Rendering with VertexID only is supported. +enum ulong BGFX_CAPS_VIEWPORT_LAYER_ARRAY = 0x0000000008000000; /// Viewport layer is available in vertex shader. enum ulong BGFX_CAPS_TEXTURE_COMPARE_ALL = 0x0000000000180000; /// All texture compare modes are supported. enum uint BGFX_CAPS_FORMAT_TEXTURE_NONE = 0x00000000; /// Texture format is not supported. @@ -942,7 +943,8 @@ struct bgfx_attachment_t bgfx_access_t access; /// Attachement access. See `Access::Enum`. bgfx_texture_handle_t handle; /// Render target texture handle. ushort mip; /// Mip level. - ushort layer; /// Cubemap side or depth layer/slice. + ushort layer; /// Cubemap side or depth layer/slice to use. + ushort numLayers; /// Number of texture layer/slice(s) in array to use. byte resolve; /// Resolve flags. See: `BGFX_RESOLVE_*` } diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 8cca874a8..1d5deb1f9 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -891,7 +891,8 @@ namespace bgfx /// /// @param[in] _handle Render target texture handle. /// @param[in] _access Access. See `Access::Enum`. - /// @param[in] _layer Cubemap side or depth layer/slice. + /// @param[in] _layer Cubemap side or depth layer/slice to use. + /// @param[in] _numLayers Number of texture layer/slice(s) in array to use. /// @param[in] _mip Mip level. /// @param[in] _resolve Resolve flags. See: `BGFX_RESOLVE_*` /// @@ -899,6 +900,7 @@ namespace bgfx TextureHandle _handle , Access::Enum _access = Access::Write , uint16_t _layer = 0 + , uint16_t _numLayers = 1 , uint16_t _mip = 0 , uint8_t _resolve = BGFX_RESOLVE_AUTO_GEN_MIPS ); @@ -906,7 +908,8 @@ namespace bgfx Access::Enum access; //!< Attachement access. See `Access::Enum`. TextureHandle handle; //!< Render target texture handle. uint16_t mip; //!< Mip level. - uint16_t layer; //!< Cubemap side or depth layer/slice. + uint16_t layer; //!< Cubemap side or depth layer/slice to use. + uint16_t numLayers; //!< Number of texture layer/slice(s) in array to use. uint8_t resolve; //!< Resolve flags. See: `BGFX_RESOLVE_*` }; diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 80b7deb90..09a7ec035 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -783,7 +783,8 @@ typedef struct bgfx_attachment_s bgfx_access_t access; /** Attachement access. See `Access::Enum`. */ bgfx_texture_handle_t handle; /** Render target texture handle. */ uint16_t mip; /** Mip level. */ - uint16_t layer; /** Cubemap side or depth layer/slice. */ + uint16_t layer; /** Cubemap side or depth layer/slice to use. */ + uint16_t numLayers; /** Number of texture layer/slice(s) in array to use. */ uint8_t resolve; /** Resolve flags. See: `BGFX_RESOLVE_*` */ } bgfx_attachment_t; @@ -903,12 +904,13 @@ typedef struct bgfx_encoder_s bgfx_encoder_t; * * @param[in] _handle Render target texture handle. * @param[in] _access Access. See `Access::Enum`. - * @param[in] _layer Cubemap side or depth layer/slice. + * @param[in] _layer Cubemap side or depth layer/slice to use. + * @param[in] _numLayers Number of texture layer/slice(s) in array to use. * @param[in] _mip Mip level. * @param[in] _resolve Resolve flags. See: `BGFX_RESOLVE_*` * */ -BGFX_C_API void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _mip, uint8_t _resolve); +BGFX_C_API void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _numLayers, uint16_t _mip, uint8_t _resolve); /** * Start VertexLayout. @@ -3532,7 +3534,7 @@ typedef enum bgfx_function_id /**/ struct bgfx_interface_vtbl { - void (*attachment_init)(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _mip, uint8_t _resolve); + void (*attachment_init)(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _numLayers, uint16_t _mip, uint8_t _resolve); bgfx_vertex_layout_t* (*vertex_layout_begin)(bgfx_vertex_layout_t* _this, bgfx_renderer_type_t _rendererType); bgfx_vertex_layout_t* (*vertex_layout_add)(bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt); void (*vertex_layout_decode)(const bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib, uint8_t * _num, bgfx_attrib_type_t * _type, bool * _normalized, bool * _asInt); diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index 82fb44ed3..8a6c9f9a5 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -15,7 +15,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(110) +#define BGFX_API_VERSION UINT32_C(111) /** * Color RGB/alpha/depth write. When it's not specified write will be disabled. @@ -466,7 +466,7 @@ #define BGFX_CAPS_COMPUTE UINT64_C(0x0000000000000004) //!< Compute shaders are supported. #define BGFX_CAPS_CONSERVATIVE_RASTER UINT64_C(0x0000000000000008) //!< Conservative rasterization is supported. #define BGFX_CAPS_DRAW_INDIRECT UINT64_C(0x0000000000000010) //!< Draw indirect is supported. -#define BGFX_CAPS_FRAGMENT_DEPTH UINT64_C(0x0000000000000020) //!< Fragment depth is accessible in fragment shader. +#define BGFX_CAPS_FRAGMENT_DEPTH UINT64_C(0x0000000000000020) //!< Fragment depth is available in fragment shader. #define BGFX_CAPS_FRAGMENT_ORDERING UINT64_C(0x0000000000000040) //!< Fragment ordering is available in fragment shader. #define BGFX_CAPS_GRAPHICS_DEBUGGER UINT64_C(0x0000000000000080) //!< Graphics debugger is present. #define BGFX_CAPS_HDR10 UINT64_C(0x0000000000000100) //!< HDR10 rendering is supported. @@ -488,6 +488,7 @@ #define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000001000000) //!< Vertex attribute half-float is supported. #define BGFX_CAPS_VERTEX_ATTRIB_UINT10 UINT64_C(0x0000000002000000) //!< Vertex attribute 10_10_10_2 is supported. #define BGFX_CAPS_VERTEX_ID UINT64_C(0x0000000004000000) //!< Rendering with VertexID only is supported. +#define BGFX_CAPS_VIEWPORT_LAYER_ARRAY UINT64_C(0x0000000008000000) //!< Viewport layer is available in vertex shader. /// All texture compare modes are supported. #define BGFX_CAPS_TEXTURE_COMPARE_ALL (0 \ | BGFX_CAPS_TEXTURE_COMPARE_RESERVED \ diff --git a/scripts/bgfx.idl b/scripts/bgfx.idl index 175a15a71..b4220cefa 100644 --- a/scripts/bgfx.idl +++ b/scripts/bgfx.idl @@ -1,7 +1,7 @@ -- vim: syntax=lua -- bgfx interface -version(110) +version(111) typedef "bool" typedef "char" @@ -369,7 +369,7 @@ flag.Caps { bits = 64, base = 1, name = "Caps" } .Compute --- Compute shaders are supported. .ConservativeRaster --- Conservative rasterization is supported. .DrawIndirect --- Draw indirect is supported. - .FragmentDepth --- Fragment depth is accessible in fragment shader. + .FragmentDepth --- Fragment depth is available in fragment shader. .FragmentOrdering --- Fragment ordering is available in fragment shader. .GraphicsDebugger --- Graphics debugger is present. .Hdr10 --- HDR10 rendering is supported. @@ -391,6 +391,7 @@ flag.Caps { bits = 64, base = 1, name = "Caps" } .VertexAttribHalf --- Vertex attribute half-float is supported. .VertexAttribUint10 --- Vertex attribute 10_10_10_2 is supported. .VertexId --- Rendering with VertexID only is supported. + .ViewportLayerArray --- Viewport layer is available in vertex shader. .TextureCompareAll { "TextureCompareReserved", "TextureCompareLequal" } --- All texture compare modes are supported. () @@ -853,11 +854,12 @@ struct.UniformInfo --- Frame buffer texture attachment info. struct.Attachment { shortname } - .access "Access::Enum" --- Attachement access. See `Access::Enum`. - .handle "TextureHandle" --- Render target texture handle. - .mip "uint16_t" --- Mip level. - .layer "uint16_t" --- Cubemap side or depth layer/slice. - .resolve "uint8_t" --- Resolve flags. See: `BGFX_RESOLVE_*` + .access "Access::Enum" --- Attachement access. See `Access::Enum`. + .handle "TextureHandle" --- Render target texture handle. + .mip "uint16_t" --- Mip level. + .layer "uint16_t" --- Cubemap side or depth layer/slice to use. + .numLayers "uint16_t" --- Number of texture layer/slice(s) in array to use. + .resolve "uint8_t" --- Resolve flags. See: `BGFX_RESOLVE_*` --- Init attachment. func.Attachment.init @@ -865,8 +867,10 @@ func.Attachment.init .handle "TextureHandle" --- Render target texture handle. .access "Access::Enum" --- Access. See `Access::Enum`. { default = "Access::Write" } - .layer "uint16_t" --- Cubemap side or depth layer/slice. + .layer "uint16_t" --- Cubemap side or depth layer/slice to use. { default = 0 } + .numLayers "uint16_t" --- Number of texture layer/slice(s) in array to use. + { default = 1 } .mip "uint16_t" --- Mip level. { default = 0 } .resolve "uint8_t" --- Resolve flags. See: `BGFX_RESOLVE_*` diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 556377239..f3946c780 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -3383,13 +3383,14 @@ namespace bgfx { } - void Attachment::init(TextureHandle _handle, Access::Enum _access, uint16_t _layer, uint16_t _mip, uint8_t _resolve) + void Attachment::init(TextureHandle _handle, Access::Enum _access, uint16_t _layer, uint16_t _numLayers, uint16_t _mip, uint8_t _resolve) { - access = _access; - handle = _handle; - mip = _mip; - layer = _layer; - resolve = _resolve; + access = _access; + handle = _handle; + mip = _mip; + layer = _layer; + numLayers = _numLayers; + resolve = _resolve; } bool init(const Init& _userInit) @@ -4667,7 +4668,7 @@ namespace bgfx for (uint8_t ii = 0; ii < _num; ++ii) { Attachment& at = attachment[ii]; - at.init(_handles[ii], Access::Write, 0, 0, BGFX_RESOLVE_AUTO_GEN_MIPS); + at.init(_handles[ii], Access::Write, 0, 1, 0, BGFX_RESOLVE_AUTO_GEN_MIPS); } return createFrameBuffer(_num, attachment, _destroyTextures); } diff --git a/src/bgfx.idl.inl b/src/bgfx.idl.inl index b2632f51c..2005c8fa7 100644 --- a/src/bgfx.idl.inl +++ b/src/bgfx.idl.inl @@ -50,11 +50,11 @@ BGFX_C99_STRUCT_SIZE_CHECK(bgfx::InternalData, bgfx_internal_data_t); #undef BGFX_C99_STRUCT_SIZE_CHECK -BGFX_C_API void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _mip, uint8_t _resolve) +BGFX_C_API void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _numLayers, uint16_t _mip, uint8_t _resolve) { bgfx::Attachment* This = (bgfx::Attachment*)_this; union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - This->init(handle.cpp, (bgfx::Access::Enum)_access, _layer, _mip, _resolve); + This->init(handle.cpp, (bgfx::Access::Enum)_access, _layer, _numLayers, _mip, _resolve); } BGFX_C_API bgfx_vertex_layout_t* bgfx_vertex_layout_begin(bgfx_vertex_layout_t* _this, bgfx_renderer_type_t _rendererType) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 2b6892823..faf1460df 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -4988,7 +4988,7 @@ namespace bgfx { namespace d3d11 { dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY; dsvDesc.Texture2DMSArray.FirstArraySlice = at.layer; - dsvDesc.Texture2DMSArray.ArraySize = 1; + dsvDesc.Texture2DMSArray.ArraySize = at.numLayers; } else { @@ -5001,7 +5001,7 @@ namespace bgfx { namespace d3d11 { dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; dsvDesc.Texture2DArray.FirstArraySlice = at.layer; - dsvDesc.Texture2DArray.ArraySize = 1; + dsvDesc.Texture2DArray.ArraySize = at.numLayers; dsvDesc.Texture2DArray.MipSlice = at.mip; } else @@ -5023,14 +5023,14 @@ namespace bgfx { namespace d3d11 if (1 < msaa.Count) { dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY; - dsvDesc.Texture2DMSArray.ArraySize = 1; dsvDesc.Texture2DMSArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DMSArray.ArraySize = at.numLayers; } else { dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; - dsvDesc.Texture2DArray.ArraySize = 1; dsvDesc.Texture2DArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DArray.ArraySize = at.numLayers; dsvDesc.Texture2DArray.MipSlice = at.mip; } DX_CHECK(s_renderD3D11->m_device->CreateDepthStencilView(texture.m_ptr, &dsvDesc, &m_dsv) ); @@ -5065,7 +5065,7 @@ namespace bgfx { namespace d3d11 { desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; desc.Texture2DArray.FirstArraySlice = at.layer; - desc.Texture2DArray.ArraySize = 1; + desc.Texture2DArray.ArraySize = at.numLayers; desc.Texture2DArray.MipSlice = at.mip; } else @@ -5086,14 +5086,14 @@ namespace bgfx { namespace d3d11 if (1 < msaa.Count) { desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY; - desc.Texture2DMSArray.ArraySize = 1; desc.Texture2DMSArray.FirstArraySlice = at.layer; + desc.Texture2DMSArray.ArraySize = at.numLayers; } else { desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; - desc.Texture2DArray.ArraySize = 1; desc.Texture2DArray.FirstArraySlice = at.layer; + desc.Texture2DArray.ArraySize = at.numLayers; desc.Texture2DArray.MipSlice = at.mip; } @@ -5103,8 +5103,8 @@ namespace bgfx { namespace d3d11 case TextureD3D11::Texture3D: desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D; desc.Texture3D.MipSlice = at.mip; - desc.Texture3D.WSize = 1; desc.Texture3D.FirstWSlice = at.layer; + desc.Texture3D.WSize = at.numLayers; DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, &desc, &m_rtv[m_num]) ); break; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 11236ec37..4f4818823 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -5349,7 +5349,7 @@ namespace bgfx { namespace d3d12 { dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY; dsvDesc.Texture2DMSArray.FirstArraySlice = at.layer; - dsvDesc.Texture2DMSArray.ArraySize = 1; + dsvDesc.Texture2DMSArray.ArraySize = at.numLayers; } else { @@ -5362,7 +5362,7 @@ namespace bgfx { namespace d3d12 { dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DARRAY; dsvDesc.Texture2DArray.FirstArraySlice = at.layer; - dsvDesc.Texture2DArray.ArraySize = 1; + dsvDesc.Texture2DArray.ArraySize = at.numLayers; dsvDesc.Texture2DArray.MipSlice = at.mip; } else @@ -5377,14 +5377,14 @@ namespace bgfx { namespace d3d12 if (1 < msaa.Count) { dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY; - dsvDesc.Texture2DMSArray.ArraySize = 1; dsvDesc.Texture2DMSArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DMSArray.ArraySize = at.numLayers; } else { dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DARRAY; - dsvDesc.Texture2DArray.ArraySize = 1; dsvDesc.Texture2DArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DArray.ArraySize = at.numLayers; dsvDesc.Texture2DArray.MipSlice = at.mip; } break; @@ -5413,7 +5413,7 @@ namespace bgfx { namespace d3d12 { desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY; desc.Texture2DMSArray.FirstArraySlice = at.layer; - desc.Texture2DMSArray.ArraySize = 1; + desc.Texture2DMSArray.ArraySize = at.numLayers; } else { @@ -5426,7 +5426,7 @@ namespace bgfx { namespace d3d12 { desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY; desc.Texture2DArray.FirstArraySlice = at.layer; - desc.Texture2DArray.ArraySize = 1; + desc.Texture2DArray.ArraySize = at.numLayers; desc.Texture2DArray.MipSlice = at.mip; desc.Texture2DArray.PlaneSlice = 0; } @@ -5443,14 +5443,14 @@ namespace bgfx { namespace d3d12 if (1 < msaa.Count) { desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY; - desc.Texture2DMSArray.ArraySize = 1; desc.Texture2DMSArray.FirstArraySlice = at.layer; + desc.Texture2DMSArray.ArraySize = at.numLayers; } else { desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY; - desc.Texture2DArray.ArraySize = 1; desc.Texture2DArray.FirstArraySlice = at.layer; + desc.Texture2DArray.ArraySize = at.numLayers; desc.Texture2DArray.MipSlice = at.mip; desc.Texture2DArray.PlaneSlice = 0; } @@ -5458,9 +5458,9 @@ namespace bgfx { namespace d3d12 case TextureD3D12::Texture3D: desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE3D; - desc.Texture3D.MipSlice = at.mip; - desc.Texture3D.WSize = 1; + desc.Texture3D.MipSlice = at.mip; desc.Texture3D.FirstWSlice = at.layer; + desc.Texture3D.WSize = at.numLayers; break; } diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index a9113cd5e..62907b0e4 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -836,7 +836,17 @@ VK_IMPORT_DEVICE } } - void setImageMemoryBarrier(VkCommandBuffer _commandBuffer, VkImage _image, VkImageAspectFlags _aspectMask, VkImageLayout _oldLayout, VkImageLayout _newLayout, uint32_t _levelCount, uint32_t _layerCount) + void setImageMemoryBarrier( + VkCommandBuffer _commandBuffer + , VkImage _image + , VkImageAspectFlags _aspectMask + , VkImageLayout _oldLayout + , VkImageLayout _newLayout + , uint32_t _baseMipLevel + , uint32_t _levelCount + , uint32_t _baseArrayLayer + , uint32_t _layerCount + ) { BX_ASSERT(true && _newLayout != VK_IMAGE_LAYOUT_UNDEFINED @@ -943,9 +953,9 @@ VK_IMPORT_DEVICE imb.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; imb.image = _image; imb.subresourceRange.aspectMask = _aspectMask; - imb.subresourceRange.baseMipLevel = 0; + imb.subresourceRange.baseMipLevel = _baseMipLevel; imb.subresourceRange.levelCount = _levelCount; - imb.subresourceRange.baseArrayLayer = 0; + imb.subresourceRange.baseArrayLayer = _baseArrayLayer; imb.subresourceRange.layerCount = _layerCount; vkCmdPipelineBarrier(_commandBuffer , VK_PIPELINE_STAGE_ALL_COMMANDS_BIT @@ -1261,7 +1271,9 @@ VK_IMPORT_DEVICE , VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT , VK_IMAGE_LAYOUT_UNDEFINED , VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL + , 0 , 1 + , 0 , 1 ); @@ -2618,25 +2630,29 @@ VK_IMPORT_DEVICE VkCommandBuffer copyCmd = beginNewCommand(); - bgfx::vk::setImageMemoryBarrier( - copyCmd + setImageMemoryBarrier( + copyCmd , dstImage , texture.m_aspectMask , VK_IMAGE_LAYOUT_UNDEFINED , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , 0 , 1 + , 0 , 1 - ); + ); - bgfx::vk::setImageMemoryBarrier( - copyCmd + setImageMemoryBarrier( + copyCmd , srcImage , texture.m_aspectMask , texture.m_currentImageLayout , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , 0 , 1 + , 0 , 1 - ); + ); VkImageCopy ic; @@ -2665,25 +2681,29 @@ VK_IMPORT_DEVICE ); // Transition destination image to general layout, which is the required layout for mapping the image memory later on - bgfx::vk::setImageMemoryBarrier( - copyCmd + setImageMemoryBarrier( + copyCmd , dstImage , texture.m_aspectMask , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL , VK_IMAGE_LAYOUT_GENERAL + , 0 , 1 + , 0 , 1 - ); + ); - bgfx::vk::setImageMemoryBarrier( - copyCmd + setImageMemoryBarrier( + copyCmd , srcImage , texture.m_aspectMask , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL , texture.m_currentImageLayout + , 0 , 1 + , 0 , 1 - ); + ); submitCommandAndWait(copyCmd); @@ -2823,24 +2843,28 @@ VK_IMPORT_DEVICE VkCommandBuffer copyCmd = beginNewCommand(); // Transition destination image to transfer destination layout - bgfx::vk::setImageMemoryBarrier( + setImageMemoryBarrier( copyCmd , dstImage , VK_IMAGE_ASPECT_COLOR_BIT , VK_IMAGE_LAYOUT_UNDEFINED , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , 0 , 1 + , 0 , 1 ); // Transition swapchain image from present to transfer source layout - bgfx::vk::setImageMemoryBarrier( + setImageMemoryBarrier( copyCmd , srcImage , VK_IMAGE_ASPECT_COLOR_BIT , VK_IMAGE_LAYOUT_PRESENT_SRC_KHR , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , 0 , 1 + , 0 , 1 ); @@ -2872,24 +2896,28 @@ VK_IMPORT_DEVICE ); // Transition destination image to general layout, which is the required layout for mapping the image memory later on - bgfx::vk::setImageMemoryBarrier( + setImageMemoryBarrier( copyCmd , dstImage , VK_IMAGE_ASPECT_COLOR_BIT , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL , VK_IMAGE_LAYOUT_GENERAL + , 0 , 1 + , 0 , 1 ); // Transition back the swap chain image after the blit is done - bgfx::vk::setImageMemoryBarrier( + setImageMemoryBarrier( copyCmd , srcImage , VK_IMAGE_ASPECT_COLOR_BIT , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL , VK_IMAGE_LAYOUT_PRESENT_SRC_KHR + , 0 , 1 + , 0 , 1 ); @@ -5968,7 +5996,9 @@ VK_DESTROY , m_aspectMask , VK_IMAGE_LAYOUT_UNDEFINED , VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + , 0 , m_numMips + , 0 , m_numSides ); @@ -6175,7 +6205,9 @@ VK_DESTROY , m_aspectMask , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , 0 , i - 1 + , 0 , 1 ); @@ -6210,7 +6242,9 @@ VK_DESTROY , m_aspectMask , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL , VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + , 0 , i - 1 + , 0 , 1 ); @@ -6224,7 +6258,9 @@ VK_DESTROY , m_aspectMask , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL , VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + , 0 , m_numMips - 1 + , 0 , 1 ); @@ -6266,7 +6302,9 @@ VK_DESTROY , m_aspectMask , m_currentImageLayout , newImageLayout + , 0 , m_numMips + , 0 , m_numSides ); @@ -6560,12 +6598,17 @@ VK_DESTROY m_commandBuffer = m_commandBuffers[m_backBufferColorIdx]; VK_CHECK(vkBeginCommandBuffer(m_commandBuffer, &cbbi) ); - setImageMemoryBarrier(m_commandBuffer + setImageMemoryBarrier( + m_commandBuffer , m_backBufferColorImage[m_backBufferColorIdx] , VK_IMAGE_ASPECT_COLOR_BIT , m_backBufferColorImageLayout[m_backBufferColorIdx] , VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL - , 1, 1); + , 0 + , 1 + , 0 + , 1 + ); m_backBufferColorImageLayout[m_backBufferColorIdx] = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; VkRenderPassBeginInfo rpbi; @@ -7432,7 +7475,9 @@ BX_UNUSED(presentMin, presentMax); , VK_IMAGE_ASPECT_COLOR_BIT , m_backBufferColorImageLayout[m_backBufferColorIdx] , VK_IMAGE_LAYOUT_PRESENT_SRC_KHR + , 0 , 1 + , 0 , 1 ); m_backBufferColorImageLayout[m_backBufferColorIdx] = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;