Skip to content

Commit

Permalink
Unreal Engine DXVK workaround 3
Browse files Browse the repository at this point in the history
  • Loading branch information
nastys committed Mar 19, 2023
1 parent 9f68d74 commit d732aaf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,8 @@
_features.depthClamp = true;
_features.vertexPipelineStoresAndAtomics = true;
_features.fragmentStoresAndAtomics = true;
_features.geometryShader = true;
_features.shaderCullDistance = true;
#if MVK_XCODE_12
_features.shaderInt64 = mslVersionIsAtLeast(MTLLanguageVersion2_3);
#else
Expand Down
8 changes: 4 additions & 4 deletions MoltenVK/MoltenVK/Utility/MVKEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ void mvkSetConfig(const MVKConfiguration& mvkConfig);

/** Support full ImageView swizzles. Disabled by default. */
#ifndef MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE
# define MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE 0
# define MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE 1
#endif

/** Set the fastMathEnabled Metal Compiler option. Set to always use fast math by default. */
#ifndef MVK_CONFIG_FAST_MATH_ENABLED
# define MVK_CONFIG_FAST_MATH_ENABLED MVK_CONFIG_FAST_MATH_ALWAYS
# define MVK_CONFIG_FAST_MATH_ENABLED MVK_CONFIG_FAST_MATH_NEVER
#endif

/** Set the logging level: */
Expand Down Expand Up @@ -241,7 +241,7 @@ void mvkSetConfig(const MVKConfiguration& mvkConfig);
* By default, use Metal events, if availalble, on most platforms.
*/
#ifndef MVK_CONFIG_VK_SEMAPHORE_SUPPORT_STYLE
# define MVK_CONFIG_VK_SEMAPHORE_SUPPORT_STYLE MVK_CONFIG_VK_SEMAPHORE_SUPPORT_STYLE_METAL_EVENTS_WHERE_SAFE
# define MVK_CONFIG_VK_SEMAPHORE_SUPPORT_STYLE MVK_CONFIG_VK_SEMAPHORE_SUPPORT_STYLE_SINGLE_QUEUE
#endif
#ifndef MVK_ALLOW_METAL_EVENTS // Deprecated
# define MVK_ALLOW_METAL_EVENTS 1
Expand Down Expand Up @@ -282,7 +282,7 @@ void mvkSetConfig(const MVKConfiguration& mvkConfig);

/** Resume MVKDevice VK_ERROR_DEVICE_LOST errors that do not cause MVKPhysicalDevice errors. Disabled by default. */
#ifndef MVK_CONFIG_RESUME_LOST_DEVICE
# define MVK_CONFIG_RESUME_LOST_DEVICE 0
# define MVK_CONFIG_RESUME_LOST_DEVICE 1
#endif

/** Support Metal argument buffers. Disabled by default. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,27 @@ MVK_PUBLIC_SYMBOL bool SPIRVToMSLConverter::convert(SPIRVToMSLConversionConfigur
}
conversionResult.msl = pMSLCompiler->compile();

struct Patch
{
std::string find;
std::string replace;
};

Patch workaround_patches[] = {
{ std::string("t3.sample(s3, r0.yzwy.xyz).xyz"), std::string("r0.yzw") },
{ std::string("t5.sample(s5, r2.xyzx.xyz).xyz"), std::string("r2.xyz") },
};

for (Patch workaround_patch : workaround_patches)
{
std::string::size_type pos = 0u;
while((pos = conversionResult.msl.find(workaround_patch.find, pos)) != std::string::npos)
{
conversionResult.msl.replace(pos, workaround_patch.find.length(), workaround_patch.replace);
pos += workaround_patch.replace.length();
}
}

if (shouldLogMSL) { logSource(conversionResult.resultLog, conversionResult.msl, "MSL", "Converted"); }

#ifndef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
Expand Down

0 comments on commit d732aaf

Please sign in to comment.