Skip to content

Commit 389bd7c

Browse files
committed
Get entry_point from IRShaderReflection
1 parent 445333d commit 389bd7c

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/FlyCube/HLSLCompiler/MetalShaderConverter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ IRShaderStage GetShaderStage(ShaderType type)
2929

3030
} // namespace
3131

32-
std::vector<uint8_t> ConvertToMetalLibBytecode(ShaderType shader_type, const std::vector<uint8_t>& blob)
32+
std::vector<uint8_t> ConvertToMetalLibBytecode(ShaderType shader_type,
33+
const std::vector<uint8_t>& blob,
34+
std::string& entry_point)
3335
{
3436
IRCompiler* compiler = IRCompilerCreate();
3537
IRObject* dxil_obj = IRObjectCreateFromDXIL(blob.data(), blob.size(), IRBytecodeOwnershipNone);
@@ -55,6 +57,11 @@ std::vector<uint8_t> ConvertToMetalLibBytecode(ShaderType shader_type, const std
5557
std::vector<uint8_t> metal_lib_bytecode(metal_lib_size);
5658
IRMetalLibGetBytecode(metal_lib, metal_lib_bytecode.data());
5759

60+
IRShaderReflection* reflection = IRShaderReflectionCreate();
61+
IRObjectGetReflection(metal_ir, GetShaderStage(shader_type), reflection);
62+
entry_point = IRShaderReflectionGetEntryPointFunctionName(reflection);
63+
64+
IRShaderReflectionDestroy(reflection);
5865
IRMetalLibBinaryDestroy(metal_lib);
5966
IRObjectDestroy(metal_ir);
6067
IRObjectDestroy(dxil_obj);
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#pragma once
22
#include "Instance/BaseTypes.h"
33

4-
std::vector<uint8_t> ConvertToMetalLibBytecode(ShaderType shader_type, const std::vector<uint8_t>& blob);
4+
std::vector<uint8_t> ConvertToMetalLibBytecode(ShaderType shader_type,
5+
const std::vector<uint8_t>& blob,
6+
std::string& entry_point);

src/FlyCube/Shader/MTShader.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
: ShaderBase(blob, blob_type, shader_type)
1414
{
1515
#if defined(USE_METAL_SHADER_CONVERTER)
16-
std::string entry_point = "main";
17-
auto metal_lib_bytecode = ConvertToMetalLibBytecode(shader_type, blob);
16+
std::string entry_point;
17+
auto metal_lib_bytecode = ConvertToMetalLibBytecode(shader_type, blob, entry_point);
1818
dispatch_data_t metal_lib_data = dispatch_data_create(metal_lib_bytecode.data(), metal_lib_bytecode.size(), nullptr,
1919
DISPATCH_DATA_DESTRUCTOR_DEFAULT);
2020
NSError* error = nullptr;

0 commit comments

Comments
 (0)