Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Laszlo Agocs
qtrhi
Commits
3b2ce2d3
Commit
3b2ce2d3
authored
Nov 22, 2018
by
Laszlo Agocs
Browse files
vk: Add some compressed texture plumbing
parent
eeb7d0c2
Changes
13
Hide whitespace changes
Inline
Side-by-side
examples/rhi/compressedtexture_bc1/compressedtexture_bc1.cpp
View file @
3b2ce2d3
...
...
@@ -155,7 +155,7 @@ static QByteArrayList loadBC1(const QString &filename, QSize *size)
void
Window
::
customInit
()
{
if
(
!
m_r
->
can
TextureFormat
Be
Supported
(
QRhiTexture
::
BC1
))
if
(
!
m_r
->
is
TextureFormatSupported
(
QRhiTexture
::
BC1
))
qFatal
(
"This backend does not support BC1"
);
d
.
vbuf
=
m_r
->
newBuffer
(
QRhiBuffer
::
Immutable
,
QRhiBuffer
::
VertexBuffer
,
sizeof
(
cube
));
...
...
src/rhi/qrhi.cpp
View file @
3b2ce2d3
...
...
@@ -350,9 +350,9 @@ QMatrix4x4 QRhi::clipSpaceCorrMatrix() const
return
d
->
clipSpaceCorrMatrix
();
}
bool
QRhi
::
can
TextureFormat
Be
Supported
(
QRhiTexture
::
Format
format
)
const
bool
QRhi
::
is
TextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
const
{
return
d
->
can
TextureFormat
Be
Supported
(
format
);
return
d
->
is
TextureFormatSupported
(
format
,
flags
);
}
QRhiGraphicsPipeline
*
QRhi
::
newGraphicsPipeline
()
...
...
src/rhi/qrhi.h
View file @
3b2ce2d3
...
...
@@ -261,6 +261,7 @@ struct Q_RHI_EXPORT QRhiTextureUploadDescription
struct
Q_RHI_EXPORT
Layer
{
struct
Q_RHI_EXPORT
MipLevel
{
MipLevel
()
{
}
// either a QImage or compressed data (not both)
MipLevel
(
const
QImage
&
image_
)
:
image
(
image_
)
{
}
MipLevel
(
const
QByteArray
&
compressedData_
)
:
compressedData
(
compressedData_
)
{
}
QImage
image
;
...
...
@@ -949,10 +950,10 @@ public:
QRhiTextureRenderTarget
::
Flags
flags
=
QRhiTextureRenderTarget
::
Flags
());
/*
Render to a QWindow (must be Vulkan/Metal/OpenGLSurface as appropriate):
Render
ing
to a QWindow (must be Vulkan/Metal/OpenGLSurface as appropriate):
Create a swapchain.
Call build() on the swapchain whenever the size is different than before.
Call release() on QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed.
Call build
OrResize
() on the swapchain whenever the size is different than before.
Call release() on
the swapchain on
QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed.
Then on every frame:
beginFrame(sc);
updates = nextResourceUpdateBatch();
...
...
@@ -961,8 +962,6 @@ public:
...
endPass(sc->currentFrameCommandBuffer());
endFrame(sc); // this queues the Present, begin/endFrame manages double buffering internally
Also works with a QVulkanWindow from startNextFrame(). Use the overload of build() in initSwapChainResources().
*/
QRhiSwapChain
*
newSwapChain
();
FrameOpResult
beginFrame
(
QRhiSwapChain
*
swapChain
);
...
...
@@ -977,8 +976,8 @@ public:
void
beginPass
(
QRhiRenderTarget
*
rt
,
QRhiCommandBuffer
*
cb
,
const
QRhiColorClearValue
&
colorClearValue
,
const
QRhiDepthStencilClearValue
&
depthStencilClearValue
,
const
QRhiColorClearValue
&
colorClearValue
,
// ignored when rt has PreserveColorContents
const
QRhiDepthStencilClearValue
&
depthStencilClearValue
,
// ignored when no ds attachment
QRhiResourceUpdateBatch
*
resourceUpdates
=
nullptr
);
void
endPass
(
QRhiCommandBuffer
*
cb
);
...
...
@@ -1031,10 +1030,7 @@ public:
// instead of just mvp, to their vertex shaders)
QMatrix4x4
clipSpaceCorrMatrix
()
const
;
// This is not isTextureFormatSupported: the result does not guarantee
// runtime availability, it only helps determining the guaranteed hopeless
// cases based on a static list from the backends.
bool
canTextureFormatBeSupported
(
QRhiTexture
::
Format
format
)
const
;
bool
isTextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
=
QRhiTexture
::
Flags
())
const
;
protected:
QRhi
();
...
...
src/rhi/qrhi_p.h
View file @
3b2ce2d3
...
...
@@ -115,7 +115,7 @@ public:
virtual
int
ubufAlignment
()
const
=
0
;
virtual
bool
isYUpInFramebuffer
()
const
=
0
;
virtual
QMatrix4x4
clipSpaceCorrMatrix
()
const
=
0
;
virtual
bool
can
TextureFormat
Be
Supported
(
QRhiTexture
::
Format
format
)
const
=
0
;
virtual
bool
is
TextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
const
=
0
;
QVector
<
QRhiResourceUpdateBatch
*>
resUpdPool
;
QBitArray
resUpdPoolMap
;
...
...
src/rhi/qrhid3d11.cpp
View file @
3b2ce2d3
...
...
@@ -228,8 +228,10 @@ QMatrix4x4 QRhiD3D11::clipSpaceCorrMatrix() const
return
m
;
}
bool
QRhiD3D11
::
can
TextureFormat
Be
Supported
(
QRhiTexture
::
Format
format
)
const
bool
QRhiD3D11
::
is
TextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
const
{
Q_UNUSED
(
flags
);
if
(
format
>=
QRhiTexture
::
ETC2_RGB8
&&
format
<=
QRhiTexture
::
ASTC_12x12
)
return
false
;
...
...
src/rhi/qrhid3d11_p.h
View file @
3b2ce2d3
...
...
@@ -407,7 +407,7 @@ public:
int
ubufAlignment
()
const
override
;
bool
isYUpInFramebuffer
()
const
override
;
QMatrix4x4
clipSpaceCorrMatrix
()
const
override
;
bool
can
TextureFormat
Be
Supported
(
QRhiTexture
::
Format
format
)
const
override
;
bool
is
TextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
const
override
;
void
create
();
void
destroy
();
...
...
src/rhi/qrhigles2.cpp
View file @
3b2ce2d3
...
...
@@ -178,8 +178,10 @@ QMatrix4x4 QRhiGles2::clipSpaceCorrMatrix() const
return
QMatrix4x4
();
// identity
}
bool
QRhiGles2
::
can
TextureFormat
Be
Supported
(
QRhiTexture
::
Format
format
)
const
bool
QRhiGles2
::
is
TextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
const
{
Q_UNUSED
(
flags
);
if
(
format
>=
QRhiTexture
::
BC1
&&
format
<=
QRhiTexture
::
BC7
)
return
false
;
...
...
src/rhi/qrhigles2_p.h
View file @
3b2ce2d3
...
...
@@ -365,7 +365,7 @@ public:
int
ubufAlignment
()
const
override
;
bool
isYUpInFramebuffer
()
const
override
;
QMatrix4x4
clipSpaceCorrMatrix
()
const
override
;
bool
can
TextureFormat
Be
Supported
(
QRhiTexture
::
Format
format
)
const
override
;
bool
is
TextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
const
override
;
void
ensureContext
(
QSurface
*
surface
=
nullptr
);
void
create
();
...
...
src/rhi/qrhimetal.mm
View file @
3b2ce2d3
...
...
@@ -254,8 +254,10 @@ QMatrix4x4 QRhiMetal::clipSpaceCorrMatrix() const
return
QMatrix4x4
();
// identity
}
bool
QRhiMetal
::
can
TextureFormat
Be
Supported
(
QRhiTexture
::
Format
format
)
const
bool
QRhiMetal
::
is
TextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
const
{
Q_UNUSED
(
flags
);
if
(
format
>=
QRhiTexture
::
BC1
&&
format
<=
QRhiTexture
::
BC7
)
return
false
;
...
...
src/rhi/qrhimetal_p.h
View file @
3b2ce2d3
...
...
@@ -296,7 +296,7 @@ public:
int
ubufAlignment
()
const
override
;
bool
isYUpInFramebuffer
()
const
override
;
QMatrix4x4
clipSpaceCorrMatrix
()
const
override
;
bool
can
TextureFormat
Be
Supported
(
QRhiTexture
::
Format
format
)
const
override
;
bool
is
TextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
const
override
;
void
create
();
void
destroy
();
...
...
src/rhi/qrhivulkan.cpp
View file @
3b2ce2d3
...
...
@@ -439,6 +439,57 @@ static inline VkFormat toVkTextureFormat(QRhiTexture::Format format, QRhiTexture
case
QRhiTexture
::
D32
:
return
VK_FORMAT_D32_SFLOAT
;
case
QRhiTexture
::
BC1
:
return
srgb
?
VK_FORMAT_BC1_RGB_SRGB_BLOCK
:
VK_FORMAT_BC1_RGB_UNORM_BLOCK
;
case
QRhiTexture
::
BC2
:
return
srgb
?
VK_FORMAT_BC2_SRGB_BLOCK
:
VK_FORMAT_BC2_UNORM_BLOCK
;
case
QRhiTexture
::
BC3
:
return
srgb
?
VK_FORMAT_BC3_SRGB_BLOCK
:
VK_FORMAT_BC3_UNORM_BLOCK
;
case
QRhiTexture
::
BC4
:
return
VK_FORMAT_BC4_UNORM_BLOCK
;
case
QRhiTexture
::
BC5
:
return
VK_FORMAT_BC5_UNORM_BLOCK
;
case
QRhiTexture
::
BC6H
:
return
VK_FORMAT_BC6H_UFLOAT_BLOCK
;
case
QRhiTexture
::
BC7
:
return
srgb
?
VK_FORMAT_BC7_SRGB_BLOCK
:
VK_FORMAT_BC7_UNORM_BLOCK
;
case
QRhiTexture
::
ETC2_RGB8
:
return
srgb
?
VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK
:
VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK
;
case
QRhiTexture
::
ETC2_RGB8A1
:
return
srgb
?
VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK
:
VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK
;
case
QRhiTexture
::
ETC2_RGBA8
:
return
srgb
?
VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK
:
VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_4x4
:
return
srgb
?
VK_FORMAT_ASTC_4x4_SRGB_BLOCK
:
VK_FORMAT_ASTC_4x4_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_5x4
:
return
srgb
?
VK_FORMAT_ASTC_5x4_SRGB_BLOCK
:
VK_FORMAT_ASTC_5x4_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_5x5
:
return
srgb
?
VK_FORMAT_ASTC_5x5_SRGB_BLOCK
:
VK_FORMAT_ASTC_5x5_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_6x5
:
return
srgb
?
VK_FORMAT_ASTC_6x5_SRGB_BLOCK
:
VK_FORMAT_ASTC_6x5_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_6x6
:
return
srgb
?
VK_FORMAT_ASTC_6x6_SRGB_BLOCK
:
VK_FORMAT_ASTC_6x6_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_8x5
:
return
srgb
?
VK_FORMAT_ASTC_8x5_SRGB_BLOCK
:
VK_FORMAT_ASTC_8x5_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_8x6
:
return
srgb
?
VK_FORMAT_ASTC_8x6_SRGB_BLOCK
:
VK_FORMAT_ASTC_8x6_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_8x8
:
return
srgb
?
VK_FORMAT_ASTC_8x8_SRGB_BLOCK
:
VK_FORMAT_ASTC_8x8_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_10x5
:
return
srgb
?
VK_FORMAT_ASTC_10x5_SRGB_BLOCK
:
VK_FORMAT_ASTC_10x5_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_10x6
:
return
srgb
?
VK_FORMAT_ASTC_10x6_SRGB_BLOCK
:
VK_FORMAT_ASTC_10x6_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_10x8
:
return
srgb
?
VK_FORMAT_ASTC_10x8_SRGB_BLOCK
:
VK_FORMAT_ASTC_10x8_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_10x10
:
return
srgb
?
VK_FORMAT_ASTC_10x10_SRGB_BLOCK
:
VK_FORMAT_ASTC_10x10_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_12x10
:
return
srgb
?
VK_FORMAT_ASTC_12x10_SRGB_BLOCK
:
VK_FORMAT_ASTC_12x10_UNORM_BLOCK
;
case
QRhiTexture
::
ASTC_12x12
:
return
srgb
?
VK_FORMAT_ASTC_12x12_SRGB_BLOCK
:
VK_FORMAT_ASTC_12x12_UNORM_BLOCK
;
default:
Q_UNREACHABLE
();
return
VK_FORMAT_R8G8B8A8_UNORM
;
...
...
@@ -1881,10 +1932,33 @@ QMatrix4x4 QRhiVulkan::clipSpaceCorrMatrix() const
return
m
;
}
bool
QRhiVulkan
::
can
TextureFormat
Be
Supported
(
QRhiTexture
::
Format
format
)
const
bool
QRhiVulkan
::
is
TextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
const
{
Q_UNUSED
(
format
);
return
true
;
VkPhysicalDeviceFeatures
features
;
f
->
vkGetPhysicalDeviceFeatures
(
physDev
,
&
features
);
// Note that with some SDKs the validation layer gives an odd warning about
// BC not being supported, even when our check here succeeds. Not much we
// can do about that.
if
(
format
>=
QRhiTexture
::
BC1
&&
format
<=
QRhiTexture
::
BC7
)
{
if
(
!
features
.
textureCompressionBC
)
return
false
;
}
if
(
format
>=
QRhiTexture
::
ETC2_RGB8
&&
format
<=
QRhiTexture
::
ETC2_RGBA8
)
{
if
(
!
features
.
textureCompressionETC2
)
return
false
;
}
if
(
format
>=
QRhiTexture
::
ASTC_4x4
&&
format
<=
QRhiTexture
::
ASTC_12x12
)
{
if
(
!
features
.
textureCompressionASTC_LDR
)
return
false
;
}
VkFormat
vkformat
=
toVkTextureFormat
(
format
,
flags
);
VkFormatProperties
props
;
f
->
vkGetPhysicalDeviceFormatProperties
(
physDev
,
vkformat
,
&
props
);
return
(
props
.
optimalTilingFeatures
&
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)
!=
0
;
}
QRhiRenderBuffer
*
QRhiVulkan
::
createRenderBuffer
(
QRhiRenderBuffer
::
Type
type
,
const
QSize
&
pixelSize
,
...
...
@@ -2623,7 +2697,7 @@ bool QVkTexture::build()
rhiD
->
f
->
vkGetPhysicalDeviceFormatProperties
(
rhiD
->
physDev
,
vkformat
,
&
props
);
const
bool
canSampleOptimal
=
(
props
.
optimalTilingFeatures
&
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
);
if
(
!
canSampleOptimal
)
{
qWarning
(
"Texture sampling not supported
?!"
);
qWarning
(
"Texture sampling
with optimal tiling for format %d
not supported
"
,
vkformat
);
return
false
;
}
...
...
src/rhi/qrhivulkan_p.h
View file @
3b2ce2d3
...
...
@@ -358,7 +358,7 @@ public:
int
ubufAlignment
()
const
override
;
bool
isYUpInFramebuffer
()
const
override
;
QMatrix4x4
clipSpaceCorrMatrix
()
const
override
;
bool
can
TextureFormat
Be
Supported
(
QRhiTexture
::
Format
format
)
const
override
;
bool
is
TextureFormatSupported
(
QRhiTexture
::
Format
format
,
QRhiTexture
::
Flags
flags
)
const
override
;
void
create
();
void
destroy
();
...
...
todo.txt
View file @
3b2ce2d3
vk: compressed textures (etc2, astc, bc)
gl, mtl: compressed textures
gl, mtl: srgb (tex, swapchain buf)
rhi without a window, fully offscreen
readbacks
mtl: cubemaps
mtl: targeting cubemap faces
mtl: cbuffers, textures, samplers set should be batched too
...
...
@@ -9,7 +11,6 @@ test cubemap
test cubemap face as target
cbuffer alignment rules - some things fail to translate (to hlsl e.g. with structs), which is fine but how to mitigate
resource import/export, what's the co-op story?
rhi without a window? fully offscreen?
copy-only passes for kicking off transfers early? (copy/transfer queue?)
copyimage (color and ds, no resolve or transforms here)
msaa offscreen (msaa texture? renderbuffer?)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment