unsafe void IManagerDevice.OnDeviceInit() { if (m_markerConstantBuffer == null) { m_markerConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyPostprocessMarkCascades.MarkerConstantBuffer", sizeof(MyMarkerConstants), usage: ResourceUsage.Dynamic); } if (m_psMarker == PixelShaderId.NULL) { m_psMarker = MyShaders.CreatePs("Shadows\\StencilMarker.hlsl"); } if (m_vsMarker == VertexShaderId.NULL) { m_vsMarker = MyShaders.CreateVs("Shadows\\StencilMarker.hlsl"); } if (m_psDrawCoverage == PixelShaderId.NULL) { m_psDrawCoverage = MyShaders.CreatePs("Shadows\\CascadeCoverage.hlsl"); } if (m_inputLayout == InputLayoutId.NULL) { m_inputLayout = MyShaders.CreateIL(m_vsMarker.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3)); } m_vertexBuffer = CreateVertexBuffer(); m_indexBuffer = CreateIndexBuffer(); }
public MyShaderBundle GetShaderBundle(MyRenderPassType pass, MyMeshDrawTechnique technique, MyInstanceLodState state, bool isCm, bool isNg, bool isExt) { // Modify input: switch (technique) { case MyMeshDrawTechnique.DECAL: case MyMeshDrawTechnique.DECAL_CUTOUT: case MyMeshDrawTechnique.DECAL_NOPREMULT: break; default: isCm = true; isNg = true; isExt = true; break; } MyShaderBundleKey key = new MyShaderBundleKey { Pass = pass, Technique = technique, IsCm = isCm, IsNg = isNg, IsExt = isExt, State = state, }; if (m_cache.ContainsKey(key)) { return(m_cache[key]); } MyVertexInputComponent[] viComps = GetVertexInputComponents(pass); VertexLayoutId vl = MyVertexLayouts.GetLayout(viComps); string vsFilepath = GetShaderDirpath(technique) + "Vertex.hlsl"; string psFilepath = GetShaderDirpath(technique) + "Pixel.hlsl"; List <ShaderMacro> macros = new List <ShaderMacro>(); AddMacrosForRenderingPass(pass, ref macros); AddMacrosForTechnique(technique, isCm, isNg, isExt, ref macros); AddMacrosVertexInputComponents(viComps, ref macros); AddMacrosState(state, ref macros); VertexShaderId vs = MyShaders.CreateVs(vsFilepath, macros.ToArray()); ((VertexShader)vs).DebugName = GetVsDebugName(pass, technique, macros); PixelShaderId ps = MyShaders.CreatePs(psFilepath, macros.ToArray()); ((PixelShader)ps).DebugName = GetPsDebugName(pass, technique, macros);; InputLayoutId il = MyShaders.CreateIL(vs.BytecodeId, vl); MyShaderBundle shaderBundle = new MyShaderBundle(ps, vs, il); m_cache.Add(key, shaderBundle); return(shaderBundle); }
internal static unsafe void Init() { //MyRender11.RegisterSettingsChangedListener(new OnSettingsChangedDelegate(RecreateShadersForSettings)); m_directionalEnvironmentLightPixel = MyShaders.CreatePs("Lighting/LightDir.hlsl"); m_directionalEnvironmentLightSample = MyShaders.CreatePs("Lighting/LightDir.hlsl", MyRender11.ShaderSampleFrequencyDefine()); m_pointlightsTiledPixel = MyShaders.CreatePs("Lighting/LightPoint.hlsl"); m_pointlightsTiledSample = MyShaders.CreatePs("Lighting/LightPoint.hlsl", MyRender11.ShaderSampleFrequencyDefine()); m_preparePointLights = MyShaders.CreateCs("Lighting/PrepareLights.hlsl", new[] { new ShaderMacro("NUMTHREADS", TILE_SIZE) }); m_spotlightProxyVs = MyShaders.CreateVs("Lighting/LightSpot.hlsl"); m_spotlightPsPixel = MyShaders.CreatePs("Lighting/LightSpot.hlsl"); m_spotlightPsSample = MyShaders.CreatePs("Lighting/LightSpot.hlsl", MyRender11.ShaderSampleFrequencyDefine()); m_spotlightProxyIl = MyShaders.CreateIL(m_spotlightProxyVs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION_PACKED)); m_pointlightCullHwBuffer = MyManagers.Buffers.CreateSrv( "MyLightRendering", MyRender11Constants.MAX_POINT_LIGHTS, sizeof(MyPointlightConstants), usage: ResourceUsage.Dynamic); }
private static void GenerateCombo(MyStringId materialId, MyStringId passId, MyShaderUnifiedFlags additionalFlags, MyShaderUnifiedFlags unsupportedFlags, MatCombos.Combo[] comboList1, MatCombos.Combo[] comboList2, float progress, OnShaderCacheProgressDelegate onShaderCacheProgress) { if (comboList1 == null || comboList1.Length == 0) { comboList1 = new[] { new MatCombos.Combo() } } ; if (comboList2 == null || comboList2.Length == 0) { comboList2 = new[] { new MatCombos.Combo() } } ; for (int k = 0; k < comboList1.Length; k++) { MyVertexInputComponentType[] vertexInput1 = comboList1[k].VertexInput; if (vertexInput1 == null) { vertexInput1 = new MyVertexInputComponentType[0]; } int[] vertexInputOrder1 = comboList1[k].VertexInputOrder; if (vertexInputOrder1 == null || vertexInputOrder1.Length != vertexInput1.Length) { vertexInputOrder1 = new int[vertexInput1.Length]; for (int x = 0; x < vertexInput1.Length; x++) { vertexInputOrder1[x] = x; } } MyShaderUnifiedFlags flags1 = ParseFlags(comboList1[k].FlagNames); if ((flags1 & unsupportedFlags) != 0) { continue; } // go through all combinations of shader flags for (int l = 0; l < comboList2.Length; l++) { MyVertexInputComponentType[] vertexInput2 = comboList2[l].VertexInput; if (vertexInput2 == null) { vertexInput2 = new MyVertexInputComponentType[0]; } int[] vertexInputOrder2 = comboList2[l].VertexInputOrder; if (vertexInputOrder2 == null || vertexInputOrder2.Length != vertexInput2.Length) { vertexInputOrder2 = new int[vertexInput2.Length]; for (int x = 0; x < vertexInput2.Length; x++) { vertexInputOrder2[x] = x; } } var vertexInput = vertexInput1.Concat(vertexInput2).ToArray(); var vertexInputOrder = vertexInputOrder1.Concat(vertexInputOrder2).ToArray(); Array.Sort(vertexInputOrder, vertexInput, m_intComparer); VertexLayoutId vertexLayout; if (vertexInput.Length != 0) { vertexLayout = MyVertexLayouts.GetLayout(vertexInput); } else { vertexLayout = MyVertexLayouts.Empty; } // return errors & skipped info string vsSource; string psSource; MyMaterialShaders.Preprocess(materialId, passId, vertexLayout.Info, out vsSource, out psSource); MyShaderUnifiedFlags flags = ParseFlags(comboList2[l].FlagNames) | flags1 | additionalFlags; if ((flags & unsupportedFlags) != 0) { continue; } var macros = MyMaterialShaders.GenerateMaterialShaderFlagMacros(flags); var descriptor = String.Format("{0}_{1}", materialId.ToString(), passId.ToString()); var vertexLayoutString = vertexLayout.Info.Components.GetString(); PreCompile(vsSource, macros, MyShadersDefines.Profiles.vs_5_0, descriptor, vertexLayoutString, progress, onShaderCacheProgress); PreCompile(psSource, macros, MyShadersDefines.Profiles.ps_5_0, descriptor, vertexLayoutString, progress, onShaderCacheProgress); macros.Add(m_globalMacros[0]); for (int m = 0; m < m_globalMacros.Length; m++) { macros[macros.Count - 1] = m_globalMacros[m]; //PreCompile(vsSource, macros, MyShadersDefines.Profiles.vs_5_0, descriptor, vertexLayoutString, progress, onShaderCacheProgress); PreCompile(psSource, macros, MyShadersDefines.Profiles.ps_5_0, descriptor, vertexLayoutString, progress, onShaderCacheProgress); } } } }
private static void GenerateCombo(MyStringId materialId, MyStringId passId, MyShaderUnifiedFlags additionalFlags, MyShaderUnifiedFlags unsupportedFlags, CacheGenerator.Combo[] comboList1, CacheGenerator.Combo[] comboList2, float progress, OnShaderCacheProgressDelegate onShaderCacheProgress) { if (comboList1 == null || comboList1.Length == 0) { comboList1 = new[] { new CacheGenerator.Combo() } } ; if (comboList2 == null || comboList2.Length == 0) { comboList2 = new[] { new CacheGenerator.Combo() } } ; for (int k = 0; k < comboList1.Length; k++) { MyVertexInputComponentType[] vertexInput1 = comboList1[k].VertexInput; if (vertexInput1 == null) { vertexInput1 = new MyVertexInputComponentType[0]; } int[] vertexInputOrder1 = comboList1[k].VertexInputOrder; if (vertexInputOrder1 == null || vertexInputOrder1.Length != vertexInput1.Length) { vertexInputOrder1 = new int[vertexInput1.Length]; for (int x = 0; x < vertexInput1.Length; x++) { vertexInputOrder1[x] = x; } } MyShaderUnifiedFlags flags1 = ParseFlags(comboList1[k].FlagNames); if ((flags1 & unsupportedFlags) != 0) { continue; } // go through all combinations of shader flags for (int l = 0; l < comboList2.Length; l++) { MyVertexInputComponentType[] vertexInput2 = comboList2[l].VertexInput; if (vertexInput2 == null) { vertexInput2 = new MyVertexInputComponentType[0]; } int[] vertexInputOrder2 = comboList2[l].VertexInputOrder; if (vertexInputOrder2 == null || vertexInputOrder2.Length != vertexInput2.Length) { vertexInputOrder2 = new int[vertexInput2.Length]; for (int x = 0; x < vertexInput2.Length; x++) { vertexInputOrder2[x] = x; } } var vertexInput = vertexInput1.Concat(vertexInput2).ToArray(); var vertexInputOrder = vertexInputOrder1.Concat(vertexInputOrder2).ToArray(); Array.Sort(vertexInputOrder, vertexInput, m_intComparer); VertexLayoutId vertexLayout; if (vertexInput.Length != 0) { vertexLayout = MyVertexLayouts.GetLayout(vertexInput); } else { vertexLayout = MyVertexLayouts.Empty; } MyShaderUnifiedFlags flags = ParseFlags(comboList2[l].FlagNames) | flags1 | additionalFlags; var macros = new List <ShaderMacro>(); macros.Add(MyMaterialShaders.GetRenderingPassMacro(passId.String)); MyMaterialShaders.AddMaterialShaderFlagMacrosTo(macros, flags); macros.AddRange(vertexLayout.Info.Macros); // return errors & skipped info MyMaterialShaderInfo sources; MyMaterialShaders.GetMaterialSources(materialId, out sources); if ((flags & unsupportedFlags) != 0) { continue; } var vertexLayoutString = vertexLayout.Info.Components.GetString(); string vsDescriptor = MyMaterialShaders.GetShaderDescriptor(sources.VertexShaderFilename, materialId.String, passId.String, vertexLayout); PreCompile(sources.VertexShaderFilepath, macros, MyShaderProfile.vs_5_0, vsDescriptor, vertexLayoutString, progress, onShaderCacheProgress); string psDescriptor = MyMaterialShaders.GetShaderDescriptor(sources.PixelShaderFilename, materialId.String, passId.String, vertexLayout); PreCompile(sources.PixelShaderFilepath, macros, MyShaderProfile.ps_5_0, psDescriptor, vertexLayoutString, progress, onShaderCacheProgress); macros.Add(m_globalMacros[0]); for (int m = 0; m < m_globalMacros.Length; m++) { macros[macros.Count - 1] = m_globalMacros[m]; //PreCompile(sources.VertexShaderFilepath, macros, MyShadersDefines.Profiles.vs_5_0, vsDescriptor, vertexLayoutString, progress, onShaderCacheProgress); PreCompile(sources.PixelShaderFilepath, macros, MyShaderProfile.ps_5_0, psDescriptor, vertexLayoutString, progress, onShaderCacheProgress); } } } }