Skip to content

Commit fcaa42c

Browse files
author
Unity Technologies
committed
Unity 2018.2.0a8 C# reference source code
1 parent 7331a93 commit fcaa42c

File tree

54 files changed

+576
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+576
-254
lines changed

Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
using System.Collections.Generic;
99
using System.Linq;
1010
using UnityEditor.Build.Reporting;
11-
using RequiredByNativeCodeAttribute = UnityEngine.Scripting.RequiredByNativeCodeAttribute;
11+
using UnityEditor.Rendering;
12+
using UnityEngine.Scripting;
1213

1314
namespace UnityEditor.Build
1415
{
@@ -60,6 +61,11 @@ public interface IActiveBuildTargetChanged : IOrderedCallback
6061
void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget);
6162
}
6263

64+
public interface IPreprocessShaders : IOrderedCallback
65+
{
66+
void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data);
67+
}
68+
6369
internal static class BuildPipelineInterfaces
6470
{
6571
internal class Processors
@@ -76,6 +82,7 @@ internal class Processors
7682

7783
public List<IFilterBuildAssemblies> filterBuildAssembliesProcessor;
7884
public List<IActiveBuildTargetChanged> buildTargetProcessors;
85+
public List<IPreprocessShaders> shaderProcessors;
7986
}
8087

8188
private static Processors m_Processors;
@@ -97,6 +104,7 @@ internal enum BuildCallbacks
97104
SceneProcessors = 2,
98105
BuildTargetProcessors = 4,
99106
FilterAssembliesProcessors = 8,
107+
ShaderProcessors = 16
100108
}
101109

102110
//common comparer for all callback types
@@ -168,6 +176,8 @@ internal static void InitializeBuildCallbacks(BuildCallbacks findFlags)
168176
bool findSceneProcessors = (findFlags & BuildCallbacks.SceneProcessors) == BuildCallbacks.SceneProcessors;
169177
bool findTargetProcessors = (findFlags & BuildCallbacks.BuildTargetProcessors) == BuildCallbacks.BuildTargetProcessors;
170178
bool findFilterProcessors = (findFlags & BuildCallbacks.FilterAssembliesProcessors) == BuildCallbacks.FilterAssembliesProcessors;
179+
bool findShaderProcessors = (findFlags & BuildCallbacks.ShaderProcessors) == BuildCallbacks.ShaderProcessors;
180+
171181
var postProcessBuildAttributeParams = new Type[] { typeof(BuildTarget), typeof(string) };
172182
foreach (var t in EditorAssemblies.GetAllTypesWithInterface<IOrderedCallback>())
173183
{
@@ -200,6 +210,11 @@ internal static void InitializeBuildCallbacks(BuildCallbacks findFlags)
200210
{
201211
AddToListIfTypeImplementsInterface(t, ref instance, ref processors.filterBuildAssembliesProcessor);
202212
}
213+
214+
if (findShaderProcessors)
215+
{
216+
AddToListIfTypeImplementsInterface(t, ref instance, ref processors.shaderProcessors);
217+
}
203218
}
204219

205220
if (findBuildProcessors)
@@ -232,6 +247,8 @@ internal static void InitializeBuildCallbacks(BuildCallbacks findFlags)
232247
processors.sceneProcessorsWithReport.Sort(CompareICallbackOrder);
233248
if (processors.filterBuildAssembliesProcessor != null)
234249
processors.filterBuildAssembliesProcessor.Sort(CompareICallbackOrder);
250+
if (processors.shaderProcessors != null)
251+
processors.shaderProcessors.Sort(CompareICallbackOrder);
235252
}
236253

237254
internal static bool ValidateType<T>(Type t)
@@ -391,6 +408,27 @@ internal static void OnActiveBuildTargetChanged(BuildTarget previousPlatform, Bu
391408
}
392409
}
393410

411+
[RequiredByNativeCode]
412+
internal static ShaderCompilerData[] OnPreprocessShaders(Shader shader, ShaderSnippetData snippet, ShaderCompilerData[] data)
413+
{
414+
var dataList = data.ToList();
415+
if (processors.shaderProcessors != null)
416+
{
417+
foreach (IPreprocessShaders abtc in processors.shaderProcessors)
418+
{
419+
try
420+
{
421+
abtc.OnProcessShader(shader, snippet, dataList);
422+
}
423+
catch (Exception e)
424+
{
425+
Debug.LogException(e);
426+
}
427+
}
428+
}
429+
return dataList.ToArray();
430+
}
431+
394432
[RequiredByNativeCode]
395433
internal static string[] FilterAssembliesIncludedInBuild(BuildOptions buildOptions, string[] assemblies)
396434
{
@@ -432,6 +470,7 @@ internal static void CleanupBuildCallbacks()
432470
processors.buildPostprocessorsWithReport = null;
433471
processors.sceneProcessorsWithReport = null;
434472
processors.filterBuildAssembliesProcessor = null;
473+
processors.shaderProcessors = null;
435474
previousFlags = BuildCallbacks.None;
436475
}
437476
}

