Beispiel #1
0
        public static D3D9.TextureAddress ConvertEnum(TextureAddressing type, D3D9.Capabilities caps)
        {
            // convert from ours to D3D
            switch (type)
            {
            case TextureAddressing.Wrap:
                return(D3D9.TextureAddress.Wrap);

            case TextureAddressing.Mirror:
                return(D3D9.TextureAddress.Mirror);

            case TextureAddressing.Clamp:
                return(D3D9.TextureAddress.Clamp);

            case TextureAddressing.Border:
                if ((caps.TextureAddressCaps & D3D9.TextureAddressCaps.Border) == D3D9.TextureAddressCaps.Border)
                {
                    return(D3D9.TextureAddress.Border);
                }
                else
                {
                    return(D3D9.TextureAddress.Clamp);
                }
            }                                         // end switch

            return((D3D9.TextureAddress) 0x7fffffff); //D3DTADDRESS_FORCE_DWORD
        }
Beispiel #2
0
        public static D3D9.TextureOperation ConvertEnum(LayerBlendOperationEx lbo, D3D9.Capabilities devCaps)
        {
            switch (lbo)
            {
            case LayerBlendOperationEx.Source1:
                return(D3D9.TextureOperation.SelectArg1);

            case LayerBlendOperationEx.Source2:
                return(D3D9.TextureOperation.SelectArg2);

            case LayerBlendOperationEx.Modulate:
                return(D3D9.TextureOperation.Modulate);

            case LayerBlendOperationEx.ModulateX2:
                return(D3D9.TextureOperation.Modulate2X);

            case LayerBlendOperationEx.ModulateX4:
                return(D3D9.TextureOperation.Modulate4X);

            case LayerBlendOperationEx.Add:
                return(D3D9.TextureOperation.Add);

            case LayerBlendOperationEx.AddSigned:
                return(D3D9.TextureOperation.AddSigned);

            case LayerBlendOperationEx.AddSmooth:
                return(D3D9.TextureOperation.AddSmooth);

            case LayerBlendOperationEx.Subtract:
                return(D3D9.TextureOperation.Subtract);

            case LayerBlendOperationEx.BlendDiffuseAlpha:
                return(D3D9.TextureOperation.BlendDiffuseAlpha);

            case LayerBlendOperationEx.BlendTextureAlpha:
                return(D3D9.TextureOperation.BlendTextureAlpha);

            case LayerBlendOperationEx.BlendCurrentAlpha:
                return(D3D9.TextureOperation.BlendCurrentAlpha);

            case LayerBlendOperationEx.BlendManual:
                return(D3D9.TextureOperation.BlendFactorAlpha);

            case LayerBlendOperationEx.DotProduct:
                return((devCaps.TextureOperationCaps & D3D9.TextureOperationCaps.DotProduct3) != 0
                                                ? D3D9.TextureOperation.DotProduct3
                                                : D3D9.TextureOperation.Modulate);

            case LayerBlendOperationEx.BlendDiffuseColor:
                return((devCaps.TextureOperationCaps & D3D9.TextureOperationCaps.Lerp) != 0
                                                ? D3D9.TextureOperation.Lerp
                                                : D3D9.TextureOperation.Modulate);
            }

            return(0);
        }
Beispiel #3
0
 public D3D9Driver(int adapterNumber, D3D9.Capabilities deviceCaps, D3D9.AdapterDetails adapterIdentifier,
                   D3D9.DisplayMode desktopDisplayMode)
     : base()
 {
     this._adapterNumber      = adapterNumber;
     this._d3D9DeviceCaps     = deviceCaps;
     this._adapterIdentifier  = adapterIdentifier;
     this._desktopDisplayMode = desktopDisplayMode;
     this._videoModeList      = null;
 }
    public static DxCapabilities RequestCapabilities(Capabilities deviceCapabilities, DisplayMode displayMode)
    {
      int maxAnisotropy = deviceCapabilities.MaxAnisotropy;
      bool supportsFiltering = MPDirect3D.Direct3D.CheckDeviceFormat(
          deviceCapabilities.AdapterOrdinal, deviceCapabilities.DeviceType, displayMode.Format,
          Usage.RenderTarget | Usage.QueryFilter, ResourceType.Texture, Format.A8R8G8B8);

      bool supportsAlphaBlend = MPDirect3D.Direct3D.CheckDeviceFormat(deviceCapabilities.AdapterOrdinal,
          deviceCapabilities.DeviceType, displayMode.Format, Usage.RenderTarget | Usage.QueryPostPixelShaderBlending,
          ResourceType.Surface, Format.A8R8G8B8);
      bool supportsShaders = deviceCapabilities.PixelShaderVersion.Major >= 2 && deviceCapabilities.VertexShaderVersion.Major >= 2;
      return new DxCapabilities(maxAnisotropy, supportsFiltering, supportsAlphaBlend, supportsShaders);
    }
