Sign in to follow this  
coderchris

DX11 GPUList<T>: A C# list class with a DX11 Buffer backend

Recommended Posts

coderchris    304
Hey everyone,

So earlier today, I was playing with some compute shader stuff, and I found myself getting very frustrated dealing with buffers, copying the data back and forth, ect...
I thought, it would be really nice if there was some kind of pretty C# interface to a list of data stored on the GPU...

Well, I never found one, so I wrote my own! I would like to share it in hopes that it will cure at least one more headache.

Its essentially an implementation of IList<T> which is backed using a SlimDX Buffer.
Any operation you do directly affects this underlying buffer.
Therefor, its very easy to make a list of data to give / receive to / from your shaders.

Its not perfect, but it gets the job done. Its pretty, easy to use, and (somewhat) tested.

Source code for the List and a small test program are below.
Please let me know if you have comments, suggestions, fixes, or find any bugs.

~Chris

[ps I tried attaching the .cs files directly but it doesn't like them?]

[code]

using System;
using System.Collections.Generic;
using System.Linq;

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

using Device = SlimDX.Direct3D11.Device;
using Buffer = SlimDX.Direct3D11.Buffer;

namespace GPUTools
{
class Program
{
/// <summary>
/// Simple structure representing some kind of particle
/// </summary>
struct Particle
{
public Vector3 Position;
public Vector3 Velocity;

public override string ToString()
{
return "Position: " + Position.ToString() + ", Velocity: " + Velocity.ToString();
}
}

static void Main(string[] args)
{
// Source code for the simple integration compute shader
const string integrateSource = @"

struct Particle
{
float3 position;
float3 velocity;
};

RWStructuredBuffer<Particle> particles;

[numthreads(1, 1, 1)]
void Integrate(uint3 threadID : SV_DispatchThreadID)
{
particles[threadID.x].position += particles[threadID.x].velocity;
}
";

// Make device
Device device = new Device(DriverType.Hardware, DeviceCreationFlags.None, FeatureLevel.Level_10_0);

// Compile compute shader
ShaderBytecode integrateBytecode = ShaderBytecode.Compile(integrateSource, "Integrate", "cs_4_0", ShaderFlags.None, EffectFlags.None);
ComputeShader integrate = new ComputeShader(device, integrateBytecode);

// Create GPUList of particles using the immediate context
GPUList<Particle> particles = new GPUList<Particle>(device.ImmediateContext);
// Add some particles
for (int i = 0; i < 10; i++)
particles.Add(new Particle() { Position = new Vector3(i, 0, 0), Velocity = new Vector3(0, i, -i) });

// Print the particles
Console.WriteLine("Before Integration:");
foreach (Particle p in particles)
Console.WriteLine(p.ToString());

// Run the compute shader
device.ImmediateContext.ComputeShader.Set(integrate);
device.ImmediateContext.ComputeShader.SetUnorderedAccessView(particles.UnorderedAccess, 0);
device.ImmediateContext.Dispatch(particles.Count, 1, 1);

// Print the particles again
Console.WriteLine("\n\nAfter Integration:");
foreach (Particle p in particles)
Console.WriteLine(p.ToString());

Console.Read();
}
}
}
[/code]


[code]

/* Who: Chris Giles
* What: A GPU-based implementation of List<T>
* When: 5/16/2011 @ ~4 AM
* Where: My house
* Why: I was tired of dealing with low level graphics resources
* This is almost completely interchangable with built in C# List<T>
* Only, the backend is a DirectX11 Buffer
* You can use the underlying buffer in any kind of shader
* But with a pretty C# interface for messing with its data
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

using SlimDX;
using SlimDX.Direct3D11;

using Device = SlimDX.Direct3D11.Device;
using Buffer = SlimDX.Direct3D11.Buffer;

namespace GPUTools
{
public class GPUList<T> : IList<T>, IDisposable where T : struct
{
#region GPUList Members

private DeviceContext context;
private Buffer buffer;
private ShaderResourceView shaderResourceView;
private UnorderedAccessView unorderedAccessView;

private int count;
private int capacity;

/// <summary>
/// Makes a new list given initial data
/// </summary>
/// <param name="context">Device context on which to perform all operations</param>
public GPUList(DeviceContext context)
{
this.context = context;
}

/// <summary>
/// Makes a new empty list with an initial capacity
/// </summary>
/// <param name="context">Device context on which to perform all operations</param>
/// <param name="initialCapacity">The initial capacity</param>
public GPUList(DeviceContext context, int initialCapacity)
{
this.context = context;
this.setCapacity(initialCapacity);
}

/// <summary>
/// Makes a new list given initial data
/// </summary>
/// <param name="context">Device context on which to perform all operations</param>
/// <param name="data">The initial data</param>
public GPUList(DeviceContext context, IEnumerable<T> data)
{
this.context = context;
this.AddRange(data);
}

/// <summary>
/// Gets the DeviceContext on which to perform all operations
/// </summary>
public DeviceContext Context { get { return context; } }

/// <summary>
/// Gets the underlying Buffer stored on the GPU
/// </summary>
public Buffer GPUBuffer { get { return buffer; } }

/// <summary>
/// Gets a ShaderResourceView for use in a shader
/// </summary>
public ShaderResourceView ShaderResource { get { return shaderResourceView; } }

/// <summary>
/// Gets a UnorderedAccessView for use in a shader
/// </summary>
public UnorderedAccessView UnorderedAccess { get { return unorderedAccessView; } }

/// <summary>
/// Gets or Sets the internal GPU buffer capacity in number of elements
/// </summary>
public int Capacity { get { return capacity; } set { setCapacity(value); } }

/// <summary>
/// Adds a range of items to the end of the list
/// </summary>
/// <param name="range"></param>
public void AddRange(IEnumerable<T> range)
{
if (range == null)
throw new ArgumentNullException();

int dataSize = Marshal.SizeOf(typeof(T));

if (range is GPUList<T> && range != this)
{
GPUList<T> list = range as GPUList<T>;

if (list.Count == 0)
return;
if (Count + list.Count > Capacity)
setCapacity(2 * Count + list.Count);

count += list.Count;

list.CopyRangeTo(0, list.Count, this, Count - list.Count);
}
else
{
T[] data = null;
if (range is T[])
data = (T[])range;
else if (range is List<T>)
data = (range as List<T>).ToArray();
else
{
List<T> dataList = new List<T>(range);
data = dataList.ToArray();
}

if (data.Length == 0)
return;
if (Count + data.Length > Capacity)
setCapacity(2 * Count + data.Length);

count += data.Length;

SetRange(Count - data.Length, data, 0, data.Length);
}
}

/// <summary>
/// Inserts a range of items into the list
/// </summary>
/// <param name="index">Position in the list to insert items</param>
/// <param name="range">The range of items to insert</param>
public void InsertRange(int index, IEnumerable<T> range)
{
if (range == null)
throw new ArgumentNullException();
if (index < 0 || index > Count)
throw new IndexOutOfRangeException();

if (index == Count)
{
AddRange(range);
}
else
{
GPUList<T> newList = null;

if (range is GPUList<T>)
{
GPUList<T> list = range as GPUList<T>;

if (list.Count == 0)
return;

newList = new GPUList<T>(Context, list.Count + Count);
newList.count = list.Count + Count;
this.CopyRangeTo(0, index, newList, 0);
list.CopyTo(newList, index);
this.CopyRangeTo(index, Count - index, newList, index + list.Count);
}
else
{
T[] data = null;
if (range is T[])
data = (T[])range;
else if (range is List<T>)
data = (range as List<T>).ToArray();
else
{
List<T> dataList = new List<T>(range);
data = dataList.ToArray();
}

if (data.Length == 0)
return;

newList = new GPUList<T>(Context, data.Length + Count);
newList.count = data.Length + Count;
this.CopyRangeTo(0, index, newList, 0);
newList.SetRange(index, data, 0, data.Length);
this.CopyRangeTo(index, Count - index, newList, index + data.Length);
}

setCapacity(0);
count = newList.count;
capacity = newList.capacity;
buffer = newList.buffer;
shaderResourceView = newList.shaderResourceView;
unorderedAccessView = newList.unorderedAccessView;
}
}

/// <summary>
/// Removes a range of items from the list
/// </summary>
/// <param name="index">Index to start removing</param>
/// <param name="count">Number of items to remove</param>
public void RemoveRange(int index, int count)
{
if (count == 0)
return;

if (count < 0)
throw new IndexOutOfRangeException();
if (index < 0 || index >= Count)
throw new IndexOutOfRangeException();
if (index + count < 0 || index + count > Count)
throw new IndexOutOfRangeException();

if (index + count == Count)
{
this.count -= count;
return;
}

GPUList<T> newList = new GPUList<T>(Context, Capacity);
newList.count = this.count - count;
this.CopyRangeTo(0, index, newList, 0);
this.CopyRangeTo(index + count, this.count - (index + count), newList, index);

setCapacity(0);
this.count = newList.count;
this.capacity = newList.capacity;
this.buffer = newList.buffer;
this.shaderResourceView = newList.shaderResourceView;
this.unorderedAccessView = newList.unorderedAccessView;
}

/// <summary>
/// Sets a range of data in the list based on an array
/// </summary>
/// <param name="index">Index in the GPUList to start setting data</param>
/// <param name="array">The array of data to use</param>
/// <param name="arrayIndex">The start index in the array</param>
/// <param name="count">The number of elements to set</param>
public void SetRange(int index, T[] array, int arrayIndex, int count)
{
if (count == 0)
return;

if (count < 0)
throw new IndexOutOfRangeException();
if (index < 0 || index >= Count)
throw new IndexOutOfRangeException();
if (index + count < 0 || index + count > Count)
throw new IndexOutOfRangeException();

if (array == null)
throw new ArgumentNullException();
if (arrayIndex < 0 || arrayIndex >= array.Length)
throw new IndexOutOfRangeException();
if (arrayIndex + array.Length < 0 || arrayIndex + count > array.Length)
throw new IndexOutOfRangeException();

int dataSize = Marshal.SizeOf(typeof(T));
DataStream stream = new DataStream(array, true, false);
stream.Seek(arrayIndex, System.IO.SeekOrigin.Begin);
context.UpdateSubresource(new DataBox(0, 0, stream), buffer, 0,
new ResourceRegion(dataSize * index, 0, 0, dataSize * (index + count), 1, 1));
}

/// <summary>
/// Copies a range of data to an array
/// </summary>
/// <param name="index">Index from which to start copying</param>
/// <param name="count">Number of elements to copy</param>
/// <param name="array">Destination array to copy to</param>
/// <param name="arrayIndex">Destination array index to copy to</param>
public void CopyRangeTo(int index, int count, T[] array, int arrayIndex)
{
if (count == 0)
return;

if (count < 0)
throw new IndexOutOfRangeException();
if (index < 0 || index >= Count)
throw new IndexOutOfRangeException();
if (index + count < 0 || index + count > Count)
throw new IndexOutOfRangeException();

if (array == null)
throw new ArgumentNullException();
if (arrayIndex < 0 || arrayIndex >= array.Length)
throw new IndexOutOfRangeException();
if (arrayIndex + array.Length < 0 || arrayIndex + count > array.Length)
throw new IndexOutOfRangeException();

int dataSize = Marshal.SizeOf(typeof(T));
Buffer stagingBuffer = new Buffer(context.Device, dataSize * count, ResourceUsage.Staging,
BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.None, 0);

context.CopySubresourceRegion(buffer, 0,
new ResourceRegion(dataSize * index, 0, 0, dataSize * (index + count), 1, 1),
stagingBuffer, 0, 0, 0, 0);

DataBox box = context.MapSubresource(stagingBuffer, 0, dataSize * count,
MapMode.Read, SlimDX.Direct3D11.MapFlags.None);
box.Data.ReadRange<T>(array, arrayIndex, count);
context.UnmapSubresource(stagingBuffer, 0);

stagingBuffer.Dispose();
}

/// <summary>
/// Copies a range of data to another GPUList
/// </summary>
/// <param name="index">Index from which to start copying</param>
/// <param name="count">Number of elements to copy</param>
/// <param name="list">Destination list to copy to</param>
/// <param name="listIndex">Destination list index to copy to</param>
public void CopyRangeTo(int index, int count, GPUList<T> list, int listIndex)
{
if (count == 0)
return;

if (list == this)
throw new Exception("Cannot copy range into self...yet");

if (count < 0)
throw new IndexOutOfRangeException();
if (index < 0 || index >= Count)
throw new IndexOutOfRangeException();
if (index + count < 0 || index + count > Count)
throw new IndexOutOfRangeException();

if (list == null)
throw new ArgumentNullException();
if (listIndex < 0 || listIndex >= list.Count)
throw new IndexOutOfRangeException();
if (listIndex + list.Count < 0 || listIndex + count > list.Count)
throw new IndexOutOfRangeException();

int dataSize = Marshal.SizeOf(typeof(T));
context.CopySubresourceRegion(buffer, 0,
new ResourceRegion(dataSize * index, 0, 0, dataSize * (index + count), 1, 1),
list.buffer, 0, dataSize * listIndex, 0, 0);
}

/// <summary>
/// Copys the list to another GPUList
/// </summary>
/// <param name="array">The list to copy data to</param>
/// <param name="arrayIndex">The starting index in the array</param>
public void CopyTo(GPUList<T> list, int listIndex)
{
CopyRangeTo(0, count, list, listIndex);
}

/// <summary>
/// Trims excess capacity on the internal GPU buffer to match the count
/// </summary>
public void TrimExcess()
{
setCapacity(Count);
}

/// <summary>
/// Returns a copy of the list into an array
/// </summary>
/// <returns></returns>
public T[] ToArray()
{
T[] data = new T[Count];
CopyTo(data, 0);
return data;
}

/// <summary>
/// Sets the internal capacity of the list
/// </summary>
/// <param name="newCapacity"></param>
private void setCapacity(int newCapacity)
{
if (newCapacity < 0)
throw new ArgumentOutOfRangeException();

if (newCapacity == capacity)
return;

if (newCapacity == 0)
{
if (unorderedAccessView != null)
unorderedAccessView.Dispose();
if (shaderResourceView != null)
shaderResourceView.Dispose();
if (buffer != null)
buffer.Dispose();

unorderedAccessView = null;
shaderResourceView = null;
buffer = null;

capacity = count = 0;
return;
}

int dataSize = Marshal.SizeOf(typeof(T));
Buffer newBuffer = new Buffer(context.Device, dataSize * newCapacity, ResourceUsage.Default,
BindFlags.ShaderResource | BindFlags.UnorderedAccess,
CpuAccessFlags.None, ResourceOptionFlags.StructuredBuffer, dataSize);

int sizeToCopy = Math.Min(newCapacity, Count);
if (sizeToCopy > 0)
context.CopySubresourceRegion(buffer, 0, new ResourceRegion(0, 0, 0, dataSize * sizeToCopy, 1, 1), newBuffer, 0, 0, 0, 0);

count = sizeToCopy;
capacity = newCapacity;

if (unorderedAccessView != null)
unorderedAccessView.Dispose();
if (shaderResourceView != null)
shaderResourceView.Dispose();
if (buffer != null)
buffer.Dispose();

buffer = newBuffer;
unorderedAccessView = new UnorderedAccessView(context.Device, buffer);
shaderResourceView = new ShaderResourceView(context.Device, buffer);
}

#endregion

#region IDisposable Members

/// <summary>
/// Disposes the list by destroying all GPU resources used
/// </summary>
public void Dispose()
{
setCapacity(0);
}

#endregion

#region IList<T> Members

/// <summary>
/// Adds one item to the end of the list
/// </summary>
/// <param name="item">The item to add</param>
public void Add(T item)
{
T[] array = new T[] { item };
AddRange(array);
}

/// <summary>
/// Gets the index in the list of the first item found
/// </summary>
/// <param name="item">The item whose index is searched for</param>
/// <returns>Index of the item found, or -1 if not found</returns>
public int IndexOf(T item)
{
T[] data = new T[count];
CopyTo(data, 0);

for (int i = 0; i < data.Length; i++)
if (data[i].Equals(item))
return i;
return -1;
}

/// <summary>
/// Inserts an item at a specific index
/// </summary>
/// <param name="index">The index in the list to insert the item</param>
/// <param name="item">The item to insert</param>
public void Insert(int index, T item)
{
T[] array = new T[] { item };
InsertRange(index, array);
}

/// <summary>
/// Removes an item at a specific index
/// </summary>
/// <param name="index"></param>
public void RemoveAt(int index)
{
RemoveRange(index, 1);
}

/// <summary>
/// Gets or Sets an element at some index in the list
/// </summary>
/// <param name="index">Index in the list to get or set</param>
/// <returns></returns>
public T this[int index]
{
get
{
if (index < 0 || index >= count)
throw new IndexOutOfRangeException();

T[] array = new T[1];
CopyRangeTo(index, 1, array, 0);
return array[0];
}
set
{
if (index < 0 || index >= count)
throw new IndexOutOfRangeException();

T[] array = new T[] { value };
SetRange(index, array, 0, 1);
}
}

#endregion

#region ICollection<T> Members

/// <summary>
/// Clears the list of all elements
/// </summary>
public void Clear()
{
count = 0;
}

/// <summary>
/// Returns true if the item is contained in the list, or false if not
/// </summary>
/// <param name="item">The item to check containment for</param>
/// <returns></returns>
public bool Contains(T item)
{
foreach (T i in this)
if (i.Equals(item))
return true;
return false;
}

/// <summary>
/// Copys the list to an array
/// </summary>
/// <param name="array">The array to copy data to</param>
/// <param name="arrayIndex">The starting index in the array</param>
public void CopyTo(T[] array, int arrayIndex)
{
CopyRangeTo(0, count, array, arrayIndex);
}

/// <summary>
/// Gets the number of items in the list
/// </summary>
public int Count { get { return count; } }

/// <summary>
/// Returns whether or not the list is read only
/// </summary>
public bool IsReadOnly { get { return false; } }

/// <summary>
/// Removes an item from the list. Only the first item found is removed
/// </summary>
/// <param name="item">The item to remove</param>
/// <returns>True if the item is removed, false otherwise</returns>
public bool Remove(T item)
{
int index = IndexOf(item);
if (index >= 0)
RemoveAt(index);
return index >= 0;
}

#endregion

#region IEnumerable<T> Members

/// <summary>
/// Gets the enumerator for this list. Any changes made while enumerating will not be reflected
/// </summary>
/// <returns></returns>
public IEnumerator<T> GetEnumerator()
{
T[] array = new T[count];
CopyTo(array, 0);
return array.AsEnumerable<T>().GetEnumerator();
}

#endregion

#region IEnumerable Members

/// <summary>
/// Gets the enumerator for this list. Any changes made while enumerating will not be reflected
/// </summary>
/// <returns></returns>
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

#endregion
}
}
[/code]

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  

  • Similar Content

    • By gomidas
      I am trying to add normal map to my project I have an example of a cube: 
      I have normal in my shader I think. Then I set shader resource view for texture (NOT BUMP)
                  device.ImmediateContext.PixelShader.SetShaderResource(0, textureView);             device.ImmediateContext.Draw(VerticesCount,0); What should I do to set my normal map or how it is done in dx11 generally example c++?
    • By fighting_falcon93
      Imagine that we have a vertex structure that looks like this:
      struct Vertex { XMFLOAT3 position; XMFLOAT4 color; }; The vertex shader looks like this:
      cbuffer MatrixBuffer { matrix world; matrix view; matrix projection; }; struct VertexInput { float4 position : POSITION; float4 color : COLOR; }; struct PixelInput { float4 position : SV_POSITION; float4 color : COLOR; }; PixelInput main(VertexInput input) { PixelInput output; input.position.w = 1.0f; output.position = mul(input.position, world); output.position = mul(output.position, view); output.position = mul(output.position, projection); output.color = input.color; return output; } And the pixel shader looks like this:
      struct PixelInput { float4 position : SV_POSITION; float4 color : COLOR; }; float4 main(PixelInput input) : SV_TARGET { return input.color; } Now let's create a quad consisting of 2 triangles and the vertices A, B, C and D:
      // Vertex A. vertices[0].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); vertices[0].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex B. vertices[1].position = XMFLOAT3( 1.0f, 1.0f, 0.0f); vertices[1].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex C. vertices[2].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); vertices[2].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex D. vertices[3].position = XMFLOAT3( 1.0f, -1.0f, 0.0f); vertices[3].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // 1st triangle. indices[0] = 0; // Vertex A. indices[1] = 3; // Vertex D. indices[2] = 2; // Vertex C. // 2nd triangle. indices[3] = 0; // Vertex A. indices[4] = 1; // Vertex B. indices[5] = 3; // Vertex D. This will result in a grey quad as shown in the image below. I've outlined the edges in red color to better illustrate the triangles:

      Now imagine that we’d want our quad to have a different color in vertex A:
      // Vertex A. vertices[0].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); vertices[0].color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f);
      That works as expected since there’s now an interpolation between the black color in vertex A and the grey color in vertices B, C and D. Let’s revert the previus changes and instead change the color of vertex C:
      // Vertex C. vertices[2].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); vertices[2].color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f);
      As you can see, the interpolation is only done half of the way across the first triangle and not across the entire quad. This is because there's no edge between vertex C and vertex B.
      Which brings us to my question:
      I want the interpolation to go across the entire quad and not only across the triangle. So regardless of which vertex we decide to change the color of, the color interpolation should always go across the entire quad. Is there any efficient way of achieving this without adding more vertices and triangles?
      An illustration of what I'm trying to achieve is shown in the image below:

       
      Background
      This is just a very brief explanation of the problems background in case that would make it easier for you to understand the problems roots and maybe help you with finding a better solution to the problem.
      I'm trying to texture a terrain mesh in DirectX11. It's working, but I'm a bit unsatisfied with the result. When changing the terrain texture of a single vertex, the interpolation with the other vertices results in a hexagon shape instead of a squared shape:

      As the red arrows illustrate, I'd like the texture to be interpolated all the way into the corners of the quads.
    • By -Tau-
      Hello, I'm close to releasing my first game to Steam however, my game keeps failing the review process because it keeps crashing. The problem is that the game doesn't crash on my computer, on my laptop, on our family computer, on fathers laptop and i also gave 3 beta keys to people i know and they said the game hasn't crashed.
      Steam reports that the game doesn't crash on startup but few frames after a level has been started.
      What could cause something like this? I have no way of debugging this as the game works fine on every computer i have.
       
      Game is written in C++, using DirectX 11 and DXUT framework.
    • By haiiry
      I'm trying to get, basically, screenshot (each 1 second, without saving) of Direct3D11 application. Code works fine on my PC(Intel CPU, Radeon GPU) but crashes after few iterations on 2 others (Intel CPU + Intel integrated GPU, Intel CPU + Nvidia GPU).
      void extractBitmap(void* texture) { if (texture) { ID3D11Texture2D* d3dtex = (ID3D11Texture2D*)texture; ID3D11Texture2D* pNewTexture = NULL; D3D11_TEXTURE2D_DESC desc; d3dtex->GetDesc(&desc); desc.BindFlags = 0; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; desc.Usage = D3D11_USAGE_STAGING; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; HRESULT hRes = D3D11Device->CreateTexture2D(&desc, NULL, &pNewTexture); if (FAILED(hRes)) { printCon(std::string("CreateTexture2D FAILED:" + format_error(hRes)).c_str()); if (hRes == DXGI_ERROR_DEVICE_REMOVED) printCon(std::string("DXGI_ERROR_DEVICE_REMOVED -- " + format_error(D3D11Device->GetDeviceRemovedReason())).c_str()); } else { if (pNewTexture) { D3D11DeviceContext->CopyResource(pNewTexture, d3dtex); // Wokring with texture pNewTexture->Release(); } } } return; } D3D11SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast< void** >(&pBackBuffer)); extractBitmap(pBackBuffer); pBackBuffer->Release(); Crash log:
      CreateTexture2D FAILED:887a0005 DXGI_ERROR_DEVICE_REMOVED -- 887a0020 Once I comment out 
      D3D11DeviceContext->CopyResource(pNewTexture, d3dtex); 
      code works fine on all 3 PC's.
    • By Fluffy10
      Hi i'm new to this forum and was wondering if there are any good places to start learning directX 11. I bought Frank D Luna's book but it's really outdated and the projects won't even compile. I was excited to start learning from this book because it gives detailed explanations on the functions being used as well as the mathematics. Are there any tutorials / courses /books that are up to date which goes over the 3D math and functions in a detailed manner? Or where does anyone here learn directX 11? I've followed some tutorials from this website http://www.directxtutorial.com/LessonList.aspx?listid=11 which did a nice job but it doesn't explain what's happening with the math so I feel like I'm not actually learning, and it only goes up until color blending. Rasteriks tutorials doesn't go over the functions much at all or the math involved either. I'd really appreciate it if anyone can point me in the right direction, I feel really lost. Thank you
  • Popular Now