Editor/Mono/Collab/CollabHistoryWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public void UpdateState(HistoryState state, bool force)
161161
if (state == m_State && !force)
162162
return;
163163

164+
m_State = state;
164165
switch (state)
165166
{
166167
case HistoryState.Ready:
@@ -171,7 +172,6 @@ public void UpdateState(HistoryState state, bool force)
171172
return;
172173
}
173174

174-
m_State = state;
175175
m_Container.Clear();
176176
m_Container.Add(m_Views[m_State]);
177177
}

Editor/Mono/Collab/Presenters/CollabHistoryPresenter.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ public void OnWindowEnabled()
4646
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
4747
m_Service.FetchRevisionsCallback += OnFetchRevisions;
4848

49-
if (Collab.instance.IsConnected())
50-
{
51-
m_ConnectState = UnityConnect.instance.GetConnectInfo();
52-
}
53-
// Copy the initialized fields of the collab info, even if the instance hasn't connected yet.
49+
m_ConnectState = UnityConnect.instance.GetConnectInfo();
5450
m_CollabState = Collab.instance.GetCollabInfo();
5551

5652
m_Window.revisionActionsEnabled = !EditorApplication.isPlayingOrWillChangePlaymode;

Editor/Mono/EditorGUIUtility.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ static Texture2D LoadGeneratedIconOrNormalIcon(string name)
608608
{
609609
icon = InnerLoadGeneratedIconOrNormalIcon(name);
610610
}
611+
612+
if (icon != null && !Mathf.Approximately(icon.pixelsPerPoint, GUIUtility.pixelsPerPoint))
613+
{
614+
icon.filterMode = FilterMode.Bilinear;
615+
}
616+
611617
return icon;
612618
}
613619

Editor/Mono/EditorHandles/SliderScale.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,8 @@ public static float DoCenter(int id, float value, Vector3 position, Quaternion r
136136
// Cancel dragging on ESC
137137
if (evt.keyCode == KeyCode.Escape)
138138
{
139-
value = s_StartScale;
140139
s_ScaleDrawLength = 1.0f;
141-
GUIUtility.hotControl = 0;
142-
GUI.changed = true;
143-
evt.Use();
140+
// We do not use the event nor clear hotcontrol to ensure auto revert value kicks in from native side
144141
}
145142
}
146143
break;
@@ -188,6 +185,7 @@ public static float DoCenter(int id, float value, Vector3 position, Quaternion r
188185
if (HandleUtility.nearestControl == id && evt.button == 0)
189186
{
190187
GUIUtility.hotControl = id; // Grab mouse focus
188+
Tools.LockHandlePosition();
191189
s_StartScale = value;
192190
s_ValueDrag = 0;
193191
evt.Use();
@@ -210,11 +208,7 @@ public static float DoCenter(int id, float value, Vector3 position, Quaternion r
210208
// Cancel dragging on ESC
211209
if (evt.keyCode == KeyCode.Escape)
212210
{
213-
value = s_StartScale;
214211
s_ScaleDrawLength = 1.0f;
215-
GUIUtility.hotControl = 0;
216-
GUI.changed = true;
217-
evt.Use();
218212
}
219213
}
220214
break;

Editor/Mono/EditorUserBuildSettings.bindings.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public enum XboxOneDeployMethod
7474
// copies files to the kit
7575
Push = 0,
7676
// run and load files from a connected PC
77+
[Obsolete("Enum member XboxOneDeployMethod.Pull has been deprecated. Use XboxOneDeployMethod.RunFromPC instead (UnityUpgradable) -> RunFromPC", true)]
7778
Pull = 1,
7879
// PC network share loose files to the kit
7980
RunFromPC = 2,
@@ -83,6 +84,21 @@ public enum XboxOneDeployMethod
8384
PackageStreaming = 4,
8485
}
8586

87+
[NativeType(Header = "Runtime/Serialize/BuildTarget.h")]
88+
public enum XboxOneDeployDrive
89+
{
90+
Default = 0,
91+
Retail = 1,
92+
Development = 2,
93+
Ext1 = 3,
94+
Ext2 = 4,
95+
Ext3 = 5,
96+
Ext4 = 6,
97+
Ext5 = 7,
98+
Ext6 = 8,
99+
Ext7 = 9
100+
}
101+
86102
[EditorBrowsable(EditorBrowsableState.Never)]
87103
[Obsolete("UnityEditor.AndroidBuildSubtarget has been deprecated. Use UnityEditor.MobileTextureSubtarget instead (UnityUpgradable)", true)]
88104
[NativeType(Header = "Editor/Src/EditorUserBuildSettings.h")]
@@ -349,6 +365,16 @@ public static extern XboxOneDeployMethod xboxOneDeployMethod
349365
set;
350366
}
351367