Beispiel #5
0
        public static int ConvertEnum(TexCoordCalcMethod method, D3D9.Capabilities caps)
        {
            switch (method)
            {
            case TexCoordCalcMethod.None:
                return((int)D3D9.TextureCoordIndex.PassThru);

            case TexCoordCalcMethod.EnvironmentMapReflection:
                return((int)D3D9.TextureCoordIndex.CameraSpaceReflectionVector);

            case TexCoordCalcMethod.EnvironmentMapPlanar:
                if ((caps.VertexProcessingCaps & D3D9.VertexProcessingCaps.TexGenSphereMap) ==
                    D3D9.VertexProcessingCaps.TexGenSphereMap)
                {
                    // use sphere map if available
                    return((int)D3D9.TextureCoordIndex.SphereMap);
                }
                else
                {
                    // If not, fall back on camera space reflection vector which isn't as good
                    return((int)D3D9.TextureCoordIndex.CameraSpaceReflectionVector);
                }

            case TexCoordCalcMethod.EnvironmentMapNormal:
                return((int)D3D9.TextureCoordIndex.CameraSpaceNormal);

            case TexCoordCalcMethod.EnvironmentMap:
                if ((caps.VertexProcessingCaps & D3D9.VertexProcessingCaps.TexGenSphereMap) ==
                    D3D9.VertexProcessingCaps.TexGenSphereMap)
                {
                    return((int)D3D9.TextureCoordIndex.SphereMap);
                }
                else
                {
                    // fall back on camera space normal if sphere map isnt supported
                    return((int)D3D9.TextureCoordIndex.CameraSpaceNormal);
                }

            case TexCoordCalcMethod.ProjectiveTexture:
                return((int)D3D9.TextureCoordIndex.CameraSpacePosition);
            }             // switch

            return(0);
        }
Beispiel #6
0
		protected void CreateD3D9Device()
		{
			// Update focus window.
			var primaryRenderWindow = PrimaryWindow;

			// Case we have to share the same focus window.
			this._focusWindow = SharedFocusWindow != IntPtr.Zero ? SharedFocusWindow : primaryRenderWindow.WindowHandle;

			var pD3D9 = D3D9RenderSystem.Direct3D9;

			if ( IsMultihead )
			{
				this.BehaviorFlags |= D3D9.CreateFlags.AdapterGroupDevice;
			}
			else
			{
				this.BehaviorFlags &= ~D3D9.CreateFlags.AdapterGroupDevice;
			}

			// Try to create the device with hardware vertex processing.
			this.BehaviorFlags |= D3D9.CreateFlags.HardwareVertexProcessing;

			var keepTrying = true;
			var loopCount = 0;

			LogManager.Instance.Write( "Creating D3D9 Device..." );
			while ( keepTrying )
			{
				try
				{
					this.pDevice = new D3D9.Device( pD3D9, AdapterNumber, DeviceType, this._focusWindow, this.BehaviorFlags,
					                                this.PresentationParams );
					keepTrying = false;
				}
				catch ( DX.SharpDXException ex )
				{
					LogManager.Instance.Write( "FAIL!" );
					switch ( loopCount )
					{
						case 0:
							// Try a second time, may fail the first time due to back buffer count,
							// which will be corrected down to 1 by the runtime
							LogManager.Instance.Write( "Trying to create the device a second time.." );
							break;

						case 1:
							// Case hardware vertex processing failed.
							// Try to create the device with mixed vertex processing.
							this.BehaviorFlags &= ~D3D9.CreateFlags.HardwareVertexProcessing;
							this.BehaviorFlags |= D3D9.CreateFlags.MixedVertexProcessing;
							LogManager.Instance.Write( "Trying to create the device with mixed vertex processing.." );
							break;

						case 2:
							// try to create the device with software vertex processing.
							this.BehaviorFlags &= ~D3D9.CreateFlags.MixedVertexProcessing;
							this.BehaviorFlags |= D3D9.CreateFlags.SoftwareVertexProcessing;
							LogManager.Instance.Write( "Trying to create the device with software vertex processing.." );
							break;

						case 3:
							// try reference device
							DeviceType = D3D9.DeviceType.Reference;
							LogManager.Instance.Write( "Trying to create a reference device.." );
							break;

						default:
							throw new AxiomException( "Cannot create device!", ex );
					}
					;

					loopCount++;
				}
			}
			;

			// Get current device caps.
			this.d3d9DeviceCaps = this.pDevice.Capabilities;

			// Get current creation parameters caps.
			this.creationParams = this.pDevice.CreationParameters;

			this.D3D9DeviceCapsValid = true;

			// Initialize device states.
			SetupDeviceStates();

			// Lock access to rendering device.
			D3D9RenderSystem.ResourceManager.LockDeviceAccess();

			var pCurActiveDevice = this.pDeviceManager.ActiveDevice;

			this.pDeviceManager.ActiveDevice = this;

			// Inform all resources that new device created.
			D3D9RenderSystem.ResourceManager.NotifyOnDeviceCreate( this.pDevice );

			this.pDeviceManager.ActiveDevice = pCurActiveDevice;

			// UnLock access to rendering device.
			D3D9RenderSystem.ResourceManager.UnlockDeviceAccess();
		}
Beispiel #7
0
        private D3D9Device _selectDevice(D3D9RenderWindow renderWindow, D3D9RenderWindowList renderWindowsGroup)
        {
            var        renderSystem    = D3D9RenderSystem.Instance;
            D3D9Device renderDevice    = null;
            var        direct3D9       = D3D9RenderSystem.Direct3D9;
            var        nAdapterOrdinal = 0; // D3DADAPTER_DEFAULT
            var        devType         = D3D9.DeviceType.Hardware;

            D3D9.CreateFlags extraFlags = 0;
            var driverList     = renderSystem.Direct3DDrivers;
            var nvAdapterFound = false;

            // Default group includes at least the given render window.
            renderWindowsGroup.Add(renderWindow);

            // Case we use nvidia performance HUD, override the device settings.
            if (renderWindow.IsNvPerfHUDEnable)
            {
                // Look for 'NVIDIA NVPerfHUD' adapter (<= v4)
                // or 'NVIDIA PerfHUD' (v5)
                // If it is present, override default settings
                for (var adapter = 0; adapter < direct3D9.AdapterCount; ++adapter)
                {
                    var currDriver = driverList[adapter];

                    if (!currDriver.DriverDescription.Contains("PerfHUD"))
                    {
                        continue;
                    }

                    // renderDevice = null;
                    nAdapterOrdinal = adapter;
                    renderSystem._activeD3DDriver = currDriver;
                    devType        = D3D9.DeviceType.Reference;
                    nvAdapterFound = true;
                    break;
                }
            }

            // No special adapter should be used.
            if (nvAdapterFound == false)
            {
                renderSystem._activeD3DDriver = _findDriver(renderWindow);
                nAdapterOrdinal = renderSystem._activeD3DDriver.AdapterNumber;

                var bTryUsingMultiheadDevice = false;

                if (renderWindow.IsFullScreen)
                {
                    bTryUsingMultiheadDevice = true;
                    var osVersionInfo = System.Environment.OSVersion;

                    // XP and below - multi-head will cause artifacts when vsync is on.
                    if (osVersionInfo.Version.Major <= 5 && renderWindow.IsVSync)
                    {
                        bTryUsingMultiheadDevice = false;
                        LogManager.Instance.Write(
                            "D3D9 : Multi head disabled. It causes horizontal line when used in XP + VSync combination");
                    }

                    // Vista and SP1 or SP2 - multi-head device can not be reset - it causes memory corruption.
                    if (osVersionInfo.Version.Major == 6 &&
                        (osVersionInfo.ServicePack.Contains("Service Pack 1") ||
                         osVersionInfo.ServicePack.Contains("Service Pack 2")))
                    {
                        bTryUsingMultiheadDevice = false;
                        LogManager.Instance.Write(
                            "D3D9 : Multi head disabled. It causes application run time crashes when used in Vista + SP 1 or 2 combination");
                    }
                }

                // Check if we can create a group of render windows
                // on the same device using the multi-head feature.
                if (bTryUsingMultiheadDevice)
                {
                    var targetAdapterCaps = renderSystem._activeD3DDriver.D3D9DeviceCaps;
                    var masterAdapterCaps = new Capabilities();

                    // Find the master device caps.
                    if (targetAdapterCaps.MasterAdapterOrdinal == targetAdapterCaps.AdapterOrdinal)
                    {
                        masterAdapterCaps = targetAdapterCaps;
                    }
                    else
                    {
                        foreach (var currDriver in driverList)
                        {
                            var currDeviceCaps = currDriver.D3D9DeviceCaps;

                            if (currDeviceCaps.AdapterOrdinal != targetAdapterCaps.MasterAdapterOrdinal)
                            {
                                continue;
                            }

                            masterAdapterCaps = currDeviceCaps;
                            break;
                        }
                    }

                    // Case the master adapter can handle multiple adapters.
                    if (masterAdapterCaps.NumberOfAdaptersInGroup > 1)
                    {
                        // Create empty list of render windows composing this group.
                        renderWindowsGroup.Clear();
                        while (renderWindowsGroup.Count < masterAdapterCaps.NumberOfAdaptersInGroup)
                        {
                            renderWindowsGroup.Add(null);
                        }

                        // Assign the current render window to it's place in the group.
                        renderWindowsGroup[targetAdapterCaps.AdapterOrdinalInGroup] = renderWindow;


                        // For each existing window - check if it belongs to the group.
                        foreach (var currRenderWindow in renderSystem.RenderWindows)
                        {
                            if (!currRenderWindow.IsFullScreen)
                            {
                                continue;
                            }

                            var currDriver     = _findDriver((D3D9RenderWindow)currRenderWindow);
                            var currDeviceCaps = currDriver.D3D9DeviceCaps;

                            if (currDeviceCaps.MasterAdapterOrdinal != masterAdapterCaps.AdapterOrdinal)
                            {
                                continue;
                            }

                            renderWindowsGroup[currDeviceCaps.AdapterOrdinalInGroup] = (D3D9RenderWindow)currRenderWindow;
                            break;
                        }

                        var bDeviceGroupFull = true;


                        // Check if render windows group is full and ready to be driven by
                        // the master device.
                        for (var i = 0; i < renderWindowsGroup.Count; ++i)
                        {
                            // This group misses required window -> go back to default.
                            if (renderWindowsGroup[i] != null)
                            {
                                continue;
                            }

                            bDeviceGroupFull = false;
                            renderWindowsGroup.Clear();
                            renderWindowsGroup.Add(renderWindow);
                            break;
                        }

                        // Case device group is full -> we can use multi head device.
                        if (bDeviceGroupFull)
                        {
                            var validateAllDevices = false;

                            for (var i = 0; i < renderWindowsGroup.Count; ++i)
                            {
                                var currRenderWindow = renderWindowsGroup[i];
                                var currDevice       = currRenderWindow.Device;

                                // This is the master window
                                if (i == 0)
                                {
                                    // If master device exists - just release it.
                                    if (currDevice != null)
                                    {
                                        renderDevice = currDevice;
                                        renderDevice.Release();
                                    }
                                }

                                // This is subordinate window.
                                else
                                {
                                    // If subordinate device exists - destroy it.
                                    if (currDevice != null)
                                    {
                                        currDevice.Destroy();
                                        validateAllDevices = true;
                                    }
                                }
                            }

                            // In case some device was destroyed - make sure all other devices are valid.
                            // A possible scenario is that full screen window has been destroyed and it's handle
                            // was used and the shared focus handle. All other devices used this handle and must be
                            // recreated using other handles otherwise create device will fail.
                            if (validateAllDevices)
                            {
                                foreach (var dev in this._renderDevices)
                                {
                                    dev.ValidateFocusWindow();
                                }
                            }
                        }
                    }
                }
            }


            // Do we want to preserve the FPU mode? Might be useful for scientific apps
            var options = renderSystem.ConfigOptions;

            ConfigOption opti;

            if (options.TryGetValue("Floating-point mode", out opti) && opti.Value == "Consistent")
            {
                extraFlags |= D3D9.CreateFlags.FpuPreserve;
            }

#if AXIOM_THREAD_SUPPORT
            if (Configuration.Config.AxiomThreadLevel == 1)
            {
                extraFlags |= D3D9.CreateFlags.Multithreaded;
            }
#endif

            // Try to find a matching device from current device list.
            if (renderDevice == null)
            {
                foreach (var currDevice in this._renderDevices)
                {
                    if (currDevice.AdapterNumber != nAdapterOrdinal || currDevice.DeviceType != devType)
                    {
                        continue;
                    }

                    renderDevice = currDevice;
                    break;
                }
            }

            // No matching device found -> try reference device type (might have been
            // previously created as a fallback, but don't change devType because HAL
            // should be preferred on creation)
            if (renderDevice == null)
            {
                foreach (var currDevice in this._renderDevices)
                {
                    if (currDevice.AdapterNumber != nAdapterOrdinal || currDevice.DeviceType != D3D9.DeviceType.Reference)
                    {
                        continue;
                    }

                    renderDevice = currDevice;
                    break;
                }
            }

            // No matching device found -> create new one.
            if (renderDevice == null)
            {
                renderDevice = new D3D9Device(this, nAdapterOrdinal, direct3D9.GetAdapterMonitor(nAdapterOrdinal), devType,
                                              extraFlags);
                this._renderDevices.Add(renderDevice);
                if (this._activeDevice == null)
                {
                    ActiveDevice = renderDevice;
                }
            }

            return(renderDevice);
        }
Beispiel #8
0
        public CAdapter(Direct3D direct3D, AdapterInformation adapterInfo)
        {
            this.direct3D = direct3D;
            this.adapterInfo = adapterInfo;
            desctopDisplayMode = adapterInfo.CurrentDisplayMode;
            caps = adapterInfo.GetCaps(DeviceType.Hardware);
            index = adapterInfo.Adapter;
            var shaderModel = System.Math.Min(caps.VertexShaderVersion.Major, caps.PixelShaderVersion.Major);
            apiVersion = new ApiVersion(9, (byte)shaderModel);
            var details = adapterInfo.Details;
            restrictions = new AdapterRestrictions
            {
                UniformBufferSlots = 256,
                SamplerSlots = caps.MaxSimultaneousTextures,
                ShaderResourceSlots = caps.MaxSimultaneousTextures,
                UnorderedAccessResourceSlots = 0,
                MaxVertexStreams = caps.MaxStreams,
                MaxVertexStreamElementCount = caps.MaxStreamStride / (4 * sizeof(float)),
                MaxStreamOutputTargets = 0,
                MaxViewports = 1,
                MaxRenderTargets = caps.SimultaneousRTCount,
                MaxThreadGroupsX = 0,
                MaxThreadGroupsY = 0,
                MaxThreadGroupsZ = 0,
                MaxThreadGroupsTotal = 0,
            };

            adapterDesc = new AdapterDescription
            {
                Description = details.Description,
                VendorId = details.VendorId,
                DeviceId = details.DeviceId,
                SubSysId = details.SubsystemId,
                Revision = details.Revision,
                DedicatedVideoMemory = 0,
                DedicatedSystemMemory = 0,
                SharedSystemMemory = 0,
                AdapterLuidHigh = 0,
                AdapterLuidLow = 0,
                Flags = AdapterFlags.None
            };

            outputDesc = new OutputDescription
            {
                DeviceName = details.DeviceName,
                DesctopCoordinates = new Math.Rectangle(),
                AttachedToDesctop = false,
                Rotation = ModeRotation.Unspecified,
                MonitorHandle = adapterInfo.Monitor
            };

            outputs = new[] { this };

            formatSupports = ((Format[])Enum.GetValues(typeof(Format))).ToDictionary(f => f, GetFormatSupport);
        }
		private void _convertPixelShaderCaps( RenderSystemCapabilities rsc )
		{
			var major = 0xFF;
			var minor = 0xFF;
			var minPsCaps = new D3D9.Capabilities();

			// Find the device with the lowest vertex shader caps.
			foreach ( var pCurDriver in this._driverList )
			{
				var currCaps = pCurDriver.D3D9DeviceCaps;
				var currMajor = currCaps.PixelShaderVersion.Major;
				var currMinor = currCaps.PixelShaderVersion.Minor;

				if ( currMajor < major )
				{
					major = currMajor;
					minor = currMinor;
					minPsCaps = currCaps;
				}
				else if ( currMajor == major && currMinor < minor )
				{
					minor = currMinor;
					minPsCaps = currCaps;
				}
			}

			var ps2a = false;
			var ps2b = false;
			var ps2x = false;

			// Special case detection for ps_2_x/a/b support
			if ( major >= 2 )
			{
				if ( ( minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.NoTextureInstructionLimit ) != 0 &&
				     ( minPsCaps.PS20Caps.TempCount >= 32 ) )
				{
					ps2b = true;
				}

				if ( ( minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.NoTextureInstructionLimit ) != 0 &&
				     ( minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.NoDependentReadLimit ) != 0 &&
				     ( minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.ArbitrarySwizzle ) != 0 &&
				     ( minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.GradientInstructions ) != 0 &&
				     ( minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.Predication ) != 0 && ( minPsCaps.PS20Caps.TempCount >= 22 ) )
				{
					ps2a = true;
				}

				// Does this enough?
				if ( ps2a || ps2b )
				{
					ps2x = true;
				}
			}

			switch ( major )
			{
				case 1:
					// no boolean params allowed
					rsc.FragmentProgramConstantBoolCount = 0;
					// no integer params allowed
					rsc.FragmentProgramConstantIntCount = 0;
					// float params, always 4D
					// NB in ps_1_x these are actually stored as fixed point values,
					// but they are entered as floats
					rsc.FragmentProgramConstantFloatCount = 8;
					break;

				case 2:
					// 16 boolean params allowed
					rsc.FragmentProgramConstantBoolCount = 16;
					// 16 integer params allowed, 4D
					rsc.FragmentProgramConstantIntCount = 16;
					// float params, always 4D
					rsc.FragmentProgramConstantFloatCount = 32;
					break;

				case 3:
					// 16 boolean params allowed
					rsc.FragmentProgramConstantBoolCount = 16;
					// 16 integer params allowed, 4D
					rsc.FragmentProgramConstantIntCount = 16;
					// float params, always 4D
					rsc.FragmentProgramConstantFloatCount = 224;
					break;
			}

			// populate syntax codes in program manager (no breaks in this one so it falls through)
			switch ( major )
			{
				case 3:
					if ( minor > 0 )
					{
						rsc.AddShaderProfile( "ps_3_x" );
					}

					rsc.AddShaderProfile( "ps_3_0" );
					goto case 2;

				case 2:
					if ( ps2x )
					{
						rsc.AddShaderProfile( "ps_2_x" );
					}
					if ( ps2a )
					{
						rsc.AddShaderProfile( "ps_2_a" );
					}
					if ( ps2b )
					{
						rsc.AddShaderProfile( "ps_2_b" );
					}

					rsc.AddShaderProfile( "ps_2_0" );
					goto case 1;

				case 1:
					if ( major > 1 || minor >= 4 )
					{
						rsc.AddShaderProfile( "ps_1_4" );
					}
					if ( major > 1 || minor >= 3 )
					{
						rsc.AddShaderProfile( "ps_1_3" );
					}
					if ( major > 1 || minor >= 2 )
					{
						rsc.AddShaderProfile( "ps_1_2" );
					}

					rsc.AddShaderProfile( "ps_1_1" );
					rsc.SetCapability( Graphics.Capabilities.FragmentPrograms );
					break;
			}
		}
        private void _convertVertexShaderCaps(RenderSystemCapabilities rsc)
        {
            var major     = 0xFF;
            var minor     = 0xFF;
            var minVsCaps = new D3D9.Capabilities();

            // Find the device with the lowest vertex shader caps.
            foreach (var pCurDriver in this._driverList)
            {
                var rkCurCaps = pCurDriver.D3D9DeviceCaps;
                var currMajor = rkCurCaps.VertexShaderVersion.Major;
                var currMinor = rkCurCaps.VertexShaderVersion.Minor;

                if (currMajor < major)
                {
                    major     = currMajor;
                    minor     = currMinor;
                    minVsCaps = rkCurCaps;
                }
                else if (currMajor == major && currMinor < minor)
                {
                    minor     = currMinor;
                    minVsCaps = rkCurCaps;
                }
            }

            var vs2x = false;
            var vs2a = false;

            // Special case detection for vs_2_x/a support
            if (major >= 2)
            {
                if ((minVsCaps.VS20Caps.Caps & D3D9.VertexShaderCaps.Predication) != 0 &&
                    (minVsCaps.VS20Caps.DynamicFlowControlDepth > 0) && (minVsCaps.VS20Caps.TempCount >= 12))
                {
                    vs2x = true;
                }

                if ((minVsCaps.VS20Caps.Caps & D3D9.VertexShaderCaps.Predication) != 0 &&
                    (minVsCaps.VS20Caps.DynamicFlowControlDepth > 0) && (minVsCaps.VS20Caps.TempCount >= 13))
                {
                    vs2a = true;
                }
            }

            // Populate max param count
            switch (major)
            {
            case 1:
                // No boolean params allowed
                rsc.VertexProgramConstantBoolCount = 0;
                // No integer params allowed
                rsc.VertexProgramConstantIntCount = 0;
                // float params, always 4D
                rsc.VertexProgramConstantFloatCount = minVsCaps.MaxVertexShaderConst;
                break;

            case 2:
                // 16 boolean params allowed
                rsc.VertexProgramConstantBoolCount = 16;
                // 16 integer params allowed, 4D
                rsc.VertexProgramConstantIntCount = 16;
                // float params, always 4D
                rsc.VertexProgramConstantFloatCount = minVsCaps.MaxVertexShaderConst;
                break;

            case 3:
                // 16 boolean params allowed
                rsc.VertexProgramConstantBoolCount = 16;
                // 16 integer params allowed, 4D
                rsc.VertexProgramConstantIntCount = 16;
                // float params, always 4D
                rsc.VertexProgramConstantFloatCount = minVsCaps.MaxVertexShaderConst;
                break;
            }

            // populate syntax codes in program manager (no breaks in this one so it falls through)
            switch (major)
            {
            case 3:
                rsc.AddShaderProfile("vs_3_0");
                goto case 2;

            case 2:
                if (vs2x)
                {
                    rsc.AddShaderProfile("vs_2_x");
                }
                if (vs2a)
                {
                    rsc.AddShaderProfile("vs_2_a");
                }

                rsc.AddShaderProfile("vs_2_0");
                goto case 1;

            case 1:
                rsc.AddShaderProfile("vs_1_1");
                rsc.SetCapability(Graphics.Capabilities.VertexPrograms);
                break;
            }
        }
        private void _convertPixelShaderCaps(RenderSystemCapabilities rsc)
        {
            var major     = 0xFF;
            var minor     = 0xFF;
            var minPsCaps = new D3D9.Capabilities();

            // Find the device with the lowest vertex shader caps.
            foreach (var pCurDriver in this._driverList)
            {
                var currCaps  = pCurDriver.D3D9DeviceCaps;
                var currMajor = currCaps.PixelShaderVersion.Major;
                var currMinor = currCaps.PixelShaderVersion.Minor;

                if (currMajor < major)
                {
                    major     = currMajor;
                    minor     = currMinor;
                    minPsCaps = currCaps;
                }
                else if (currMajor == major && currMinor < minor)
                {
                    minor     = currMinor;
                    minPsCaps = currCaps;
                }
            }

            var ps2a = false;
            var ps2b = false;
            var ps2x = false;

            // Special case detection for ps_2_x/a/b support
            if (major >= 2)
            {
                if ((minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.NoTextureInstructionLimit) != 0 &&
                    (minPsCaps.PS20Caps.TempCount >= 32))
                {
                    ps2b = true;
                }

                if ((minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.NoTextureInstructionLimit) != 0 &&
                    (minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.NoDependentReadLimit) != 0 &&
                    (minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.ArbitrarySwizzle) != 0 &&
                    (minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.GradientInstructions) != 0 &&
                    (minPsCaps.PS20Caps.Caps & D3D9.PixelShaderCaps.Predication) != 0 && (minPsCaps.PS20Caps.TempCount >= 22))
                {
                    ps2a = true;
                }

                // Does this enough?
                if (ps2a || ps2b)
                {
                    ps2x = true;
                }
            }

            switch (major)
            {
            case 1:
                // no boolean params allowed
                rsc.FragmentProgramConstantBoolCount = 0;
                // no integer params allowed
                rsc.FragmentProgramConstantIntCount = 0;
                // float params, always 4D
                // NB in ps_1_x these are actually stored as fixed point values,
                // but they are entered as floats
                rsc.FragmentProgramConstantFloatCount = 8;
                break;

            case 2:
                // 16 boolean params allowed
                rsc.FragmentProgramConstantBoolCount = 16;
                // 16 integer params allowed, 4D
                rsc.FragmentProgramConstantIntCount = 16;
                // float params, always 4D
                rsc.FragmentProgramConstantFloatCount = 32;
                break;

            case 3:
                // 16 boolean params allowed
                rsc.FragmentProgramConstantBoolCount = 16;
                // 16 integer params allowed, 4D
                rsc.FragmentProgramConstantIntCount = 16;
                // float params, always 4D
                rsc.FragmentProgramConstantFloatCount = 224;
                break;
            }

            // populate syntax codes in program manager (no breaks in this one so it falls through)
            switch (major)
            {
            case 3:
                if (minor > 0)
                {
                    rsc.AddShaderProfile("ps_3_x");
                }

                rsc.AddShaderProfile("ps_3_0");
                goto case 2;

            case 2:
                if (ps2x)
                {
                    rsc.AddShaderProfile("ps_2_x");
                }
                if (ps2a)
                {
                    rsc.AddShaderProfile("ps_2_a");
                }
                if (ps2b)
                {
                    rsc.AddShaderProfile("ps_2_b");
                }

                rsc.AddShaderProfile("ps_2_0");
                goto case 1;

            case 1:
                if (major > 1 || minor >= 4)
                {
                    rsc.AddShaderProfile("ps_1_4");
                }
                if (major > 1 || minor >= 3)
                {
                    rsc.AddShaderProfile("ps_1_3");
                }
                if (major > 1 || minor >= 2)
                {
                    rsc.AddShaderProfile("ps_1_2");
                }

                rsc.AddShaderProfile("ps_1_1");
                rsc.SetCapability(Graphics.Capabilities.FragmentPrograms);
                break;
            }
        }
 private Result GetDeviceCaps(IntPtr devicePointer, Capabilities caps)
 {
     throw new NotImplementedException();
 }
 public Capabilities GetDeviceCaps(int adapter, DeviceType deviceType)
 {
     Capabilities capsRef = new Capabilities();
     int res = Interop.Calli(comPointer, adapter, (int)deviceType, (IntPtr)(void*)&capsRef,(*(IntPtr**)comPointer)[14]);
     if( res < 0 ) { throw new SharpDXException( res ); }
     return capsRef;
 }
Beispiel #14
0
        public static D3D9.TextureFilter ConvertEnum(FilterType type, FilterOptions options, D3D9.Capabilities devCaps,
                                                     D3D9TextureType texType)
        {
            // Assume normal
            D3D9.FilterCaps capsType = devCaps.TextureFilterCaps;

            switch (texType)
            {
            case D3D9TextureType.Normal:
                capsType = devCaps.TextureFilterCaps;
                break;

            case D3D9TextureType.Cube:
                capsType = devCaps.CubeTextureFilterCaps;
                break;

            case D3D9TextureType.Volume:
                capsType = devCaps.VolumeTextureFilterCaps;
                break;
            }

            switch (type)
            {
                #region FilterType.Min

            case FilterType.Min:
            {
                switch (options)
                {
                // NOTE: Fall through if device doesn't support requested type
                case FilterOptions.Anisotropic:
                    if ((capsType & D3D9.FilterCaps.MinAnisotropic) == D3D9.FilterCaps.MinAnisotropic)
                    {
                        return(D3D9.TextureFilter.Anisotropic);
                    }
                    break;

                case FilterOptions.Linear:
                    if ((capsType & D3D9.FilterCaps.MinLinear) == D3D9.FilterCaps.MinLinear)
                    {
                        return(D3D9.TextureFilter.Linear);
                    }
                    break;

                case FilterOptions.Point:
                case FilterOptions.None:
                    return(D3D9.TextureFilter.Point);
                }
                break;
            }

                #endregion FilterType.Min

                #region FilterType.Mag

            case FilterType.Mag:
            {
                switch (options)
                {
                // NOTE: Fall through if device doesn't support requested type
                case FilterOptions.Anisotropic:
                    if ((capsType & D3D9.FilterCaps.MagAnisotropic) == D3D9.FilterCaps.MagAnisotropic)
                    {
                        return(D3D9.TextureFilter.Anisotropic);
                    }
                    break;

                case FilterOptions.Linear:
                    if ((capsType & D3D9.FilterCaps.MagLinear) == D3D9.FilterCaps.MagLinear)
                    {
                        return(D3D9.TextureFilter.Linear);
                    }
                    break;

                case FilterOptions.Point:
                case FilterOptions.None:
                    return(D3D9.TextureFilter.Point);
                }
                break;
            }

                #endregion FilterType.Mag

                #region FilterType.Mip

            case FilterType.Mip:
            {
                switch (options)
                {
                case FilterOptions.Anisotropic:
                case FilterOptions.Linear:
                    if ((capsType & D3D9.FilterCaps.MipLinear) == D3D9.FilterCaps.MipLinear)
                    {
                        return(D3D9.TextureFilter.Linear);
                    }
                    break;

                case FilterOptions.Point:
                    if ((capsType & D3D9.FilterCaps.MipPoint) == D3D9.FilterCaps.MipPoint)
                    {
                        return(D3D9.TextureFilter.Point);
                    }
                    break;

                case FilterOptions.None:
                    return(D3D9.TextureFilter.None);
                }
                break;
            }

                #endregion FilterType.Mip
            }

            // should never get here
            return(0);
        }
		private void _convertVertexShaderCaps( RenderSystemCapabilities rsc )
		{
			var major = 0xFF;
			var minor = 0xFF;
			var minVsCaps = new D3D9.Capabilities();

			// Find the device with the lowest vertex shader caps.
			foreach ( var pCurDriver in this._driverList )
			{
				var rkCurCaps = pCurDriver.D3D9DeviceCaps;
				var currMajor = rkCurCaps.VertexShaderVersion.Major;
				var currMinor = rkCurCaps.VertexShaderVersion.Minor;

				if ( currMajor < major )
				{
					major = currMajor;
					minor = currMinor;
					minVsCaps = rkCurCaps;
				}
				else if ( currMajor == major && currMinor < minor )
				{
					minor = currMinor;
					minVsCaps = rkCurCaps;
				}
			}

			var vs2x = false;
			var vs2a = false;

			// Special case detection for vs_2_x/a support
			if ( major >= 2 )
			{
				if ( ( minVsCaps.VS20Caps.Caps & D3D9.VertexShaderCaps.Predication ) != 0 &&
				     ( minVsCaps.VS20Caps.DynamicFlowControlDepth > 0 ) && ( minVsCaps.VS20Caps.TempCount >= 12 ) )
				{
					vs2x = true;
				}

				if ( ( minVsCaps.VS20Caps.Caps & D3D9.VertexShaderCaps.Predication ) != 0 &&
				     ( minVsCaps.VS20Caps.DynamicFlowControlDepth > 0 ) && ( minVsCaps.VS20Caps.TempCount >= 13 ) )
				{
					vs2a = true;
				}
			}

			// Populate max param count
			switch ( major )
			{
				case 1:
					// No boolean params allowed
					rsc.VertexProgramConstantBoolCount = 0;
					// No integer params allowed
					rsc.VertexProgramConstantIntCount = 0;
					// float params, always 4D
					rsc.VertexProgramConstantFloatCount = minVsCaps.MaxVertexShaderConst;
					break;

				case 2:
					// 16 boolean params allowed
					rsc.VertexProgramConstantBoolCount = 16;
					// 16 integer params allowed, 4D
					rsc.VertexProgramConstantIntCount = 16;
					// float params, always 4D
					rsc.VertexProgramConstantFloatCount = minVsCaps.MaxVertexShaderConst;
					break;

				case 3:
					// 16 boolean params allowed
					rsc.VertexProgramConstantBoolCount = 16;
					// 16 integer params allowed, 4D
					rsc.VertexProgramConstantIntCount = 16;
					// float params, always 4D
					rsc.VertexProgramConstantFloatCount = minVsCaps.MaxVertexShaderConst;
					break;
			}

			// populate syntax codes in program manager (no breaks in this one so it falls through)
			switch ( major )
			{
				case 3:
					rsc.AddShaderProfile( "vs_3_0" );
					goto case 2;

				case 2:
					if ( vs2x )
					{
						rsc.AddShaderProfile( "vs_2_x" );
					}
					if ( vs2a )
					{
						rsc.AddShaderProfile( "vs_2_a" );
					}

					rsc.AddShaderProfile( "vs_2_0" );
					goto case 1;

				case 1:
					rsc.AddShaderProfile( "vs_1_1" );
					rsc.SetCapability( Graphics.Capabilities.VertexPrograms );
					break;
			}
		}
