Skip to content
Permalink
Browse files

[Vulkan] PipelineState: Entry point name could be GC before used

  • Loading branch information
xen2 committed Jul 26, 2019
1 parent 04f6233 commit 7f293fad43028ced8ffc01e196ffab57bb53a55b
Showing with 7 additions and 4 deletions.
  1. +7 −4 sources/engine/Xenko.Graphics/Vulkan/PipelineState.Vulkan.cs
@@ -35,6 +35,9 @@ public partial class PipelineState
DynamicState.StencilReference,
};

// GLSL converter always outputs entry point main()
private static readonly byte[] defaultEntryPoint = Encoding.UTF8.GetBytes("main\0");

internal PipelineState(GraphicsDevice graphicsDevice, PipelineStateDescription pipelineStateDescription) : base(graphicsDevice)
{
Description = pipelineStateDescription.Clone();
@@ -52,6 +55,9 @@ private unsafe void Recreate()

// Create shader stages
Dictionary<int, string> inputAttributeNames;

// Note: important to pin this so that stages[x].Name is valid during this whole function
void* defaultEntryPointData = Interop.Fixed(defaultEntryPoint);
var stages = CreateShaderStages(Description, out inputAttributeNames);

var inputAttributes = new VertexInputAttributeDescription[Description.InputElements.Length];
@@ -399,16 +405,13 @@ private unsafe PipelineShaderStageCreateInfo[] CreateShaderStages(PipelineStateD

inputAttributeNames = null;

// GLSL converter always outputs entry point main()
var entryPoint = Encoding.UTF8.GetBytes("main\0");

for (int i = 0; i < stages.Length; i++)
{
var shaderBytecode = BinarySerialization.Read<ShaderInputBytecode>(stages[i].Data);
if (stages[i].Stage == ShaderStage.Vertex)
inputAttributeNames = shaderBytecode.InputAttributeNames;

fixed (byte* entryPointPointer = &entryPoint[0])
fixed (byte* entryPointPointer = &defaultEntryPoint[0])
fixed (byte* codePointer = &shaderBytecode.Data[0])
{
// Create shader module

0 comments on commit 7f293fa

Please sign in to comment.
You can’t perform that action at this time.