368+
//selected Xbox One Deployment Drive
369+
public static extern XboxOneDeployDrive xboxOneDeployDrive
370+
{
371+
[NativeMethod("GetSelectedXboxOneDeployDrive")]
372+
get;
373+
[NativeMethod("SetSelectedXboxOneDeployDrive")]
374+
set;
375+
}
376+
377+
352378
public static extern string xboxOneUsername { get; set; }
353379

354380
public static extern string xboxOneNetworkSharePath { get; set; }

Editor/Mono/GUI/DockArea.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,22 @@ protected override void OldOnGUI()
332332
r.x = background.margin.left;
333333
r.y = background.margin.top;
334334
Rect wPos = windowPosition;
335+
Rect containerWindowPosition = window.position;
336+
containerWindowPosition.width = Mathf.FloorToInt(containerWindowPosition.width);
337+
containerWindowPosition.height = Mathf.FloorToInt(containerWindowPosition.height);
338+
335339
float sideBorder = kSideBorders;
336340
if (wPos.x == 0)
337341
{
338342
r.x -= sideBorder;
339343
r.width += sideBorder;
340344
}
341-
if (wPos.xMax == window.position.width)
345+
if (wPos.xMax == containerWindowPosition.width)
342346
{
343347
r.width += sideBorder;
344348
}
345349

346-
if (wPos.yMax == window.position.height)
350+
if (wPos.yMax == containerWindowPosition.height)
347351
{
348352
r.height += customBorder ? 2f : kBottomBorders;
349353
}
@@ -756,7 +760,7 @@ protected override RectOffset GetBorderSize()
756760
Rect r = windowPosition;
757761
if (r.xMin != 0)
758762
m_BorderSize.left += (int)kSideBorders;
759-
if (r.xMax != window.position.width)
763+
if (r.xMax != Mathf.FloorToInt(window.position.width))
760764
{
761765
m_BorderSize.right += (int)kSideBorders;
762766
}