Beispiel #16
0
 protected virtual bool ConfirmDevice(Capabilities caps, VertexProcessingType vertexProcessingType,
     Format adapterFormat, Format backBufferFormat)
 {
   return true;
 }
Beispiel #17
0
        public WinformsDevice(WinformsEye eye, Direct3D direct3D, CAdapter adapter, 
            ControlWindow primaryWindow, SwapChainDescription implicitSwapChainDesc, 
            DeviceInitializationFlags flags, IFileSystem fileSystem)
        {
            this.eye = eye;
            this.adapter = adapter;
            this.primaryWindow = primaryWindow;
            this.implicitSwapChainDesc = implicitSwapChainDesc;
            this.flags = flags;

            caps = adapter.Info.GetCaps(DeviceType.Hardware);
            devicePresentParams = new PresentParameters();

            FillDevicePresentParams();
            d3dDevice = new Device(direct3D, adapter.Index, DeviceType.Hardware, primaryWindow.Handle, CreateFlags.FpuPreserve | CreateFlags.HardwareVertexProcessing, devicePresentParams);

            CreateBackBufferAndDepthStencil();

            additionalSwapChains = new List<CAdditionalSwapChain>();
            creator = new CDeviceChildCreator(this);
            immediateContext = new CDeviceContext(this);

            lastSwapChainSize = new IntSize(primaryWindow.SwapChainWidth, primaryWindow.SwapChainHeight);
            fullscreenState = FullscreenState.Windowed;
            fullscreenDisplayMode = adapter.GetSupportedDisplayModes().First();
        }