mirror of
https://github.com/AxioDL/boo.git
synced 2025-07-07 05:36:02 +00:00
Minor Metal backend change
This commit is contained in:
parent
5f903c09ee
commit
9a7cadce3a
@ -1294,74 +1294,77 @@ IShaderPipeline* MetalDataFactory::Context::newShaderPipeline(const char* vertSo
|
|||||||
ZTest depthTest, bool depthWrite, bool colorWrite,
|
ZTest depthTest, bool depthWrite, bool colorWrite,
|
||||||
bool alphaWrite, CullMode culling)
|
bool alphaWrite, CullMode culling)
|
||||||
{
|
{
|
||||||
MetalData* d = MetalDataFactoryImpl::m_deferredData.get();
|
@autoreleasepool
|
||||||
MetalDataFactoryImpl& factory = static_cast<MetalDataFactoryImpl&>(m_parent);
|
|
||||||
MTLCompileOptions* compOpts = [MTLCompileOptions new];
|
|
||||||
compOpts.languageVersion = MTLLanguageVersion1_1;
|
|
||||||
NSError* err = nullptr;
|
|
||||||
|
|
||||||
XXH64_state_t hashState;
|
|
||||||
uint64_t hashes[2];
|
|
||||||
XXH64_reset(&hashState, 0);
|
|
||||||
XXH64_update(&hashState, vertSource, strlen(vertSource));
|
|
||||||
hashes[0] = XXH64_digest(&hashState);
|
|
||||||
XXH64_reset(&hashState, 0);
|
|
||||||
XXH64_update(&hashState, fragSource, strlen(fragSource));
|
|
||||||
hashes[1] = XXH64_digest(&hashState);
|
|
||||||
|
|
||||||
MetalShareableShader::Token vertShader;
|
|
||||||
MetalShareableShader::Token fragShader;
|
|
||||||
auto vertFind = factory.m_sharedShaders.find(hashes[0]);
|
|
||||||
if (vertFind != factory.m_sharedShaders.end())
|
|
||||||
{
|
{
|
||||||
vertShader = vertFind->second->lock();
|
MetalData* d = MetalDataFactoryImpl::m_deferredData.get();
|
||||||
}
|
MetalDataFactoryImpl& factory = static_cast<MetalDataFactoryImpl&>(m_parent);
|
||||||
else
|
MTLCompileOptions* compOpts = [MTLCompileOptions new];
|
||||||
{
|
compOpts.languageVersion = MTLLanguageVersion1_1;
|
||||||
id<MTLLibrary> vertShaderLib = [factory.m_ctx->m_dev newLibraryWithSource:@(vertSource)
|
NSError* err = nullptr;
|
||||||
options:compOpts
|
|
||||||
error:&err];
|
XXH64_state_t hashState;
|
||||||
if (!vertShaderLib)
|
uint64_t hashes[2];
|
||||||
|
XXH64_reset(&hashState, 0);
|
||||||
|
XXH64_update(&hashState, vertSource, strlen(vertSource));
|
||||||
|
hashes[0] = XXH64_digest(&hashState);
|
||||||
|
XXH64_reset(&hashState, 0);
|
||||||
|
XXH64_update(&hashState, fragSource, strlen(fragSource));
|
||||||
|
hashes[1] = XXH64_digest(&hashState);
|
||||||
|
|
||||||
|
MetalShareableShader::Token vertShader;
|
||||||
|
MetalShareableShader::Token fragShader;
|
||||||
|
auto vertFind = factory.m_sharedShaders.find(hashes[0]);
|
||||||
|
if (vertFind != factory.m_sharedShaders.end())
|
||||||
{
|
{
|
||||||
printf("%s\n", vertSource);
|
vertShader = vertFind->second->lock();
|
||||||
Log.report(logvisor::Fatal, "error compiling vert shader: %s", [[err localizedDescription] UTF8String]);
|
|
||||||
}
|
}
|
||||||
id<MTLFunction> vertFunc = [vertShaderLib newFunctionWithName:@"vmain"];
|
else
|
||||||
|
|
||||||
auto it =
|
|
||||||
factory.m_sharedShaders.emplace(std::make_pair(hashes[0],
|
|
||||||
std::make_unique<MetalShareableShader>(factory, hashes[0], vertFunc))).first;
|
|
||||||
vertShader = it->second->lock();
|
|
||||||
}
|
|
||||||
auto fragFind = factory.m_sharedShaders.find(hashes[1]);
|
|
||||||
if (fragFind != factory.m_sharedShaders.end())
|
|
||||||
{
|
|
||||||
fragShader = fragFind->second->lock();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
id<MTLLibrary> fragShaderLib = [factory.m_ctx->m_dev newLibraryWithSource:@(fragSource)
|
|
||||||
options:compOpts
|
|
||||||
error:&err];
|
|
||||||
if (!fragShaderLib)
|
|
||||||
{
|
{
|
||||||
printf("%s\n", fragSource);
|
id<MTLLibrary> vertShaderLib = [factory.m_ctx->m_dev newLibraryWithSource:@(vertSource)
|
||||||
Log.report(logvisor::Fatal, "error compiling frag shader: %s", [[err localizedDescription] UTF8String]);
|
options:compOpts
|
||||||
|
error:&err];
|
||||||
|
if (!vertShaderLib)
|
||||||
|
{
|
||||||
|
printf("%s\n", vertSource);
|
||||||
|
Log.report(logvisor::Fatal, "error compiling vert shader: %s", [[err localizedDescription] UTF8String]);
|
||||||
|
}
|
||||||
|
id<MTLFunction> vertFunc = [vertShaderLib newFunctionWithName:@"vmain"];
|
||||||
|
|
||||||
|
auto it =
|
||||||
|
factory.m_sharedShaders.emplace(std::make_pair(hashes[0],
|
||||||
|
std::make_unique<MetalShareableShader>(factory, hashes[0], vertFunc))).first;
|
||||||
|
vertShader = it->second->lock();
|
||||||
}
|
}
|
||||||
id<MTLFunction> fragFunc = [fragShaderLib newFunctionWithName:@"fmain"];
|
auto fragFind = factory.m_sharedShaders.find(hashes[1]);
|
||||||
|
if (fragFind != factory.m_sharedShaders.end())
|
||||||
|
{
|
||||||
|
fragShader = fragFind->second->lock();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
id<MTLLibrary> fragShaderLib = [factory.m_ctx->m_dev newLibraryWithSource:@(fragSource)
|
||||||
|
options:compOpts
|
||||||
|
error:&err];
|
||||||
|
if (!fragShaderLib)
|
||||||
|
{
|
||||||
|
printf("%s\n", fragSource);
|
||||||
|
Log.report(logvisor::Fatal, "error compiling frag shader: %s", [[err localizedDescription] UTF8String]);
|
||||||
|
}
|
||||||
|
id<MTLFunction> fragFunc = [fragShaderLib newFunctionWithName:@"fmain"];
|
||||||
|
|
||||||
auto it =
|
auto it =
|
||||||
factory.m_sharedShaders.emplace(std::make_pair(hashes[1],
|
factory.m_sharedShaders.emplace(std::make_pair(hashes[1],
|
||||||
std::make_unique<MetalShareableShader>(factory, hashes[1], fragFunc))).first;
|
std::make_unique<MetalShareableShader>(factory, hashes[1], fragFunc))).first;
|
||||||
fragShader = it->second->lock();
|
fragShader = it->second->lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
MetalShaderPipeline* retval = new MetalShaderPipeline(d, factory.m_ctx, std::move(vertShader), std::move(fragShader),
|
||||||
|
static_cast<const MetalVertexFormat*>(vtxFmt), targetSamples,
|
||||||
|
srcFac, dstFac, prim, depthTest, depthWrite,
|
||||||
|
colorWrite, alphaWrite, culling);
|
||||||
|
d->m_SPs.emplace_back(retval);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
MetalShaderPipeline* retval = new MetalShaderPipeline(d, factory.m_ctx, std::move(vertShader), std::move(fragShader),
|
|
||||||
static_cast<const MetalVertexFormat*>(vtxFmt), targetSamples,
|
|
||||||
srcFac, dstFac, prim, depthTest, depthWrite,
|
|
||||||
colorWrite, alphaWrite, culling);
|
|
||||||
d->m_SPs.emplace_back(retval);
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IShaderDataBinding*
|
IShaderDataBinding*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user