Support 3D textures in OpenGL ES, add feature check

This commit is contained in:
Henrik Rydgård 2022-07-31 00:18:28 +02:00
parent 129f3fe997
commit 46d6b43618
9 changed files with 22 additions and 3 deletions

View File

@ -283,6 +283,7 @@ D3D11DrawContext::D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *de
caps_.framebufferCopySupported = true;
caps_.framebufferDepthBlitSupported = false;
caps_.framebufferDepthCopySupported = true;
caps_.texture3DSupported = true;
D3D11_FEATURE_DATA_D3D11_OPTIONS options{};
HRESULT result = device_->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &options, sizeof(options));

View File

@ -667,6 +667,8 @@ D3D9Context::D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, ID
caps_.framebufferCopySupported = false;
caps_.framebufferDepthBlitSupported = true;
caps_.framebufferDepthCopySupported = false;
caps_.texture3DSupported = true;
if (d3d) {
D3DDISPLAYMODE displayMode;
d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode);

View File

@ -383,6 +383,7 @@ void CheckGLExtensions() {
gl_extensions.EXT_shader_framebuffer_fetch = g_set_gl_extensions.count("GL_EXT_shader_framebuffer_fetch") != 0;
gl_extensions.ARM_shader_framebuffer_fetch = g_set_gl_extensions.count("GL_ARM_shader_framebuffer_fetch") != 0;
gl_extensions.OES_texture_float = g_set_gl_extensions.count("GL_OES_texture_float") != 0;
gl_extensions.OES_texture_3D = g_set_gl_extensions.count("GL_OES_texture_3D") != 0;
gl_extensions.EXT_buffer_storage = g_set_gl_extensions.count("GL_EXT_buffer_storage") != 0;
gl_extensions.EXT_clip_cull_distance = g_set_gl_extensions.count("GL_EXT_clip_cull_distance") != 0;
gl_extensions.APPLE_clip_distance = g_set_gl_extensions.count("GL_APPLE_clip_distance") != 0;

View File

@ -51,6 +51,7 @@ struct GLExtensions {
bool OES_vertex_array_object;
bool OES_copy_image;
bool OES_texture_float;
bool OES_texture_3D;
// ARB
bool ARB_framebuffer_object;

View File

@ -536,8 +536,10 @@ OpenGLContext::OpenGLContext() {
} else {
caps_.preferredDepthBufferFormat = DataFormat::D16;
}
caps_.texture3DSupported = gl_extensions.OES_texture_3D;
} else {
caps_.preferredDepthBufferFormat = DataFormat::D24_S8;
caps_.texture3DSupported = true;
}
caps_.framebufferBlitSupported = gl_extensions.NV_framebuffer_blit || gl_extensions.ARB_framebuffer_object;
caps_.framebufferDepthBlitSupported = caps_.framebufferBlitSupported;

View File

@ -787,6 +787,7 @@ VKContext::VKContext(VulkanContext *vulkan, bool splitSubmit)
caps_.framebufferDepthBlitSupported = false; // Can be checked for.
caps_.framebufferDepthCopySupported = true; // Will pretty much always be the case.
caps_.preferredDepthBufferFormat = DataFormat::D24_S8; // TODO: Ask vulkan.
caps_.texture3DSupported = true;
auto deviceProps = vulkan->GetPhysicalDeviceProperties(vulkan_->GetCurrentPhysicalDeviceIndex()).properties;
switch (deviceProps.vendorID) {

View File

@ -532,6 +532,8 @@ struct DeviceCaps {
bool framebufferDepthCopySupported;
bool framebufferDepthBlitSupported;
bool framebufferFetchSupported;
bool texture3DSupported;
std::string deviceName; // The device name to use when creating the thin3d context, to get the same one.
};

View File

@ -49,6 +49,8 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
highpTexcoord = highpFog;
}
bool texture3D = id.Bit(FS_BIT_3D_TEXTURE);
ReplaceAlphaType stencilToAlpha = static_cast<ReplaceAlphaType>(id.Bits(FS_BIT_STENCIL_TO_ALPHA, 2));
std::vector<const char*> gl_exts;
@ -62,6 +64,9 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
if (compat.framebufferFetchExtension) {
gl_exts.push_back(compat.framebufferFetchExtension);
}
if (gl_extensions.OES_texture_3D && texture3D) {
gl_exts.push_back("#extension GL_OES_texture_3D: enable");
}
}
ShaderWriter p(buffer, compat, ShaderStage::Fragment, gl_exts.data(), gl_exts.size());
@ -78,7 +83,6 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
bool enableColorDoubling = id.Bit(FS_BIT_COLOR_DOUBLE);
bool doTextureProjection = id.Bit(FS_BIT_DO_TEXTURE_PROJ);
bool doTextureAlpha = id.Bit(FS_BIT_TEXALPHA);
bool texture3D = id.Bit(FS_BIT_3D_TEXTURE);
bool flatBug = bugs.Has(Draw::Bugs::BROKEN_FLAT_IN_SHADER) && g_Config.bVendorBugChecksEnabled;
@ -277,7 +281,12 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
}
if (doTexture) {
WRITE(p, "uniform %s tex;\n", texture3D ? "sampler3D" : "sampler2D");
if (texture3D) {
// For whatever reason, a precision specifier is required here.
WRITE(p, "uniform lowp sampler3D tex;\n");
} else {
WRITE(p, "uniform sampler2D tex;\n");
}
}
if (readFramebufferTex) {

View File

@ -2097,7 +2097,7 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt
}
}
if (pure3D) {
if (pure3D && draw_->GetDeviceCaps().texture3DSupported) {
plan.depth = plan.levelsToLoad;
plan.scaleFactor = 1;
}