Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metal FeatureFamily change is now using incorrect enum values #3067

Open
EvilTrev opened this issue Mar 23, 2023 · 5 comments
Open

Metal FeatureFamily change is now using incorrect enum values #3067

EvilTrev opened this issue Mar 23, 2023 · 5 comments

Comments

@EvilTrev
Copy link

EvilTrev commented Mar 23, 2023

One of the more recent changes to renderer_mtl moved from MTLFeatureSet to MTLGPUFamily, however in many cases it is now using incorrect enum values and tests. For example here:

if (m_macOS11Runtime
|| [m_device supportsFamily:(MTLGPUFamily)4 /*MTLGPUFamily_iOS_GPUFamily3_v1*/])
{
	const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT;
	m_samplerDescriptor.compareFunction = 0 == cmpFunc
		? MTLCompareFunctionNever
		: s_cmpFunc[cmpFunc]
		;
}

Comparison sampling is supported from family "Common2" and "Apple3" up, and those enums are:

    MTLGPUFamilyCommon2 = 3002,
    MTLGPUFamilyApple3  = 1003,

As a result, samplers with comparisons do not work on iOS devices. There are other inconsistencies and errors in the metal renderer currently as a result of this change. I think it might be worth defining this enum (and maybe others) on platforms without the header to avoid magic numbers? Assuming that's the reason they are hardcoded constants?

@EvilTrev
Copy link
Author

EvilTrev commented Mar 23, 2023

Here are the fixes:

g_caps.limits.maxTextureSize = m_device.supportsFamily( (MTLGPUFamily)1003 /* iOS_GPUFamily3_v1 */) ? 16384 : 8192;

g_caps.supported |= m_device.supportsFamily( (MTLGPUFamily)1003 /* MTLGPUFamily_iOS_GPUFamily3_v1 */)
	? BGFX_CAPS_DRAW_INDIRECT
	: 0
	;

g_caps.supported |= m_device.supportsFamily( (MTLGPUFamily)1004 /* MTLGPUFamily_iOS_GPUFamily4_v1 */)
	? BGFX_CAPS_TEXTURE_CUBE_ARRAY
	: 0
	;

g_caps.supported |= m_device.supportsFamily( (MTLGPUFamily)2002 /* MTLGPUFamily_macOS_GPUFamily1_v2 */)
	? BGFX_CAPS_DRAW_INDIRECT
	: 0
	;

if (m_macOS11Runtime
	|| [m_device supportsFamily:(MTLGPUFamily)1003 /*MTLGPUFamilyApple3*/]
	|| [m_device supportsFamily:(MTLGPUFamily)3002 /*MTLGPUFamilyCommon2*/])
	{
		const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT;
		m_samplerDescriptor.compareFunction = 0 == cmpFunc
			? MTLCompareFunctionNever
			: s_cmpFunc[cmpFunc]
			;
	}

@bkaradzic
Copy link
Owner

Good catch, Just submit PR with fixes.

@EvilTrev
Copy link
Author

@bkaradzic my codebase isn't in a place where I can easily submit PRs unfortunately, so I'm just passing along the info for now :)

@bkaradzic
Copy link
Owner

bkaradzic added a commit that referenced this issue Apr 2, 2023
@fiserj
Copy link

fiserj commented Apr 23, 2023

@bkaradzic I think c43c447 and using the MTLGPUFamily enum values directly made the compilation fail on older versions of Xcode.

Would it make sense to add Xcode version detection like in MoltenVK (version macros defined here)?

jay3d pushed a commit to jay3d/bgfx that referenced this issue Apr 24, 2023
jay3d pushed a commit to jay3d/bgfx that referenced this issue Apr 24, 2023
docEdub added a commit to BabylonJS/bgfx that referenced this issue Jun 26, 2023
belegdol pushed a commit to belegdol/mame that referenced this issue Aug 27, 2023
belegdol pushed a commit to belegdol/mame that referenced this issue Aug 27, 2023
mipek pushed a commit to mipek/bgfx that referenced this issue Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants