mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-07 19:58:32 +09:00
[Fix, Test] (MG_Util, MG_Test): rename Photon-conflicting MSL identifiers
This commit is contained in:
@@ -2692,11 +2692,13 @@ out vec4 fragColor;
|
|||||||
float fma
|
float fma
|
||||||
(float a, float b, float c) { return a * b + c; }
|
(float a, float b, float c) { return a * b + c; }
|
||||||
float sinh(float x, float y) { return x * y; }
|
float sinh(float x, float y) { return x * y; }
|
||||||
|
float length_squared(vec3 value) { return dot(value, value); }
|
||||||
float round(float x) { return floor(x + 0.5); }
|
float round(float x) { return floor(x + 0.5); }
|
||||||
float min3(float a, float b, float c) { return min(min(a, b), c); }
|
float min3(float a, float b, float c) { return min(min(a, b), c); }
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
fragColor = vec4(fma(0.1, 0.2, 0.3), sinh(0.4, 2.0), round(1.25), min3(0.1, 0.2, 0.3));
|
fragColor = vec4(fma(0.1, 0.2, 0.3), sinh(0.4, 2.0), round(1.25),
|
||||||
|
min3(0.1, 0.2, 0.3) + length_squared(vec3(0.1, 0.2, 0.3)));
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
GLuint vs = CompileShaderChecked(GL_VERTEX_SHADER, vsSource);
|
GLuint vs = CompileShaderChecked(GL_VERTEX_SHADER, vsSource);
|
||||||
@@ -2707,6 +2709,7 @@ void main() {
|
|||||||
if (essl.find("fragColor") == String::npos) continue; // fragment module only
|
if (essl.find("fragColor") == String::npos) continue; // fragment module only
|
||||||
EXPECT_NE(essl.find("mg_fma("), String::npos) << essl;
|
EXPECT_NE(essl.find("mg_fma("), String::npos) << essl;
|
||||||
EXPECT_NE(essl.find("mg_sinh("), String::npos) << essl;
|
EXPECT_NE(essl.find("mg_sinh("), String::npos) << essl;
|
||||||
|
EXPECT_NE(essl.find("mg_length_squared("), String::npos) << essl;
|
||||||
EXPECT_NE(essl.find("mg_round("), String::npos) << essl;
|
EXPECT_NE(essl.find("mg_round("), String::npos) << essl;
|
||||||
EXPECT_NE(essl.find("mg_min3("), String::npos) << essl;
|
EXPECT_NE(essl.find("mg_min3("), String::npos) << essl;
|
||||||
EXPECT_EQ(essl.find("float fma("), String::npos) << essl;
|
EXPECT_EQ(essl.find("float fma("), String::npos) << essl;
|
||||||
|
|||||||
@@ -52,20 +52,24 @@ TEST_F(ProgramUtilTest, RenameSamplerFunctionParameterInSpirvPass) {
|
|||||||
OpEntryPoint Fragment %main "main" %outColor
|
OpEntryPoint Fragment %main "main" %outColor
|
||||||
OpExecutionMode %main OriginUpperLeft
|
OpExecutionMode %main OriginUpperLeft
|
||||||
OpName %globalSampler "sampler"
|
OpName %globalSampler "sampler"
|
||||||
|
OpName %globalNew "new"
|
||||||
OpName %paramSampler "sampler"
|
OpName %paramSampler "sampler"
|
||||||
|
OpName %paramNew "new"
|
||||||
OpName %main "main"
|
OpName %main "main"
|
||||||
OpDecorate %outColor Location 0
|
OpDecorate %outColor Location 0
|
||||||
%void = OpTypeVoid
|
%void = OpTypeVoid
|
||||||
%float = OpTypeFloat 32
|
%float = OpTypeFloat 32
|
||||||
%v4float = OpTypeVector %float 4
|
%v4float = OpTypeVector %float 4
|
||||||
%mainFn = OpTypeFunction %void
|
%mainFn = OpTypeFunction %void
|
||||||
%paramFn = OpTypeFunction %void %float
|
%paramFn = OpTypeFunction %void %float %float
|
||||||
%outV4Ptr = OpTypePointer Output %v4float
|
%outV4Ptr = OpTypePointer Output %v4float
|
||||||
%privatePtr = OpTypePointer Private %float
|
%privatePtr = OpTypePointer Private %float
|
||||||
%outColor = OpVariable %outV4Ptr Output
|
%outColor = OpVariable %outV4Ptr Output
|
||||||
%globalSampler = OpVariable %privatePtr Private
|
%globalSampler = OpVariable %privatePtr Private
|
||||||
|
%globalNew = OpVariable %privatePtr Private
|
||||||
%helper = OpFunction %void None %paramFn
|
%helper = OpFunction %void None %paramFn
|
||||||
%paramSampler = OpFunctionParameter %float
|
%paramSampler = OpFunctionParameter %float
|
||||||
|
%paramNew = OpFunctionParameter %float
|
||||||
%helperBody = OpLabel
|
%helperBody = OpLabel
|
||||||
OpReturn
|
OpReturn
|
||||||
OpFunctionEnd
|
OpFunctionEnd
|
||||||
@@ -91,6 +95,7 @@ TEST_F(ProgramUtilTest, RenameSamplerFunctionParameterInSpirvPass) {
|
|||||||
ASSERT_TRUE(tools.Disassemble(outputBinary, &outputText));
|
ASSERT_TRUE(tools.Disassemble(outputBinary, &outputText));
|
||||||
|
|
||||||
EXPECT_NE(outputText.find("\"MGL_COMPAT_sampler\""), String::npos);
|
EXPECT_NE(outputText.find("\"MGL_COMPAT_sampler\""), String::npos);
|
||||||
|
EXPECT_NE(outputText.find("\"MGL_COMPAT_new\""), String::npos);
|
||||||
|
|
||||||
SizeT exactSamplerNameCount = 0;
|
SizeT exactSamplerNameCount = 0;
|
||||||
SizeT searchOffset = 0;
|
SizeT searchOffset = 0;
|
||||||
@@ -99,6 +104,14 @@ TEST_F(ProgramUtilTest, RenameSamplerFunctionParameterInSpirvPass) {
|
|||||||
searchOffset += std::strlen("\"sampler\"");
|
searchOffset += std::strlen("\"sampler\"");
|
||||||
}
|
}
|
||||||
EXPECT_EQ(exactSamplerNameCount, 1u);
|
EXPECT_EQ(exactSamplerNameCount, 1u);
|
||||||
|
|
||||||
|
SizeT exactNewNameCount = 0;
|
||||||
|
searchOffset = 0;
|
||||||
|
while ((searchOffset = outputText.find("\"new\"", searchOffset)) != String::npos) {
|
||||||
|
++exactNewNameCount;
|
||||||
|
searchOffset += std::strlen("\"new\"");
|
||||||
|
}
|
||||||
|
EXPECT_EQ(exactNewNameCount, 1u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ProgramUtilTest, UnformattedFloatStorageImagesKeepIntegerAtomicImagesTyped) {
|
TEST_F(ProgramUtilTest, UnformattedFloatStorageImagesKeepIntegerAtomicImagesTyped) {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace MobileGL {
|
|||||||
"imageAtomicXor", "imageLoad", "imageSize", "imageStore", "imulExtended",
|
"imageAtomicXor", "imageLoad", "imageSize", "imageStore", "imulExtended",
|
||||||
"intBitsToFloat", "interpolateAtCentroid", "interpolateAtOffset",
|
"intBitsToFloat", "interpolateAtCentroid", "interpolateAtOffset",
|
||||||
"interpolateAtSample", "inverse", "inversesqrt", "isinf", "isnan",
|
"interpolateAtSample", "inverse", "inversesqrt", "isinf", "isnan",
|
||||||
"ldexp", "length", "lessThan", "lessThanEqual", "log", "log2",
|
"ldexp", "length", "length_squared", "lessThan", "lessThanEqual", "log", "log2",
|
||||||
"matrixCompMult", "max", "max3", "memoryBarrier",
|
"matrixCompMult", "max", "max3", "memoryBarrier",
|
||||||
"memoryBarrierAtomicCounter", "memoryBarrierBuffer", "memoryBarrierImage",
|
"memoryBarrierAtomicCounter", "memoryBarrierBuffer", "memoryBarrierImage",
|
||||||
"memoryBarrierShared", "mid3", "min", "min3", "mix", "mod", "modf",
|
"memoryBarrierShared", "mid3", "min", "min3", "mix", "mod", "modf",
|
||||||
|
|||||||
+15
-10
@@ -19,23 +19,27 @@ namespace MobileGL {
|
|||||||
namespace MG_Util {
|
namespace MG_Util {
|
||||||
namespace ShaderTranspiler {
|
namespace ShaderTranspiler {
|
||||||
namespace {
|
namespace {
|
||||||
constexpr const char* kConflictingName = "sampler";
|
const char* GetCompatName(StringView name) {
|
||||||
constexpr const char* kCompatName = "MGL_COMPAT_sampler";
|
if (name == "sampler") return "MGL_COMPAT_sampler";
|
||||||
|
if (name == "new") return "MGL_COMPAT_new";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
Bool IsNamedSamplerFunctionParameter(spvtools::opt::IRContext* context,
|
const char* GetConflictingFunctionParameterCompatName(spvtools::opt::IRContext* context,
|
||||||
spvtools::opt::Instruction& nameInst) {
|
spvtools::opt::Instruction& nameInst) {
|
||||||
if (nameInst.opcode() != spv::Op::OpName || nameInst.NumInOperands() < 2) {
|
if (nameInst.opcode() != spv::Op::OpName || nameInst.NumInOperands() < 2) {
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nameInst.GetInOperand(1).AsString() != kConflictingName) {
|
const char* compatName = GetCompatName(nameInst.GetInOperand(1).AsString());
|
||||||
return false;
|
if (compatName == nullptr) {
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* defUseMgr = context->get_def_use_mgr();
|
auto* defUseMgr = context->get_def_use_mgr();
|
||||||
const Uint32 targetId = nameInst.GetSingleWordInOperand(0);
|
const Uint32 targetId = nameInst.GetSingleWordInOperand(0);
|
||||||
const auto* target = defUseMgr->GetDef(targetId);
|
const auto* target = defUseMgr->GetDef(targetId);
|
||||||
return target != nullptr && target->opcode() == spv::Op::OpFunctionParameter;
|
return target != nullptr && target->opcode() == spv::Op::OpFunctionParameter ? compatName : nullptr;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@@ -44,12 +48,13 @@ namespace MobileGL {
|
|||||||
auto* irContext = context();
|
auto* irContext = context();
|
||||||
|
|
||||||
for (auto& debugInst : irContext->debugs2()) {
|
for (auto& debugInst : irContext->debugs2()) {
|
||||||
if (!IsNamedSamplerFunctionParameter(irContext, debugInst)) {
|
const char* compatName = GetConflictingFunctionParameterCompatName(irContext, debugInst);
|
||||||
|
if (compatName == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
debugInst.SetInOperand(
|
debugInst.SetInOperand(
|
||||||
1, spvtools::utils::MakeVector<spvtools::opt::Operand::OperandData>(kCompatName));
|
1, spvtools::utils::MakeVector<spvtools::opt::Operand::OperandData>(compatName));
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user