• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ulao

using an old slimDX project error with new slimDX version

4 posts in this topic

I have some code created in 2010 I'm trying to bring to life. The source didnt include slimDX.dll so I have to use the latest. I get errors on ShaderBytecode as its not in the the same namespace anymore. also this line

 _effect = new Effect( D3D11Device, _effectBytecode, EffectFlags.None );

no longer takes the 3 parms

 

I tried adding the D3DCompiler and omiting that last parm ( and it compiles ) but that crashes the app on MapSubresource

"E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)"

 

Here is the source I'm having troubles with.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Threading;
using System.Windows.Forms;
using System.Drawing;
using System.Configuration;

using SlimDX;
using SlimDX.DXGI;
using SlimDX.Direct3D11;

using LibSnesDotNet.Core;
using LibSnesDotNet.Threading;

using Device = SlimDX.Direct3D11.Device;
using Buffer = SlimDX.Direct3D11.Buffer;
using Configuration = System.Configuration.Configuration;
//using SlimDX.Direct3D9;

namespace LibSnesDotNet.Video
{
	class Direct3D11Driver : Direct3D11Base, IVideoDriver
	{
		WorkerThread       _workerThread;
		WaitableBool       _isBusy;

		DeviceContext      _context;
		RenderTargetView   _backBufferView;

        ShaderBytecode     _effectBytecode;
		Effect             _effect;
		EffectTechnique    _technique;
		EffectPass         _pass;
		InputLayout        _layout;
		Buffer             _vertices;
		Texture2D          _texture;
		ShaderResourceView _textureView;

		public Direct3D11Driver(Form form, Configuration config)
			: base(form, new SwapChainDescription()
			             {
				             IsWindowed = true,
				             BufferCount = 1,
				             SwapEffect = SwapEffect.Discard,
				             Usage = Usage.RenderTargetOutput,
				             Flags = SwapChainFlags.None,
				             SampleDescription = new SampleDescription(1, 0),
				             ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(), Format.R8G8B8A8_UNorm)
			             })
		{
			IsDisposed = false;

			try
			{
				_workerThread = new WorkerThread();
				_isBusy = new WaitableBool(false);

				_context = D3D11Device.ImmediateContext;
				_backBufferView = GetBackBufferView();
				_context.OutputMerger.SetTargets(_backBufferView);

				Viewport viewPort = new Viewport()
				{
					X = 0,
					Y = 0,
					Width = form.ClientSize.Width,
					Height = form.ClientSize.Height,
					MinZ = 0.0F,
					MaxZ = 1.0F
				};
				_context.Rasterizer.SetViewports(viewPort);

                _effectBytecode = ShaderBytecode.CompileFromFile( "Effect.fx", " ", "fx_5_0", ShaderFlags.None,EffectFlags.None, null, null );
                _effect = new Effect( D3D11Device, _effectBytecode, EffectFlags.None );

				_technique = _effect.GetTechniqueByIndex(0);
				_pass = _technique.GetPassByIndex(0);

				InputElement[] elements = new InputElement[]
				{
					new InputElement("POSITION", 0, Format.R32G32B32A32_Float,  0, 0),
					new InputElement("TEXCOORD", 0, Format.R32G32_Float,       16, 0)
				};
				_layout = new InputLayout(D3D11Device, _pass.Description.Signature, elements);

				DataStream stream = new DataStream(4 * Marshal.SizeOf(typeof(Vertex)), true, true);
				stream.Write(new Vector4(-1.0F, 1.0F, 0.5F, 1.0F));
				stream.Write(new Vector2(0.0F, 0.0F));
				stream.Write(new Vector4(1.0F, 1.0F, 0.5F, 1.0F));
				stream.Write(new Vector2(1.0F, 0.0F));
				stream.Write(new Vector4(-1.0F, -1.0F, 0.5F, 1.0F));
				stream.Write(new Vector2(0.0F, 1.0F));
				stream.Write(new Vector4(1.0F, -1.0F, 0.5F, 1.0F));
				stream.Write(new Vector2(1.0F, 1.0F));

				stream.Position = 0;

				_vertices = new Buffer(D3D11Device, stream, new BufferDescription()
				{
					SizeInBytes = (int)stream.Length,
					BindFlags = BindFlags.VertexBuffer,
					Usage = ResourceUsage.Default,
					CpuAccessFlags = CpuAccessFlags.None,
					OptionFlags = ResourceOptionFlags.None
				});
				stream.Close();

				_texture = new Texture2D(D3D11Device, new Texture2DDescription()
				{
					Width = 512,
					Height = 512,
					Format = Format.R8G8B8A8_UNorm,
					ArraySize = 1,
					MipLevels = 1,
					Usage = ResourceUsage.Dynamic,
					CpuAccessFlags = CpuAccessFlags.Write,
					BindFlags = BindFlags.ShaderResource,
					SampleDescription = SwapChainDescription.SampleDescription
				});

				_textureView = new ShaderResourceView(D3D11Device, _texture);

				_effect.GetVariableByName("InputTexture").AsResource().SetResource(_textureView);
			}
			catch
			{
				Dispose();
				throw;
			}
		}

