Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
qtrhi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Laszlo Agocs
qtrhi
Commits
9018aa1a
Commit
9018aa1a
authored
Dec 31, 2018
by
Laszlo Agocs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce QRhi::EnableProfiling and gather resource statistics
parent
c446d98d
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
226 additions
and
32 deletions
+226
-32
examples/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp
...ominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp
+1
-1
examples/rhi/multiwindow/multiwindow.cpp
examples/rhi/multiwindow/multiwindow.cpp
+1
-1
examples/rhi/multiwindow_threaded/multiwindow_threaded.cpp
examples/rhi/multiwindow_threaded/multiwindow_threaded.cpp
+1
-1
examples/rhi/plainqwindow_metal/main.cpp
examples/rhi/plainqwindow_metal/main.cpp
+1
-1
examples/rhi/shared/examplefw.h
examples/rhi/shared/examplefw.h
+1
-1
examples/rhi/shared/examplewindow.cpp
examples/rhi/shared/examplewindow.cpp
+1
-1
src/rhi/qrhi.cpp
src/rhi/qrhi.cpp
+15
-3
src/rhi/qrhi.h
src/rhi/qrhi.h
+9
-2
src/rhi/qrhi_p.h
src/rhi/qrhi_p.h
+11
-1
src/rhi/qrhid3d11.cpp
src/rhi/qrhid3d11.cpp
+12
-4
src/rhi/qrhid3d11_p.h
src/rhi/qrhid3d11_p.h
+1
-1
src/rhi/qrhigles2.cpp
src/rhi/qrhigles2.cpp
+10
-3
src/rhi/qrhigles2_p.h
src/rhi/qrhigles2_p.h
+1
-1
src/rhi/qrhimetal.mm
src/rhi/qrhimetal.mm
+38
-2
src/rhi/qrhimetal_p.h
src/rhi/qrhimetal_p.h
+1
-1
src/rhi/qrhiprofiler.cpp
src/rhi/qrhiprofiler.cpp
+71
-0
src/rhi/qrhiprofiler.h
src/rhi/qrhiprofiler.h
+6
-1
src/rhi/qrhiprofiler_p.h
src/rhi/qrhiprofiler_p.h
+19
-0
src/rhi/qrhivulkan.cpp
src/rhi/qrhivulkan.cpp
+23
-6
src/rhi/qrhivulkan_p.h
src/rhi/qrhivulkan_p.h
+2
-1
todo.txt
todo.txt
+1
-0
No files found.
examples/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp
View file @
9018aa1a
...
...
@@ -293,7 +293,7 @@ void Window::init()
m_ds
=
m_r
->
newRenderBuffer
(
QRhiRenderBuffer
::
DepthStencil
,
QSize
(),
// no need to set the size yet
1
,
QRhiRenderBuffer
::
ToBe
UsedWithSwapChainOnly
);
QRhiRenderBuffer
::
UsedWithSwapChainOnly
);
releasePool
<<
m_ds
;
m_sc
->
setWindow
(
this
);
m_sc
->
setDepthStencil
(
m_ds
);
...
...
examples/rhi/multiwindow/multiwindow.cpp
View file @
9018aa1a
...
...
@@ -401,7 +401,7 @@ void Window::init()
m_ds
=
r
.
r
->
newRenderBuffer
(
QRhiRenderBuffer
::
DepthStencil
,
QSize
(),
// no need to set the size yet
1
,
QRhiRenderBuffer
::
ToBe
UsedWithSwapChainOnly
);
QRhiRenderBuffer
::
UsedWithSwapChainOnly
);
m_releasePool
<<
m_ds
;
m_sc
->
setWindow
(
this
);
m_sc
->
setDepthStencil
(
m_ds
);
...
...
examples/rhi/multiwindow_threaded/multiwindow_threaded.cpp
View file @
9018aa1a
...
...
@@ -452,7 +452,7 @@ void Renderer::init()
m_ds
=
r
->
newRenderBuffer
(
QRhiRenderBuffer
::
DepthStencil
,
QSize
(),
// no need to set the size yet
1
,
QRhiRenderBuffer
::
ToBe
UsedWithSwapChainOnly
);
QRhiRenderBuffer
::
UsedWithSwapChainOnly
);
m_releasePool
<<
m_ds
;
m_sc
->
setWindow
(
window
);
m_sc
->
setDepthStencil
(
m_ds
);
...
...
examples/rhi/plainqwindow_metal/main.cpp
View file @
9018aa1a
...
...
@@ -65,7 +65,7 @@ private:
void
MetalWindow
::
init
()
{
QRhiMetalInitParams
params
;
m_r
=
QRhi
::
create
(
QRhi
::
Metal
,
&
params
);
m_r
=
QRhi
::
create
(
QRhi
::
Metal
,
&
params
,
QRhi
::
EnableProfiling
);
//setSampleCount(4); // enable 4x MSAA (except for the render-to-texture pass)
...
...
examples/rhi/shared/examplefw.h
View file @
9018aa1a
...
...
@@ -282,7 +282,7 @@ void Window::init()
m_ds
=
m_r
->
newRenderBuffer
(
QRhiRenderBuffer
::
DepthStencil
,
QSize
(),
// no need to set the size yet
1
,
QRhiRenderBuffer
::
ToBe
UsedWithSwapChainOnly
);
QRhiRenderBuffer
::
UsedWithSwapChainOnly
);
m_sc
->
setWindow
(
this
);
m_sc
->
setDepthStencil
(
m_ds
);
m_rp
=
m_sc
->
newCompatibleRenderPassDescriptor
();
...
...
examples/rhi/shared/examplewindow.cpp
View file @
9018aa1a
...
...
@@ -110,7 +110,7 @@ void ExampleWindow::init()
m_ds
=
m_r
->
newRenderBuffer
(
QRhiRenderBuffer
::
DepthStencil
,
QSize
(),
// no need to set the size yet
m_sampleCount
,
QRhiRenderBuffer
::
ToBe
UsedWithSwapChainOnly
);
QRhiRenderBuffer
::
UsedWithSwapChainOnly
);
m_sc
->
setWindow
(
this
);
m_sc
->
setDepthStencil
(
m_ds
);
m_sc
->
setSampleCount
(
m_sampleCount
);
...
...
src/rhi/qrhi.cpp
View file @
9018aa1a
...
...
@@ -193,6 +193,11 @@ QRhiImplementation::~QRhiImplementation()
qDeleteAll
(
resUpdPool
);
}
void
QRhiImplementation
::
sendVMemStatsToProfiler
()
{
// nothing to do in the default implementation
}
bool
QRhiImplementation
::
isCompressedFormat
(
QRhiTexture
::
Format
format
)
const
{
return
(
format
>=
QRhiTexture
::
BC1
&&
format
<=
QRhiTexture
::
BC7
)
...
...
@@ -373,7 +378,7 @@ QRhi::~QRhi()
}
}
QRhi
*
QRhi
::
create
(
Implementation
impl
,
QRhiInitParams
*
params
)
QRhi
*
QRhi
::
create
(
Implementation
impl
,
QRhiInitParams
*
params
,
Flags
flags
)
{
QScopedPointer
<
QRhi
>
r
(
new
QRhi
);
...
...
@@ -409,8 +414,15 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params)
break
;
}
if
(
r
->
d
&&
r
->
d
->
create
())
return
r
.
take
();
if
(
r
->
d
)
{
if
(
flags
.
testFlag
(
EnableProfiling
))
{
QRhiProfilerPrivate
*
profD
=
QRhiProfilerPrivate
::
get
(
&
r
->
d
->
profiler
);
profD
->
rhi
=
r
.
data
();
profD
->
rhiD
=
r
->
d
;
}
if
(
r
->
d
->
create
(
flags
))
return
r
.
take
();
}
return
nullptr
;
}
...
...
src/rhi/qrhi.h
View file @
9018aa1a
...
...
@@ -558,7 +558,7 @@ public:
};
enum
Flag
{
ToBe
UsedWithSwapChainOnly
=
1
<<
0
// use implicit winsys buffers, don't create anything (GL)
UsedWithSwapChainOnly
=
1
<<
0
// use implicit winsys buffers, don't create anything (GL)
};
Q_DECLARE_FLAGS
(
Flags
,
Flag
)
...
...
@@ -1084,6 +1084,11 @@ public:
Metal
};
enum
Flag
{
EnableProfiling
=
1
<<
0
};
Q_DECLARE_FLAGS
(
Flags
,
Flag
)
enum
FrameOpResult
{
FrameOpSuccess
=
0
,
FrameOpError
,
...
...
@@ -1098,7 +1103,7 @@ public:
~
QRhi
();
static
QRhi
*
create
(
Implementation
impl
,
QRhiInitParams
*
params
);
static
QRhi
*
create
(
Implementation
impl
,
QRhiInitParams
*
params
,
Flags
flags
=
Flags
()
);
/*
The underlying graphics resources are created when calling build() and
...
...
@@ -1250,6 +1255,8 @@ private:
QRhiImplementation
*
d
=
nullptr
;
};
Q_DECLARE_OPERATORS_FOR_FLAGS
(
QRhi
::
Flags
)
QT_END_NAMESPACE
#endif
src/rhi/qrhi_p.h
View file @
9018aa1a
...
...
@@ -50,6 +50,8 @@ QT_BEGIN_NAMESPACE
#define QRHI_RES(t, x) static_cast<t *>(x)
#define QRHI_RES_RHI(t) t *rhiD = static_cast<t *>(rhi)
#define QRHI_PROF QRhiProfilerPrivate *rhiP = rhi->profilerPrivateOrNull()
#define QRHI_PROF_F(f) for (bool qrhip_enabled = rhiP != nullptr; qrhip_enabled; qrhip_enabled = false) rhiP->f
class
QRhiReferenceRenderTarget
:
public
QRhiRenderTarget
{
...
...
@@ -62,7 +64,7 @@ class QRhiImplementation
public:
virtual
~
QRhiImplementation
();
virtual
bool
create
()
=
0
;
virtual
bool
create
(
QRhi
::
Flags
flags
)
=
0
;
virtual
void
destroy
()
=
0
;
virtual
QRhiGraphicsPipeline
*
createGraphicsPipeline
()
=
0
;
...
...
@@ -129,6 +131,8 @@ public:
virtual
bool
isFeatureSupported
(
QRhi
::
Feature
)
const
=
0
;
virtual
const
QRhiNativeHandles
*
nativeHandles
()
=
0
;
virtual
void
sendVMemStatsToProfiler
();
bool
isCompressedFormat
(
QRhiTexture
::
Format
format
)
const
;
void
compressedFormatInfo
(
QRhiTexture
::
Format
format
,
const
QSize
&
size
,
quint32
*
bpl
,
quint32
*
byteSize
,
...
...
@@ -136,6 +140,12 @@ public:
void
textureFormatInfo
(
QRhiTexture
::
Format
format
,
const
QSize
&
size
,
quint32
*
bpl
,
quint32
*
byteSize
)
const
;
QRhiProfilerPrivate
*
profilerPrivateOrNull
()
{
QRhiProfilerPrivate
*
p
=
QRhiProfilerPrivate
::
get
(
&
profiler
);
return
p
->
rhi
?
p
:
nullptr
;
}
protected:
QVector
<
QRhiResourceUpdateBatch
*>
resUpdPool
;
QBitArray
resUpdPoolMap
;
...
...
src/rhi/qrhid3d11.cpp
View file @
9018aa1a
...
...
@@ -91,11 +91,13 @@ static inline uint aligned(uint v, uint byteAlign)
return
(
v
+
byteAlign
-
1
)
&
~
(
byteAlign
-
1
);
}
bool
QRhiD3D11
::
create
()
bool
QRhiD3D11
::
create
(
QRhi
::
Flags
flags
)
{
uint
flags
=
0
;
Q_UNUSED
(
flags
);
uint
devFlags
=
0
;
if
(
debugLayer
)
f
lags
|=
D3D11_CREATE_DEVICE_DEBUG
;
devF
lags
|=
D3D11_CREATE_DEVICE_DEBUG
;
HRESULT
hr
=
CreateDXGIFactory2
(
0
,
IID_IDXGIFactory2
,
reinterpret_cast
<
void
**>
(
&
dxgiFactory
));
if
(
FAILED
(
hr
))
{
...
...
@@ -127,7 +129,7 @@ bool QRhiD3D11::create()
}
ID3D11DeviceContext
*
ctx
=
nullptr
;
HRESULT
hr
=
D3D11CreateDevice
(
adapterToUse
,
D3D_DRIVER_TYPE_UNKNOWN
,
nullptr
,
f
lags
,
HRESULT
hr
=
D3D11CreateDevice
(
adapterToUse
,
D3D_DRIVER_TYPE_UNKNOWN
,
nullptr
,
devF
lags
,
nullptr
,
0
,
D3D11_SDK_VERSION
,
&
dev
,
&
featureLevel
,
&
ctx
);
adapterToUse
->
Release
();
...
...
@@ -1385,6 +1387,9 @@ void QD3D11Buffer::release()
buffer
->
Release
();
buffer
=
nullptr
;
QRHI_PROF
;
QRHI_PROF_F
(
releaseBuffer
(
this
));
}
static
inline
uint
toD3DBufferUsage
(
QRhiBuffer
::
UsageFlags
usage
)
...
...
@@ -1426,6 +1431,9 @@ bool QD3D11Buffer::build()
hasPendingDynamicUpdates
=
false
;
}
QRHI_PROF
;
QRHI_PROF_F
(
newBuffer
(
this
,
roundedSize
,
1
,
m_type
==
Dynamic
?
1
:
0
));
generation
+=
1
;
return
true
;
}
...
...
src/rhi/qrhid3d11_p.h
View file @
9018aa1a
...
...
@@ -419,7 +419,7 @@ class QRhiD3D11 : public QRhiImplementation
public:
QRhiD3D11
(
QRhiInitParams
*
params
);
bool
create
()
override
;
bool
create
(
QRhi
::
Flags
flags
)
override
;
void
destroy
()
override
;
QRhiGraphicsPipeline
*
createGraphicsPipeline
()
override
;
...
...
src/rhi/qrhigles2.cpp
View file @
9018aa1a
...
...
@@ -91,8 +91,9 @@ bool QRhiGles2::ensureContext(QSurface *surface) const
return
true
;
}
bool
QRhiGles2
::
create
()
bool
QRhiGles2
::
create
(
QRhi
::
Flags
flags
)
{
Q_UNUSED
(
flags
);
Q_ASSERT
(
ctx
);
Q_ASSERT
(
fallbackSurface
);
...
...
@@ -1487,11 +1488,15 @@ void QGles2Buffer::release()
QRHI_RES_RHI
(
QRhiGles2
);
rhiD
->
releaseQueue
.
append
(
e
);
QRHI_PROF
;
QRHI_PROF_F
(
releaseBuffer
(
this
));
}
bool
QGles2Buffer
::
build
()
{
QRHI_RES_RHI
(
QRhiGles2
);
QRHI_PROF
;
if
(
buffer
)
release
();
...
...
@@ -1499,6 +1504,7 @@ bool QGles2Buffer::build()
if
(
m_usage
.
testFlag
(
QRhiBuffer
::
UniformBuffer
))
{
// special since we do not support uniform blocks in this backend
ubuf
.
resize
(
m_size
);
QRHI_PROF_F
(
newBuffer
(
this
,
m_size
,
0
,
1
));
return
true
;
}
...
...
@@ -1514,6 +1520,7 @@ bool QGles2Buffer::build()
rhiD
->
f
->
glBindBuffer
(
target
,
buffer
);
rhiD
->
f
->
glBufferData
(
target
,
m_size
,
nullptr
,
m_type
==
Dynamic
?
GL_DYNAMIC_DRAW
:
GL_STATIC_DRAW
);
QRHI_PROF_F
(
newBuffer
(
this
,
m_size
,
1
,
0
));
return
true
;
}
...
...
@@ -1546,11 +1553,11 @@ bool QGles2RenderBuffer::build()
if
(
renderbuffer
)
release
();
if
(
m_flags
.
testFlag
(
ToBe
UsedWithSwapChainOnly
))
{
if
(
m_flags
.
testFlag
(
UsedWithSwapChainOnly
))
{
if
(
m_type
==
DepthStencil
)
return
true
;
qWarning
(
"RenderBuffer:
ToBe
UsedWithSwapChainOnly is meaningless in combination with Color"
);
qWarning
(
"RenderBuffer: UsedWithSwapChainOnly is meaningless in combination with Color"
);
}
if
(
!
rhiD
->
ensureContext
())
...
...
src/rhi/qrhigles2_p.h
View file @
9018aa1a
...
...
@@ -441,7 +441,7 @@ class QRhiGles2 : public QRhiImplementation
public:
QRhiGles2
(
QRhiInitParams
*
params
);
bool
create
()
override
;
bool
create
(
QRhi
::
Flags
flags
)
override
;
void
destroy
()
override
;
QRhiGraphicsPipeline
*
createGraphicsPipeline
()
override
;
...
...
src/rhi/qrhimetal.mm
View file @
9018aa1a
...
...
@@ -229,8 +229,10 @@ static inline uint aligned(uint v, uint byteAlign)
return
(
v
+
byteAlign
-
1
)
&
~
(
byteAlign
-
1
);
}
bool
QRhiMetal
::
create
()
bool
QRhiMetal
::
create
(
QRhi
::
Flags
flags
)
{
Q_UNUSED
(
flags
);
if
(
!
importedDevice
)
d
->
dev
=
MTLCreateSystemDefaultDevice
();
...
...
@@ -771,6 +773,7 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
{
QMetalCommandBuffer
*
cbD
=
QRHI_RES
(
QMetalCommandBuffer
,
cb
);
QRhiResourceUpdateBatchPrivate
*
ud
=
QRhiResourceUpdateBatchPrivate
::
get
(
resourceUpdates
);
QRhiProfilerPrivate
*
rhiP
=
profilerPrivateOrNull
();
for
(
const
QRhiResourceUpdateBatchPrivate
::
DynamicBufferUpdate
&
u
:
ud
->
dynamicBufferUpdates
)
{
QMetalBuffer
*
bufD
=
QRHI_RES
(
QMetalBuffer
,
u
.
buf
);
...
...
@@ -817,6 +820,8 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
if
(
!
utexD
->
d
->
stagingBuf
[
currentFrameSlot
])
utexD
->
d
->
stagingBuf
[
currentFrameSlot
]
=
[
d
->
dev
newBufferWithLength
:
stagingSize
options
:
MTLResourceStorageModeShared
];
QRHI_PROF_F
(
newTextureStagingArea
(
utexD
,
currentFrameSlot
,
stagingSize
));
void
*
mp
=
[
utexD
->
d
->
stagingBuf
[
currentFrameSlot
]
contents
];
qsizetype
curOfs
=
0
;
for
(
int
layer
=
0
,
layerCount
=
u
.
desc
.
layers
.
count
();
layer
!=
layerCount
;
++
layer
)
{
...
...
@@ -917,6 +922,7 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
e
.
stagingBuffer
.
buffer
=
utexD
->
d
->
stagingBuf
[
currentFrameSlot
];
utexD
->
d
->
stagingBuf
[
currentFrameSlot
]
=
nil
;
d
->
releaseQueue
.
append
(
e
);
QRHI_PROF_F
(
releaseTextureStagingArea
(
utexD
,
currentFrameSlot
));
}
}
...
...
@@ -1202,6 +1208,9 @@ void QMetalBuffer::release()
QRHI_RES_RHI
(
QRhiMetal
);
rhiD
->
d
->
releaseQueue
.
append
(
e
);
QRHI_PROF
;
QRHI_PROF_F
(
releaseBuffer
(
this
));
}
bool
QMetalBuffer
::
build
()
...
...
@@ -1231,6 +1240,9 @@ bool QMetalBuffer::build()
}
}
QRHI_PROF
;
QRHI_PROF_F
(
newBuffer
(
this
,
roundedSize
,
m_type
==
Immutable
?
1
:
QMTL_FRAMES_IN_FLIGHT
,
0
));
lastActiveFrameSlot
=
-
1
;
generation
+=
1
;
return
true
;
...
...
@@ -1262,6 +1274,9 @@ void QMetalRenderBuffer::release()
QRHI_RES_RHI
(
QRhiMetal
);
rhiD
->
d
->
releaseQueue
.
append
(
e
);
QRHI_PROF
;
QRHI_PROF_F
(
releaseRenderBuffer
(
this
));
}
bool
QMetalRenderBuffer
::
build
()
...
...
@@ -1281,12 +1296,14 @@ bool QMetalRenderBuffer::build()
desc
.
resourceOptions
=
MTLResourceStorageModePrivate
;
desc
.
usage
=
MTLTextureUsageRenderTarget
;
bool
transientBacking
=
false
;
switch
(
m_type
)
{
case
DepthStencil
:
#ifdef Q_OS_MACOS
desc
.
storageMode
=
MTLStorageModePrivate
;
#else
desc
.
storageMode
=
MTLResourceStorageModeMemoryless
;
transientBacking
=
true
;
#endif
d
->
format
=
rhiD
->
d
->
dev
.
depth24Stencil8PixelFormatSupported
?
MTLPixelFormatDepth24Unorm_Stencil8
:
MTLPixelFormatDepth32Float_Stencil8
;
...
...
@@ -1305,6 +1322,9 @@ bool QMetalRenderBuffer::build()
d
->
tex
=
[
rhiD
->
d
->
dev
newTextureWithDescriptor
:
desc
];
[
desc
release
];
QRHI_PROF
;
QRHI_PROF_F
(
newRenderBuffer
(
this
,
transientBacking
,
true
));
lastActiveFrameSlot
=
-
1
;
generation
+=
1
;
return
true
;
...
...
@@ -1349,6 +1369,9 @@ void QMetalTexture::release()
QRHI_RES_RHI
(
QRhiMetal
);
rhiD
->
d
->
releaseQueue
.
append
(
e
);
QRHI_PROF
;
QRHI_PROF_F
(
releaseTexture
(
this
));
}
static
inline
MTLPixelFormat
toMetalTextureFormat
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
...
...
@@ -1509,7 +1532,8 @@ bool QMetalTexture::build()
MTLTextureDescriptor
*
desc
=
[[
MTLTextureDescriptor
alloc
]
init
];
if
(
m_flags
.
testFlag
(
CubeMap
))
const
bool
isCube
=
m_flags
.
testFlag
(
CubeMap
);
if
(
isCube
)
desc
.
textureType
=
MTLTextureTypeCube
;
else
desc
.
textureType
=
samples
>
1
?
MTLTextureType2DMultisample
:
MTLTextureType2D
;
...
...
@@ -1531,6 +1555,9 @@ bool QMetalTexture::build()
d
->
owns
=
true
;
nativeHandlesStruct
.
texture
=
d
->
tex
;
QRHI_PROF
;
QRHI_PROF_F
(
newTexture
(
this
,
true
,
mipLevelCount
,
isCube
?
6
:
1
,
samples
));
lastActiveFrameSlot
=
-
1
;
generation
+=
1
;
return
true
;
...
...
@@ -1550,6 +1577,9 @@ bool QMetalTexture::buildFrom(const QRhiNativeHandles *src)
d
->
owns
=
false
;
nativeHandlesStruct
.
texture
=
d
->
tex
;
QRHI_PROF
;
QRHI_PROF_F
(
newTexture
(
this
,
false
,
mipLevelCount
,
m_flags
.
testFlag
(
CubeMap
)
?
6
:
1
,
samples
));
lastActiveFrameSlot
=
-
1
;
generation
+=
1
;
return
true
;
...
...
@@ -2339,6 +2369,9 @@ void QMetalSwapChain::release()
QRHI_RES_RHI
(
QRhiMetal
);
rhiD
->
swapchains
.
remove
(
this
);
QRHI_PROF
;
QRHI_PROF_F
(
releaseSwapChain
(
this
));
}
QRhiCommandBuffer
*
QMetalSwapChain
::
currentFrameCommandBuffer
()
...
...
@@ -2470,6 +2503,9 @@ bool QMetalSwapChain::buildOrResize()
[
desc
release
];
}
QRHI_PROF
;
QRHI_PROF_F
(
resizeSwapChain
(
this
,
QMTL_FRAMES_IN_FLIGHT
,
samples
));
return
true
;
}
...
...
src/rhi/qrhimetal_p.h
View file @
9018aa1a
...
...
@@ -256,7 +256,7 @@ public:
QRhiMetal
(
QRhiInitParams
*
params
);
~
QRhiMetal
();
bool
create
()
override
;
bool
create
(
QRhi
::
Flags
flags
)
override
;
void
destroy
()
override
;
QRhiGraphicsPipeline
*
createGraphicsPipeline
()
override
;
...
...
src/rhi/qrhiprofiler.cpp
View file @
9018aa1a
...
...
@@ -35,6 +35,7 @@
****************************************************************************/
#include "qrhiprofiler_p.h"
#include "qrhi_p.h"
QT_BEGIN_NAMESPACE
...
...
@@ -48,4 +49,74 @@ QRhiProfiler::~QRhiProfiler()
delete
d
;
}
const
QRhiProfilerStream
*
QRhiProfiler
::
stream
()
const
{
return
nullptr
;
// ###
}
void
QRhiProfiler
::
addVMemAllocatorStats
()
{
if
(
d
->
rhiD
)
d
->
rhiD
->
sendVMemStatsToProfiler
();
}
void
QRhiProfilerPrivate
::
newBuffer
(
QRhiBuffer
*
buf
,
size_t
realSize
,
int
backingGpuBufCount
,
int
backingCpuBufCount
)
{
}
void
QRhiProfilerPrivate
::
releaseBuffer
(
QRhiBuffer
*
buf
)
{
}
void
QRhiProfilerPrivate
::
newBufferStagingArea
(
QRhiBuffer
*
buf
,
int
slot
,
size_t
size
)
{
}
void
QRhiProfilerPrivate
::
releaseBufferStagingArea
(
QRhiBuffer
*
buf
,
int
slot
)
{
}
void
QRhiProfilerPrivate
::
newRenderBuffer
(
QRhiRenderBuffer
*
rb
,
bool
transientBacking
,
bool
winSysBacking
)
{
// calc approx size
}
void
QRhiProfilerPrivate
::
releaseRenderBuffer
(
QRhiRenderBuffer
*
rb
)
{
}
void
QRhiProfilerPrivate
::
newTexture
(
QRhiTexture
*
tex
,
bool
owns
,
int
mipCount
,
int
layerCount
,
int
sampleCount
)
{
// size_t approxSize = 0;
// for (int i = 0; i < mipLevelCount; ++i) {
// quint32 byteSize = 0;
// rhiD->textureFormatInfo(m_format, size, nullptr, &byteSize);
// approxSize += byteSize;
// }
// const int layerCount = isCube ? 6 : 1;
// approxSize *= layerCount;
}
void
QRhiProfilerPrivate
::
releaseTexture
(
QRhiTexture
*
tex
)
{
}
void
QRhiProfilerPrivate
::
newTextureStagingArea
(
QRhiTexture
*
tex
,
int
slot
,
size_t
size
)
{
}
void
QRhiProfilerPrivate
::
releaseTextureStagingArea
(
QRhiTexture
*
tex
,
int
slot
)
{
}
void
QRhiProfilerPrivate
::
resizeSwapChain
(
QRhiSwapChain
*
sc
,
int
bufferCount
,
int
sampleCount
)
{
// calc approx size
}
void
QRhiProfilerPrivate
::
releaseSwapChain
(
QRhiSwapChain
*
sc
)
{
}
QT_END_NAMESPACE
src/rhi/qrhiprofiler.h
View file @
9018aa1a
...
...
@@ -37,11 +37,12 @@
#ifndef QRHIPROFILER_H
#define QRHIPROFILER_H
#include <QtRhi/q
trhiglobal
.h>
#include <QtRhi/q
rhi
.h>
QT_BEGIN_NAMESPACE
class
QRhiProfilerPrivate
;
class
QRhiProfilerStream
;
class
Q_RHI_EXPORT
QRhiProfiler
{
...
...
@@ -49,6 +50,10 @@ public:
QRhiProfiler
();
~
QRhiProfiler
();
const
QRhiProfilerStream
*
stream
()
const
;
void
addVMemAllocatorStats
();
private:
QRhiProfilerPrivate
*
d
;
friend
class
QRhiProfilerPrivate
;
...
...
src/rhi/qrhiprofiler_p.h
View file @
9018aa1a
...
...
@@ -50,6 +50,25 @@ class QRhiProfilerPrivate
{
public:
static
QRhiProfilerPrivate
*
get
(
QRhiProfiler
*
p
)
{
return
p
->
d
;
}
void
newBuffer
(
QRhiBuffer
*
buf
,
size_t
realSize
,
int
backingGpuBufCount
,
int
backingCpuBufCount
);
void
releaseBuffer
(
QRhiBuffer
*
buf
);
void
newBufferStagingArea
(
QRhiBuffer
*
buf
,
int
slot
,
size_t
size
);
void
releaseBufferStagingArea
(
QRhiBuffer
*
buf
,
int
slot
);
void
newRenderBuffer
(
QRhiRenderBuffer
*
rb
,
bool
transientBacking
,
bool
winSysBacking
);
void
releaseRenderBuffer
(
QRhiRenderBuffer
*
rb
);
void
newTexture
(
QRhiTexture
*
tex
,
bool
owns
,
int
mipCount
,
int
layerCount
,
int
sampleCount
);
void
releaseTexture
(
QRhiTexture
*
tex
);
void
newTextureStagingArea
(
QRhiTexture
*
tex
,
int
slot
,
size_t
size
);
void
releaseTextureStagingArea
(
QRhiTexture
*
tex
,
int
slot
);
void
resizeSwapChain
(
QRhiSwapChain
*
sc
,
int
bufferCount
,
int
sampleCount
);
void
releaseSwapChain
(
QRhiSwapChain
*
sc
);
QRhi
*
rhi
=
nullptr
;
QRhiImplementation
*
rhiD
=
nullptr
;
};
QT_END_NAMESPACE
...
...
src/rhi/qrhivulkan.cpp
View file @
9018aa1a
...
...
@@ -172,8 +172,9 @@ QRhiVulkan::QRhiVulkan(QRhiInitParams *params)
maybeWindow
=
vkparams
->
window
;
// may be null
}
bool
QRhiVulkan
::
create
()
bool
QRhiVulkan
::
create
(
QRhi
::
Flags
flags
)
{
Q_UNUSED
(
flags
);
Q_ASSERT
(
inst
);
globalVulkanInstance
=
inst
;
// assume this will not change during the lifetime of the entire application
...
...
@@ -1947,6 +1948,7 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
{
QVkCommandBuffer
*
cbD
=
QRHI_RES
(
QVkCommandBuffer
,
cb
);
QRhiResourceUpdateBatchPrivate
*
ud
=
QRhiResourceUpdateBatchPrivate
::
get
(
resourceUpdates
);
QRhiProfilerPrivate
*
rhiP
=
profilerPrivateOrNull
();
for
(
const
QRhiResourceUpdateBatchPrivate
::
DynamicBufferUpdate
&
u
:
ud
->
dynamicBufferUpdates
)
{
QVkBuffer
*
bufD
=
QRHI_RES
(
QVkBuffer
,
u
.
buf
);
...
...
@@ -1976,6 +1978,7 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
&
bufD
->
stagingBuffers
[
currentFrameSlot
],
&
allocation
,
nullptr
);
if
(
err
==
VK_SUCCESS
)
{
bufD
->
stagingAllocations
[
currentFrameSlot
]
=
allocation
;
QRHI_PROF_F
(
newBufferStagingArea
(
bufD
,
currentFrameSlot
,
bufD
->
m_size
));
}
else
{
qWarning
(
"Failed to create staging buffer of size %d: %d"
,
bufD
->
m_size
,
err
);
continue
;
...
...
@@ -2012,6 +2015,7 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
bufD
->
stagingBuffers
[
currentFrameSlot
]
=
VK_NULL_HANDLE
;
bufD
->
stagingAllocations
[
currentFrameSlot
]
=
nullptr
;
releaseQueue
.
append
(
e
);
QRHI_PROF_F
(
releaseBufferStagingArea
(
bufD
,
currentFrameSlot
));
}
}
...
...
@@ -2642,6 +2646,13 @@ const QRhiNativeHandles *QRhiVulkan::nativeHandles()
return
&
nativeHandlesStruct
;
}
void
QRhiVulkan
::
sendVMemStatsToProfiler
()
{
VmaStats
stats
;
vmaCalculateStats
(
toVmaAllocator
(
allocator
),
&
stats
);
// ###
}
QRhiRenderBuffer
*
QRhiVulkan
::
createRenderBuffer
(
QRhiRenderBuffer
::
Type
type
,
const
QSize
&
pixelSize
,
int
sampleCount
,
QRhiRenderBuffer
::
Flags
flags
)
{
...
...
@@ -3220,6 +3231,9 @@ void QVkBuffer::release()
QRHI_RES_RHI
(
QRhiVulkan
);
rhiD
->
releaseQueue
.
append
(
e
);
QRHI_PROF
;
QRHI_PROF_F
(
releaseBuffer
(
this
));
}
bool
QVkBuffer
::
build
()
...
...
@@ -3261,14 +3275,17 @@ bool QVkBuffer::build()
}
}
if
(
err
==
VK_SUCCESS
)
{
lastActiveFrameSlot
=
-
1
;
generation
+=
1
;
return
true
;
}
else
{
if
(
err
!=
VK_SUCCESS
)
{
qWarning
(
"Failed to create buffer: %d"
,
err
);
return
false
;
}