Editor/Mono/GUI/ScalableGUIContent.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,20 @@ public static implicit operator GUIContent(ScalableGUIContent gc)
6262
Texture2D loadedResource =
6363
StyleSheetResourceUtil.LoadResource(resourcePath, typeof(Texture2D), false) as Texture2D;
6464
loadedResource.pixelsPerPoint = resourceDpi;
65+
6566
gc.m_GuiContent.image = loadedResource;
6667
gc.m_CurrentResourcePath = resourcePath;
6768
}
69+
70+
if (resourceDpi != GUIUtility.pixelsPerPoint)
71+
{
72+
Texture2D image = gc.m_GuiContent.image as Texture2D;
73+
if (image != null)
74+
{
75+
image.filterMode = FilterMode.Bilinear;
76+
}
77+
}
78+
6879
return gc.m_GuiContent;
6980
}
7081
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System;
6+
using UnityEngine.Rendering;
7+
using UnityEngine.Scripting;
8+
using System.Runtime.InteropServices;
9+
10+
namespace UnityEditor.Rendering
11+
{
12+
[StructLayout(LayoutKind.Sequential)]
13+
[UsedByNativeCode]
14+
public struct ShaderSnippetData
15+
{
16+
private ShaderType m_ShaderType;
17+
private PassType m_PassType;
18+
private string m_PassName;
19+
20+
public ShaderType shaderType
21+
{
22+
get { return m_ShaderType; }
23+
}
24+
25+
public PassType passType
26+
{
27+
get { return m_PassType; }
28+
}
29+
30+
public string passName
31+
{
32+
get { return m_PassName; }
33+
}
34+
}
35+
36+
[StructLayout(LayoutKind.Sequential)]
37+
[UsedByNativeCode]
38+
public struct ShaderCompilerData
39+
{
40+
public ShaderKeywordSet shaderKeywordSet;
41+
public PlatformKeywordSet platformKeywordSet; // C++ side is PlatformCapKeywords
42+
private ShaderRequirements m_ShaderRequirements;
43+
private GraphicsTier m_GraphicsTier;
44+
private ShaderCompilerPlatform m_ShaderCompilerPlatform;
45+
46+
public ShaderRequirements shaderRequirements
47+
{
48+
get { return m_ShaderRequirements; }
49+
}
50+
51+
public GraphicsTier graphicsTier
52+
{
53+
get { return m_GraphicsTier; }
54+
}
55+
56+
public ShaderCompilerPlatform shaderCompilerPlatform
57+
{
58+
get { return m_ShaderCompilerPlatform; }
59+
}
60+
}
61+
62+
public enum ShaderCompilerPlatform
63+
{
64+
None = 0, // For non initialized variable.
65+
D3D = 4, // Direct3D 11 (FL10.0 and up) and Direct3D 12, compiled with MS D3DCompiler
66+
GLES20 = 5, // OpenGL ES 2.0 / WebGL 1.0, compiled with hlsl2glslfork + glsl-optimizer
67+
GLES3x = 9, // OpenGL ES 3.0+ / WebGL 2.0, compiled with MS D3DCompiler + HLSLcc
68+
Vita = 10, // Sony PSP2/Vita
69+
PS4 = 11, // Sony PS4
70+
XboxOneD3D11 = 12, // MS XboxOne
71+
Metal = 14, // Apple Metal, compiled with MS D3DCompiler + HLSLcc
72+
OpenGLCore = 15, // Desktop OpenGL 3+, compiled with MS D3DCompiler + HLSLcc
73+
N3DS = 16, // Nintendo 3DS
74+
Vulkan = 18, // Vulkan SPIR-V, compiled with MS D3DCompiler + HLSLcc
75+
Switch = 19, // Nintendo Switch (NVN)
76+
XboxOneD3D12 = 20 // Xbox One D3D12
77+
}
78+
79+
[Flags]
80+
public enum ShaderRequirements
81+
{
82+
None = 0,
83+
BaseShaders = (1 << 0), // Basic "can have shaders" (SM2.0 level) capability
84+
Interpolators10 = (1 << 1), // 10 interpolators/varyings
85+
Interpolators32 = (1 << 2), // 32 interpolators/varyings
86+
MRT4 = (1 << 3), // Multiple render targets, at least 4 (ability for fragment shader to output up to 4 colors)
87+
MRT8 = (1 << 4), // Multiple render targets, at least 8 (ability for fragment shader to output up to 8 colors)
88+
Derivatives = (1 << 5), // Derivative (ddx/ddy) instructions in the fragment shader
89+
SampleLOD = (1 << 6), // Ability to sample textures in fragment shader with explicit LOD level
90+
FragCoord = (1 << 7), // Pixel position (VPOS/SV_Position/gl_FragCoord) input in fragment shader
91+
// = (1 << 8), // unused
92+
Interpolators15Integers = (1 << 9), // Integers + Interpolators15. We bundle them together since extremely unlikely a GPU/API will ever exist that only has part of that.
93+
Texture2DArray = (1 << 10), // 2DArray textures
94+
Instancing = (1 << 11), // SV_InstanceID shader input
95+
Geometry = (1 << 12), // Geometry shaders
96+
CubeArray = (1 << 13), // Cubemap arrays
97+
Compute = (1 << 14), // Compute shaders
98+
RandomWrite = (1 << 15), // Random-write textures (UAVs) from shader stages
99+
TessellationCompute = (1 << 16), // Tessellator hardware, i.e. Metal style
100+
TessellationShaders = (1 << 17), // Tessellation shaders, i.e. DX11 style (hull/domain shader stages)
101+
SparseTexelResident = (1 << 18), // Sparse textures with sampling instructions that return residency info
102+
FramebufferFetch = (1 << 19), // Framebuffer fetch (ability to have in+out fragment shader color params)
103+
MSAATextureSamples = (1 << 20) // Access to MSAA'd texture samples in shaders (e.g. HLSL Texture2DMS)
104+
}
105+
106+
public enum ShaderType
107+
{
108+
Vertex = 1,
109+
Fragment = 2,
110+
Geometry = 3,
111+
Hull = 4,
112+
Domain = 5
113+
}
114+
}

0 commit comments

Comments
 (0)