		public IWaitableBool IsBusy { get { return new ReadOnlyWaitableBool(_isBusy); } }
		bool IVideoDriver.IsFullscreen
		{
			get { return IsFullscreen; }
			set
			{
				_isBusy.Acquire(true);
				ChangeMode(value);
				_isBusy.Value = false;
			}
		}

		public void Render(VideoUpdatedEventArgs e)
		{
			while (!TryRender(e))
			{
				_isBusy.WaitWhile();
			}
		}

		public bool TryRender(VideoUpdatedEventArgs e)
		{
			AssertUndisposed();

			if (!_isBusy.TryAcquire(true)) { return false; }

			DataBox dataBox = _context.MapSubresource(_texture, 0, 512 * 512 * 4, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None);
			unsafe
			{
				ushort* snesBuffer = (ushort*)e.VideoBuffer.DataPointer;
				byte* textureBuffer = (byte*)dataBox.Data.DataPointer;
				for (int j = 0; j < e.Height; j++)
				{
					for (int i = 0; i < e.Width; i++)
					{
						ushort color = *snesBuffer++;
						int b;

						b = ((color >> 10) & 31) * 8;
						*textureBuffer++ = (byte)(b + b / 35);
						b = ((color >> 5) & 31) * 8;
						*textureBuffer++ = (byte)(b + b / 35);
						b = ((color >> 0) & 31) * 8;
						*textureBuffer++ = (byte)(b + b / 35);
						*textureBuffer++ = 255;
					}

					textureBuffer += dataBox.RowPitch - e.Width * 4;
					snesBuffer += e.Height > 256 ? 512 - e.Width : 1024 - e.Width;
				}
			}
			dataBox.Data.Close();
			_context.UnmapSubresource(_texture, 0);

			_workerThread.DoWork(new Action(() =>
			{
				AssertUndisposed();

				_context.ClearRenderTargetView(_backBufferView, new Color4(0.0F, 0.0F, 0.0F));

				_context.InputAssembler.InputLayout = _layout;
				_context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
				_context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vertices, Marshal.SizeOf(typeof(Vertex)), 0));

				_effect.GetVariableByName("TexelRange").AsVector().Set(new Vector2(e.Width / 512.0F, e.Height / 512.0F));
				_pass.Apply(_context);
				_context.Draw(4, 0);

				Present(IsComposited && !IsFullscreen ? 0 : 1, PresentFlags.None);

				_isBusy.Value = false;
			}));

			return true;
		}

		protected override void OnFullscreenToggled()
		{
			_isBusy.Acquire(true);

			base.OnFullscreenToggled();

			_isBusy.Value = false;
		}

		protected override void OnBuffersChanging()
		{
			_isBusy.Acquire(true);

			_backBufferView.Resource.Dispose();
			_backBufferView.Dispose();

			base.OnBuffersChanging();
		}

		protected override void OnBuffersChanged()
		{
			_backBufferView = GetBackBufferView();
			_context.OutputMerger.SetTargets(_backBufferView);

			Rectangle viewRect = new Rectangle();
			if (Form.ClientSize.Height * (4.0F / 3.0F) + 2 < Form.ClientSize.Width)
			{
				viewRect.Width = (int)(Form.ClientSize.Height * (4.0F / 3.0F));
				viewRect.Height = Form.ClientSize.Height;
				viewRect.X = (Form.ClientSize.Width - viewRect.Width) / 2;
				viewRect.Y = 0;
			}
			else if (Form.ClientSize.Width * (3.0F / 4.0F) + 2 < Form.ClientSize.Height)
			{
				viewRect.Width = Form.ClientSize.Width;
				viewRect.Height = (int)(Form.ClientSize.Width * (3.0F / 4.0F));
				viewRect.X = 0;
				viewRect.Y = (Form.ClientSize.Height - viewRect.Height) / 2;
			}
			else
			{
				viewRect.Width = Form.ClientSize.Width;
				viewRect.Height = Form.ClientSize.Height;
				viewRect.X = 0;
				viewRect.Y = 0;
			}

			_context.Rasterizer.SetViewports(new Viewport()
			{
				X = viewRect.X,
				Y = viewRect.Y,
				Width = viewRect.Width,
				Height = viewRect.Height,
				MinZ = 0.0F,
				MaxZ = 1.0F
			});

			base.OnBuffersChanged();

			_isBusy.Value = false;
		}

		public new bool IsDisposed { get; private set; }

		public new void Dispose()
		{
			AssertUndisposed();
			IsDisposed = true;

			if (_workerThread != null)
			{
				_workerThread.WaitFor();
				_workerThread.Dispose();
			}
			if (_context != null) { _context.Dispose(); }
			if (_backBufferView != null)
			{
				_backBufferView.Resource.Dispose();
				_backBufferView.Dispose();
			}
			if (_effectBytecode != null) { _effectBytecode.Dispose(); }
			if (_effect != null) { _effect.Dispose(); }
			if (_layout != null) { _layout.Dispose(); }
			if (_vertices != null) { _vertices.Dispose(); }
			if (_texture != null) { _texture.Dispose(); }
			if (_textureView != null) { _textureView.Dispose(); }

			base.Dispose();
		}

		public new void AssertUndisposed()
		{
			if (IsDisposed) { throw new ObjectDisposedException(ToString()); }
		}
	}

	[StructLayout(LayoutKind.Sequential, Pack = 1)]
	struct Vertex
	{
		public Vector4 Position;
		public Vector2 TexCoord;
	}
}

Edited by ulao
0

Share this post


Link to post
Share on other sites

Try to enable debug runtime library (e.g. new D3D.Device(DriverType.Hardware, DeviceCreationFlags.Debug)), you can then get more detailed error report in your output window.

0

Share this post


Link to post
Share on other sites

I found some code that I think constructs the device

 

        public Direct3D11Base(Form form,
                                 SwapChainDescription swapDesc,
                                 Adapter adapter = null,
                                 DriverType type = DriverType.Hardware,
                                 DeviceCreationFlags flags = DeviceCreationFlags.Debug, <-------- was set to None
                                 FeatureLevel[] levels = null)

 

I made the changes In bold but the error is the same, is there a log somewhere?

0

Share this post


Link to post
Share on other sites

First, make sure that you have the latest DirectX 11 SDK installed. Then, open the configuration program "C:\Windows\System32\dxcpl.exe" and check the flag for "Application Controlled" in the Debug Layer section. Then run your application, the error message should in the output window (opened through VS View>Output menu.)

0

Share this post


Link to post
Share on other sites

All of the options are grey'd out but Application Controlled is already checked. When I run my app and get the error, nothing shows in the output box.

Edited by ulao
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0