Skip to content

Commit

Permalink
Add some small fixes to AMD GPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
KredeGC committed Dec 23, 2023
1 parent b9060f5 commit 1ac940d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
19 changes: 19 additions & 0 deletions Mahakam/src/Platform/OpenGL/OpenGLShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,28 @@ namespace Mahakam
GLenum stage = ShaderStageToOpenGLStage(kv.first);
GLuint shader = glCreateShader(stage);

// AMD GPUs do not load SPIR-V shaders correctly in OpenGL
// https://github.com/TheCherno/Hazel/issues/440
// TODO: Make this an automatic check based on drivers?
#if true // ifdef MH_AMD_GPU
spirv_cross::CompilerGLSL glsl(kv.second);

spirv_cross::CompilerGLSL::Options options;
options.version = 430;
glsl.set_common_options(options);

std::string source = glsl.compile();

const char* sourceA[]{ source.c_str() };

MH_GL_CALL(glShaderSource(shader, 1, sourceA, 0));

MH_GL_CALL(glCompileShader(shader));
#else
MH_GL_CALL(glShaderBinary(1, &shader, GL_SHADER_BINARY_FORMAT_SPIR_V, kv.second.data(), (int)(kv.second.size() * sizeof(uint32_t))));

MH_GL_CALL(glSpecializeShaderARB(shader, "main", 0, nullptr, nullptr));
#endif

GLint isCompiled = 0;
MH_GL_CALL(glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled));
Expand Down
25 changes: 18 additions & 7 deletions Mahakam/src/Platform/OpenGL/OpenGLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,18 @@ namespace Mahakam
uint32_t size = 0;
for (uint32_t mip = 0; mip < maxMipLevels; ++mip)
{
int is_compressed;

MH_GL_CALL(glGetTexLevelParameteriv(targetID, mip, GL_TEXTURE_COMPRESSED, &is_compressed));

// TODO: Query glGetIntegerV(GL_NUM_COMPRESSED_TEXTURE_FORMATS) to determine DXT and BSTC support
//MH_GL_CALL(glGetTexLevelParameteriv(targetID, mip, GL_TEXTURE_INTERNAL_FORMAT, &internal_format));

if (compressed != is_compressed)
MH_WARN("Texture compression does not match preference! {0} != {1}", bool(is_compressed), compressed);

uint32_t mipSize;
if (compressed)
if (is_compressed)
{
int compressed_size;
MH_GL_CALL(glGetTexLevelParameteriv(targetID, mip, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_size));
Expand Down Expand Up @@ -404,8 +414,9 @@ namespace Mahakam

// Calculate the size
uint32_t bpp = TextureFormatToByteSize(m_Props.Format);
m_Size = CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, false, false, m_Props.Resolution, m_Props.Resolution);
m_TotalSize = 6 * CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, false, m_Props.Mipmaps, m_Props.Resolution, m_Props.Resolution);
// TODO: Support properly
//m_Size = CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, false, false, m_Props.Resolution, m_Props.Resolution);
//m_TotalSize = 6 * CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, false, m_Props.Mipmaps, m_Props.Resolution, m_Props.Resolution);

if (m_Props.Prefilter != TextureCubePrefilter::None)
CreatePrefilter(m_RendererID);
Expand Down Expand Up @@ -671,8 +682,8 @@ namespace Mahakam

// Calculate the size
uint32_t bpp = TextureFormatToByteSize(m_Props.Format);
m_Size = CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, m_Compressed, false, m_Props.Resolution, m_Props.Resolution);
m_TotalSize = 6 * CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, m_Compressed, m_Props.Mipmaps, m_Props.Resolution, m_Props.Resolution);
//m_Size = CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, m_Compressed, false, m_Props.Resolution, m_Props.Resolution);
//m_TotalSize = 6 * CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, m_Compressed, m_Props.Mipmaps, m_Props.Resolution, m_Props.Resolution);

MH_GL_CALL(glBindFramebuffer(GL_FRAMEBUFFER, 0));
MH_GL_CALL(glViewport(viewport[0], viewport[1], viewport[2], viewport[3]));
Expand Down Expand Up @@ -814,7 +825,7 @@ namespace Mahakam

// Calculate the size
uint32_t bpp = TextureFormatToByteSize(m_Props.Format);
m_Size = CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, m_Compressed, false, m_Props.Resolution, m_Props.Resolution);
m_TotalSize = 6 * CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, m_Compressed, m_Props.Mipmaps, m_Props.Resolution, m_Props.Resolution);
//m_Size = CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, m_Compressed, false, m_Props.Resolution, m_Props.Resolution);
//m_TotalSize = 6 * CalculateTextureByteSize(GL_TEXTURE_CUBE_MAP, bpp, m_Compressed, m_Props.Mipmaps, m_Props.Resolution, m_Props.Resolution);
}
}

0 comments on commit 1ac940d

Please sign in to comment.