damix911

Members
  • Content count

    58
  • Joined

  • Last visited

Community Reputation

201 Neutral

About damix911

  • Rank
    Member
  1. Ashaman73, lTyl, bschmidt1962, thank you for your help; I'm happy to hear that it is a little bit of a secondary problem.
  2. Hello KurtO, just so you know (because it is actually a little counter-intuitive) your 8-series card [i]may[/i] support compute shaders, even though with some limitations. So you may want to give them a try, they could be useful to achieve some smoothing effects. You can refer to this thread for more info on this topic. [url="http://www.gamedev.net/topic/582066-the-question-about-directcompute-and-opencl/"]http://www.gamedev.net/topic/582066-the-question-about-directcompute-and-opencl/[/url] Basically as Asesh said the DirectX 11 API can be used to program DirectX 10 and even DirectX 9 hardware, but all the features you use must be available on that hardware, so DirectX 11 adds nohing in terms of functionality to these cards [i]except[/i] compute shaders, which actually work (I used to program them on my G210, DirectX 10 card).
  3. Let's say John is:[list] [*]a developer and he wrote a cross-platform networking library for MMORPG; [*]or maybe he's a graphic artist and he designed, modeled, textured and rigged a game character; [*]or maybe he's a musician and he composed a theme and recorded it as MP3. [/list] Now let's say he released his work under some [b]free[/b] [b]licence[/b], which basically allow people to use his work free of charge in their projects, provided that they are ad-free and are not distributed via a smartphone market like App Store, Google Play or Windows Marketplace; instead he just wants to be acknowledged in the credits or in the about box of the application. He also plans to provide a [b]commercial[/b] [b]licence[/b], including some form of support, for people intending to sell their products via one of the aforementioned stores; in this case John wants to charge them, in some way. [b]Question 1) How can John check if his stuff is being used by people who didn't buy a commercial license?[/b] It's probably impossible to detect all unauthorized usages, but maybe it is possible to design a system that automatically crawls the stores and performs some sort of analysis on the top-selling games. [b]Question 2) Are there systems like this in operation today?[/b] [b]Question 3) Do they take the form of a single web-crawler/analyzer?[/b] [b]Question 4) Or do they require the embedding of user/application specific information into the licensed content, possibly using a cryptographic authentication scheme?[/b] [b]Question 5) Should the content be delivered to the client in encrypted form?[/b] [b]Question 6) Are watermarking techniques useful for detecting unauthorized use of image and audio content in games?[/b] [b]Question 7) Is it reasonable to embed in a library an authentication routine that requires an Internet connection to John's servers? (I think it's not)[/b] After you suspect that someone stole your content, I guess the next step is calling a lawyer, and if you are really sure, suing the offending developer/publisher. Thank you for your help. Have a nice day. Dario
  4. Hi shiqiu1105, I just want to add that DirectX 11 interfaces can be used on so called "downlevel" hardware, that is hardware which supports DirectX 9 and DirectX 10; however some features will be unavailable and will cause your DX11 device creation request to fail in case you explicitly request them. For instance you can not use DX11 tesselation engine on DirectX 9 and 10 cards. However, just so you know DX11 DirectCompute works, with some limitations, on DirectX 10 (but NOT 9) cards. This post by me contains some information you may find useful. The reply to that topic posted on 3/9/2010 3:25:24 PM (which is the last one, at the time of writing) contains the working C++ and HLSL code. It works on my EN210, which is a DirectX 10.1 card, though much more recent than the GS8400. You could give it a try, and see if it works on yours. Bye, hopefully this was helpful! Dario EDIT: Now the link is the right one; previous one was wrong, sorry.
  5. Hello guys, I must have some sort of magnet for this kind of error. I have the following code in my effect: uniform float4x4 w; uniform float4x4 wv; uniform float4x4 wvp; uniform float4x4 wvpToTex; uniform float4 lightPositionsW[4]; uniform float4 lightColors[4]; uniform float4 lightDirsW[4]; uniform int nLights; void VSLighting( float4 iPosition : POSITION, float3 iNormal : NORMAL, float4 iColor : COLOR0, out float4 oPositionWVP : POSITION, out float4 oPositionWVP_TC : TEXCOORD3, out float4 oPositionW : TEXCOORD1, out float3 oNormalWV : TEXCOORD0, out float3 oNormalW : TEXCOORD2, out float4 oColor : COLOR0) { oPositionWVP = mul(iPosition, wvp); oPositionWVP_TC = mul(iPosition, wvp); oPositionW = mul(iPosition, w); oNormalWV = mul(iNormal, wv); oNormalW = mul(iNormal, w); oColor = iColor; } void PSLighting( float4 iPositionWVP : POSITION, float4 iPositionWVP_TC : TEXCOORD3, float4 iPositionW : TEXCOORD1, float3 iNormalWV : TEXCOORD0, float3 iNormalW : TEXCOORD2, float4 iColor : COLOR0, out float4 oColorValid : COLOR0, out float4 oPositionW : COLOR1, out float4 oNormalWDist : COLOR2) { oColorValid.rgb = iColor.rgb; oColorValid.a = 1.0f; oPositionW = iPositionW / iPositionW.w; oNormalWDist.xyz = normalize(iNormalW); oNormalWDist.w = iPositionWVP_TC.w; } The problem is in the following line in function VSLighting() oNormalW = mul(iNormal, w); Despite w being the identity matrix in my case, when I call DrawIndexedPrimitive() i get the following exceptions: First-chance exception at 0x003b00af in RSGI.exe: 0xC0000005: Access violation reading location 0x00244014. Unhandled exception at 0x003b00af in RSGI.exe: 0xC0000005: Access violation reading location 0x00244014. while, if i change that line in oNormalW = iNormal; everything seems to work fine. Even more weird than this, if I don't use TEXCOORD2 int the pixel shader, everything works fine no matter what the vertex shader looks like; that is, if I change line oNormalWDist.xyz = normalize(iNormalW); in the pixel shader to oNormalWDist.xyz = 123; everything works fine. If I run the program outside Visual Studio, aparently everything works fine no matter what the VS and PS look like. Now I am in a seaside resort, in a few days I'll go back home and I will have a real computer and a real Internet connection, and obviously I will update DXSDK and maybe drivers and everything, but it would be cool if you can think to some explanation. Thank you very much have a great day. Dario EDIT: I'm working on an Acer Aspire One with Intel GMA 945, DirectX SDK March 2009. All of this is happening with the REF device. EDIT 2: Could it be that I'm exceding the maximum number of instructions allowed for profile 3.0? If yes, why I'm not getting any warning or error, not even if I try to compile with FXC? And why outside of Visual Studio it works (aparently) without raising any exception? [Edited by - damix911 on September 2, 2010 10:38:44 AM]
  6. Hi AnthIste, I don't really know much about the topics you are talking about, however if you only need to create a device there are several working samples. The one I'm posting here is for a demo I made for a workshop at my university; it used to run under XP with GF 7600, Vista on a 2008 laptop, WinXP on a ATI 4850 and Win7 on GF 210. There isn't much error checking, however it should be quite portable. If you are developing on a non very recent laptop a parameter you should definitely consider is D3DCREATE_SOFTWARE_VERTEXPROCESSING in the CreateDevice call. Bye, hopefully that was helpful! Dario void Renderer::Init(HWND hWnd, HINSTANCE hInstance, int width, int height, bool windowed) { m_hWnd = hWnd; m_hInstance = hInstance; m_width = width; m_height = height; m_windowed = windowed; m_d3d = Direct3DCreate9(D3D_SDK_VERSION); D3DPRESENT_PARAMETERS d3dpp; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.BackBufferCount = 1; if (m_windowed) { d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; } else { d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; } d3dpp.BackBufferHeight = m_height; d3dpp.BackBufferWidth = m_width; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.hDeviceWindow = m_hWnd; d3dpp.MultiSampleQuality = 0; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.Windowed = (BOOL)m_windowed; hr = m_d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_d3dDevice); ...
  7. D3D11 Shader reflection

    Hi panic, thank you for the suggestion, I didn't really consider that aspect! It looks like it applies to variables in constant buffer, but I'm still not able to reflect Buffers declared in HLSL. By the way, in the meantime I completed the application, but I am unsatisfied because in the end I'm doing what I didn't want to do: UINT initCounts = 0; d3dContext->CSSetUnorderedAccessViews(0, 1, &viewY, &initCounts); d3dContext->CSSetShaderResources(0, 1, &viewX); d3dContext->CSSetShaderResources(1, 1, &viewB); d3dContext->CSSetConstantBuffers(0, 1, &buffCB); d3dContext->CSSetShader(compute, NULL, NULL); int nGroups = (N / 4) + ((N % 4) ? 1 : 0); d3dContext->Dispatch(nGroups, 1, 1); that is, blindy setting the slots in the same order as the (supposedly) corresponding variables appear in the HLSL. One of my mistakes was in the fact that I assumed that different kinds of resources used consecutive slots, while aparently different kinds are all based at slot 0. So the only non-zero slot I'm setting is the one for buffer viewB, because it is the second of its kind. The following is the full source code of my program, without reflection; it implements the vector operation: y := a * x + b where x, b and y are same-size vectors and a is a scalar, hopefully someone will find it useful! It should work on most DirectX 10 hardware; it was developed and tested on a GeForce 210 (DirectX 10.1). Code should be linked against d3d11.lib and d3dx11.lib. Bye! Dario Compute shader (compute.csh) RWStructuredBuffer<float> y; Buffer<float> x; Buffer<float> b; cbuffer CB { float a; int N; }; [numthreads(4, 1, 1)] void main(uint3 DTid : SV_DispatchThreadID) { int index = DTid.x; if (index < N) y[index] = a * x[index] + b[index]; } C++ Application (main.cpp) #include <iostream> #include <d3d11.h> #include <d3dx11.h> template<class T> inline void SafeRelease(T *&p) { if (p) { p->Release(); p = NULL; } } HRESULT ShowData(ID3D11Buffer *buff, int N, ID3D11Buffer *buffStaging, ID3D11DeviceContext *d3dContext) { d3dContext->CopyResource(buffStaging, buff); D3D11_MAPPED_SUBRESOURCE mapped; HRESULT hr = d3dContext->Map(buffStaging, 0, D3D11_MAP_READ, 0, &mapped); float *result = (float *)mapped.pData; for (int i = 0; i < N; ++i) { std::cout << " " << result[i]; } d3dContext->Unmap(buffStaging, 0); return hr; } int main(int argc, char *argv[]) { float a = 2.0f; int N = 13; HRESULT hr; ID3D11Device *d3dDevice; D3D_FEATURE_LEVEL features; ID3D11DeviceContext *d3dContext; hr = D3D11CreateDevice( NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, NULL, 0, D3D11_SDK_VERSION, &d3dDevice, &features, &d3dContext); ID3D10Blob *bytecode; ID3D10Blob *errors; hr = D3DX11CompileFromFile( L"compute.csh", NULL, NULL, "main", "cs_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &bytecode, &errors, NULL); if (errors) { MessageBoxA(NULL, (LPSTR)errors->GetBufferPointer(), "Error!", MB_ICONSTOP); errors->Release(); } ID3D11ComputeShader *compute; hr = d3dDevice->CreateComputeShader( bytecode->GetBufferPointer(), bytecode->GetBufferSize(), NULL, &compute); ID3D11Buffer *buffCB; ID3D11Buffer *buffY; ID3D11Buffer *buffX; ID3D11Buffer *buffB; ID3D11Buffer *buffStaging; D3D11_BUFFER_DESC descCB; descCB.BindFlags = D3D11_BIND_CONSTANT_BUFFER; descCB.ByteWidth = 16; descCB.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; descCB.MiscFlags = 0; descCB.StructureByteStride = 0; descCB.Usage = D3D11_USAGE_DYNAMIC; struct MyCB { float a; int N; int foo1; int foo2; } dataCB; dataCB.a = a; dataCB.N = N; D3D11_SUBRESOURCE_DATA initCB; initCB.pSysMem = &dataCB; initCB.SysMemPitch = 0; initCB.SysMemSlicePitch = 0; hr = d3dDevice->CreateBuffer(&descCB, &initCB, &buffCB); { D3D11_BUFFER_DESC descY; descY.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS; descY.ByteWidth = N * sizeof(float); descY.CPUAccessFlags = 0; descY.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; descY.StructureByteStride = sizeof(float); descY.Usage = D3D11_USAGE_DEFAULT; float *dataY = new float[N]; D3D11_SUBRESOURCE_DATA initY; initY.pSysMem = dataY; initY.SysMemPitch = 0; initY.SysMemSlicePitch = 0; hr = d3dDevice->CreateBuffer(&descY, &initY, &buffY); delete [] dataY; } { D3D11_BUFFER_DESC descX; descX.BindFlags = D3D11_BIND_SHADER_RESOURCE; descX.ByteWidth = N * sizeof(float); descX.CPUAccessFlags = 0; descX.MiscFlags = 0; descX.StructureByteStride = 0; descX.Usage = D3D11_USAGE_DEFAULT; float *dataX = new float[N]; for (int i = 0; i < N; ++i) dataX[i] = 10 * i; D3D11_SUBRESOURCE_DATA initX; initX.pSysMem = dataX; initX.SysMemPitch = 0; initX.SysMemSlicePitch = 0; hr = d3dDevice->CreateBuffer(&descX, &initX, &buffX); delete [] dataX; } { D3D11_BUFFER_DESC descB; descB.BindFlags = D3D11_BIND_SHADER_RESOURCE; descB.ByteWidth = N * sizeof(float); descB.CPUAccessFlags = 0; descB.MiscFlags = 0; descB.StructureByteStride = 0; descB.Usage = D3D11_USAGE_DEFAULT; float *dataB = new float[N]; for (int i = 0; i < N; ++i) dataB[i] = i; D3D11_SUBRESOURCE_DATA initB; initB.pSysMem = dataB; initB.SysMemPitch = 0; initB.SysMemSlicePitch = 0; hr = d3dDevice->CreateBuffer(&descB, &initB, &buffB); delete [] dataB; } ID3D11UnorderedAccessView *viewY; D3D11_UNORDERED_ACCESS_VIEW_DESC vDescY; vDescY.Format = DXGI_FORMAT_UNKNOWN; vDescY.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; vDescY.Buffer.FirstElement = 0; vDescY.Buffer.NumElements = N; vDescY.Buffer.Flags = 0; hr = d3dDevice->CreateUnorderedAccessView(buffY, &vDescY, &viewY); ID3D11ShaderResourceView *viewX; D3D11_SHADER_RESOURCE_VIEW_DESC vDescX; vDescX.Format = DXGI_FORMAT_R32_FLOAT; vDescX.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX; vDescX.BufferEx.FirstElement = 0; vDescX.BufferEx.NumElements = N; vDescX.BufferEx.Flags = 0; hr = d3dDevice->CreateShaderResourceView(buffX, &vDescX, &viewX); ID3D11ShaderResourceView *viewB; D3D11_SHADER_RESOURCE_VIEW_DESC vDescB; vDescB.Format = DXGI_FORMAT_R32_FLOAT; vDescB.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX; vDescB.BufferEx.FirstElement = 0; vDescB.BufferEx.NumElements = N; vDescB.BufferEx.Flags = 0; hr = d3dDevice->CreateShaderResourceView(buffB, &vDescB, &viewB); UINT initCounts = 0; d3dContext->CSSetUnorderedAccessViews(0, 1, &viewY, &initCounts); d3dContext->CSSetShaderResources(0, 1, &viewX); d3dContext->CSSetShaderResources(1, 1, &viewB); d3dContext->CSSetConstantBuffers(0, 1, &buffCB); d3dContext->CSSetShader(compute, NULL, NULL); int nGroups = (N / 4) + ((N % 4) ? 1 : 0); d3dContext->Dispatch(nGroups, 1, 1); D3D11_BUFFER_DESC descStaging; descStaging.BindFlags = 0; descStaging.ByteWidth = N * sizeof(float); descStaging.CPUAccessFlags = D3D11_CPU_ACCESS_READ; descStaging.MiscFlags = 0; descStaging.StructureByteStride = sizeof(float); descStaging.Usage = D3D11_USAGE_STAGING; float *dataStaging = new float[N]; D3D11_SUBRESOURCE_DATA initStaging; initStaging.pSysMem = dataStaging; initStaging.SysMemPitch = 0; initStaging.SysMemSlicePitch = 0; hr = d3dDevice->CreateBuffer(&descStaging, &initStaging, &buffStaging); delete [] dataStaging; std::cout << " " << a << " * " << std::endl; hr = ShowData(buffX, N, buffStaging, d3dContext); std::cout << " + " << std::endl; hr = ShowData(buffB, N, buffStaging, d3dContext); std::cout << " = " << std::endl; hr = ShowData(buffY, N, buffStaging, d3dContext); SafeRelease(buffCB); SafeRelease(buffY); SafeRelease(buffX); SafeRelease(buffB); SafeRelease(buffStaging); SafeRelease(viewY); SafeRelease(viewX); SafeRelease(viewB); SafeRelease(bytecode); SafeRelease(errors); SafeRelease(compute); SafeRelease(d3dDevice); SafeRelease(d3dContext); std::cin.get(); return 0; }
  8. Hi guys! I'm not being able to retrieve reflection info from my compute shader. I have the following C++ code: ID3D11ComputeShader *compute; hr = d3dDevice->CreateComputeShader( bytecode->GetBufferPointer(), bytecode->GetBufferSize(), NULL, &compute); d3dContext->CSSetShader(compute, NULL, NULL); ID3D11ShaderReflection *computeRefl; hr = D3DReflect( bytecode->GetBufferPointer(), bytecode->GetBufferSize(), IID_ID3D11ShaderReflection, (void **)&computeRefl); D3D11_SHADER_VARIABLE_DESC descA; computeRefl->GetVariableByName("a")->GetDesc(&descA); D3D11_SHADER_VARIABLE_DESC descY; computeRefl->GetVariableByName("y")->GetDesc(&descY); And an empty compute shader that declares the following global variables: RWStructuredBuffer<float> y; float a; StructuredBuffer<float> x; StructuredBuffer<float> b; int N; ... Both calls to GetVariableByName return something invalid, unless I put variable a inside a constant buffer, in which case the first call works fine. I'm doing this because in the end I want to retrieve the input slots of the variable, in order to set the input values; I saw some examples on the Internet in which people call CSSetShaderResources and CSSetUnorderedAccessViews passing 0 as the first parameter, but I couldn't find anything in the MSDN saying that by doing this they actually access the first global variable of the shader. Any suggestion? Thank you! Dario
  9. Cool, it looks like you are close to solving the problem; just out of curiosity I want to post this code, which is a version that uses a length computed with 3 components. This is very close to your initial guess, the differences are (1) in the vector subtraction, as noted by jyk; (2) in the fact that it uses asin in place of acos; (3) in the fact that considers the OpenGL reference frame, which is right handed with y-axis being up. Bye! #include <stdio.h> #include <math.h> int main(int argc, char *argv[]) { float x1 = -1; float y1 = -1; float z1 = 3; float position_x = 1; float position_y = 1; float position_z = 1; float v_x = x1 - position_x; float v_y = y1 - position_y; float v_z = z1 - position_z; float length = sqrt(v_x * v_x + v_y * v_y + v_z * v_z); float pitch = asin(v_y / length); float yaw = atan2(v_z, v_x); printf("Pitch = %d\n", (int)(180 * (pitch / 3.1415))); printf("Yaw = %d\n", (int)(180 * (yaw / 3.1415))); return 0; }
  10. Hi Wavesonics, I tried the following code and it works; It's pretty much what jyk was suggesting, however I still post it. However here I explicitly assume a right-hand setting in which plane XZ is the ground and y-axis is the UP direction, which I think would be the case in a typical OpenGL setting. The program outputs: Pitch = -35 Yaw = 135 Which makes sense for the input. Bye! #include <stdio.h> #include <math.h> int main(int argc, char *argv[]) { float x1 = -1; float y1 = -1; float z1 = 3; float position_x = 1; float position_y = 1; float position_z = 1; float v_x = x1 - position_x; float v_y = y1 - position_y; float v_z = z1 - position_z; float length = sqrt(v_x * v_x + v_z * v_z); float pitch = atan2(v_y, length); float yaw = atan2(v_z, v_x); printf("Pitch = %d\n", (int)(180 * (pitch / 3.1415))); printf("Yaw = %d\n", (int)(180 * (yaw / 3.1415))); return 0; }
  11. Hi xnunes, Reference devices are software implementation of the Direct3D api; they are unrelated with the driver and the hardware, and they fully implement the entire Direct3D api. However they are extremely slow and cannot be used in production. However they are useful for debugging and testing, especially if you want to know if you wrote the right code or not. If something doesn't work with the reference device, it's extremely likely to be wrong. If something works with the reference device but not with the hardware device then it's likely to be correct, and maybe there is a problem in either the hardware or the driver. D3DDEVTYPE Enumeration CreateDevice Method
  12. Hi xnunes, in my short experience as a hobbyist graphic programmer I experienced this kind of problems, and in my case usually got solved switching from a 2.0 profile to a 3.0 profile. I usually set my shaders to the maximum supported profile, both for vertex, pixel and geometry in D3D10. But if you are working on a project that will be released I guess this might not be the best option. I only played a little bit with the Pix debugger and I don't know much about it, however I would recommend you to test rendering with a reference device and see what happens. Use D3DDEVTYPE_REF in Direct3D 9 Use D3D_DRIVER_TYPE_REFERENCE in Direct3D 10 and 11 Bye, have a nice day! Dario
  13. Woah! Amazing, it works! Thank you so much! I had seen those pages but I didn't really investigate too much, sorry. I post the updated code, which now works both with reference 11 and with hardware 10.1 devices, on my GeForce 210. You explained everything perfectly, however I would like to point out again that: In the effect file, profiles MUST be vs/gs/ps_4_0; the technique can be either 10 or 11. technique10 MyTechnique { pass P0 { SetVertexShader(CompileShader(vs_4_0, VS())); SetGeometryShader(CompileShader(gs_4_0, GS())); SetPixelShader(CompileShader(ps_4_0, PS())); } } When compiling the effect, the profile MUST be fx_5_0. hr = D3DX11CompileFromFile(L"effect.fx", NULL, NULL, "MeThinksItSReallyUseless", "fx_5_0", 0, 0, 0, &effectBytecode, &blob, NULL); Anything else didn't work, for me. These are the updated sources: #include <windows.h> #include <d3d11.h> #include <d3dx11effect.h> #include <d3dx11.h> #include <xnamath.h> struct VertexP { XMFLOAT4 position; }; LRESULT CALLBACK WndMainProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { int WIDTH = 640; int HEIGHT = 480; LPWSTR CLASSNAME = L"WndMain"; DWORD STYLE = WS_OVERLAPPEDWINDOW; D3D_DRIVER_TYPE DRIVER_TYPE = D3D_DRIVER_TYPE_HARDWARE; HRESULT hr; WNDCLASSEX wc; wc.cbClsExtra = 0; wc.cbSize = sizeof(wc); wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.hInstance = hInst; wc.lpfnWndProc = WndMainProc; wc.lpszClassName = CLASSNAME; wc.lpszMenuName = NULL; wc.style = 0; RegisterClassEx(&wc); RECT rect = {0, 0, WIDTH, HEIGHT}; AdjustWindowRectEx(&rect, STYLE, NULL, 0); HWND hWnd = CreateWindowEx(0, CLASSNAME, L"DirectX 11 Application", STYLE, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInst, NULL); DXGI_SWAP_CHAIN_DESC scDesc; scDesc.BufferCount = 1; scDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; scDesc.BufferDesc.Height = HEIGHT; scDesc.BufferDesc.Width = WIDTH; scDesc.BufferDesc.RefreshRate.Numerator = 60; scDesc.BufferDesc.RefreshRate.Denominator = 1; scDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; scDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; scDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; scDesc.Flags = 0; scDesc.OutputWindow = hWnd; scDesc.SampleDesc.Count = 1; scDesc.SampleDesc.Quality = 0; scDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; scDesc.Windowed = TRUE; D3D_FEATURE_LEVEL featureLevel; hr = D3D11CreateDevice(NULL, DRIVER_TYPE, NULL, D3D11_CREATE_DEVICE_DEBUG, NULL, 0, D3D11_SDK_VERSION, NULL, &featureLevel, NULL); D3D_FEATURE_LEVEL featLevels[1] = {featureLevel}; ID3D11Device *d3dDevice; ID3D11DeviceContext *d3dDeviceContext; IDXGISwapChain *swapChain; hr = D3D11CreateDeviceAndSwapChain(NULL, DRIVER_TYPE, NULL, D3D11_CREATE_DEVICE_DEBUG, featLevels, 1, D3D11_SDK_VERSION, &scDesc, &swapChain, &d3dDevice, NULL, NULL); d3dDevice->GetImmediateContext(&d3dDeviceContext); ID3D11Texture2D *backBuffer; hr = swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void **>(&backBuffer)); ID3D11RenderTargetView *renderTargetView; hr = d3dDevice->CreateRenderTargetView(backBuffer, 0, &renderTargetView); D3D11_TEXTURE2D_DESC depthStencilDesc; depthStencilDesc.ArraySize = 1; depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthStencilDesc.CPUAccessFlags = 0; depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthStencilDesc.Height = HEIGHT; depthStencilDesc.Width = WIDTH; depthStencilDesc.MipLevels = 1; depthStencilDesc.MiscFlags = 0; depthStencilDesc.SampleDesc.Count = 1; depthStencilDesc.SampleDesc.Quality = 0; depthStencilDesc.Usage = D3D11_USAGE_DEFAULT; ID3D11Texture2D *depthStencilBuffer; hr = d3dDevice->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer); ID3D11DepthStencilView *depthStencilView; hr = d3dDevice->CreateDepthStencilView(depthStencilBuffer, NULL, &depthStencilView); d3dDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView); D3D11_VIEWPORT vp; vp.TopLeftX = 0.0f; vp.TopLeftY = 0.0f; vp.Width = (FLOAT)WIDTH; vp.Height = (FLOAT)HEIGHT; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; d3dDeviceContext->RSSetViewports(1, &vp); D3D11_INPUT_ELEMENT_DESC iedP[] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0} }; ID3D10Blob *blob; ID3D10Blob *effectBytecode; ID3DX11Effect *effect; ID3DX11EffectTechnique *effectTechnique; ID3DX11EffectPass *effectPass; D3DX11_PASS_DESC passDesc; ID3D11InputLayout *ilP; hr = D3DX11CompileFromFile(L"effect.fx", NULL, NULL, "MeThinksItSReallyUseless", "fx_5_0", 0, 0, 0, &effectBytecode, &blob, NULL); if (FAILED(hr)) { if (blob) { MessageBoxA(hWnd, reinterpret_cast<char *>(blob->GetBufferPointer()), "Error!", 0); } else { MessageBoxA(hWnd, "An error occurred.", "Error!", 0); } return -1; } hr = D3DX11CreateEffectFromMemory(effectBytecode->GetBufferPointer(), effectBytecode->GetBufferSize(), 0, d3dDevice, &effect); effectTechnique = effect->GetTechniqueByName("MyTechnique"); effectPass = effectTechnique->GetPassByIndex(0); hr = effectPass->GetDesc(&passDesc); hr = d3dDevice->CreateInputLayout(iedP, 1, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &ilP); VertexP vertices[1]; vertices[0].position = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); D3D11_SUBRESOURCE_DATA initData; initData.pSysMem = vertices; ID3D11Buffer *vertexBuffer; D3D11_BUFFER_DESC bufferDesc; bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bufferDesc.ByteWidth = sizeof(vertices); bufferDesc.CPUAccessFlags = 0; bufferDesc.MiscFlags = 0; bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; bufferDesc.StructureByteStride = 0; hr = d3dDevice->CreateBuffer(&bufferDesc, &initData, &vertexBuffer); ShowWindow(hWnd, nCmdShow); MSG msg; bool run = true; while (run) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { run = false; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { FLOAT clearColor[4] = {0.0f, 0.0f, 0.0f, 1.0f}; d3dDeviceContext->ClearRenderTargetView(renderTargetView, clearColor); d3dDeviceContext->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); hr = effectTechnique->GetPassByIndex(0)->Apply(0, d3dDeviceContext); UINT stride = sizeof(VertexP); UINT offset = 0; d3dDeviceContext->IASetInputLayout(ilP); d3dDeviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); d3dDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); d3dDeviceContext->Draw(1, 0); hr = swapChain->Present(0, 0); } } return msg.wParam; } LRESULT CALLBACK WndMainProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } } struct Vertex { float4 position : POSITION; }; struct Fragment { float4 position : SV_POSITION; float4 color : COLOR; }; Vertex VS(Vertex vertex) { return vertex; } [maxvertexcount(3)] void GS(point Vertex p[1], inout TriangleStream<Fragment> o) { Fragment v1; v1.position = p[0].position; v1.position.x += 0.1f; v1.position.y -= 0.1f; v1.color = float4(1.0f, 0.0f, 0.0f, 1.0f); Fragment v2; v2.position = p[0].position; v2.position.x -= 0.1f; v2.position.y -= 0.1f; v2.color = float4(0.0f, 1.0f, 0.0f, 1.0f); Fragment v3; v3.position = p[0].position; v3.position.y += 0.1f; v3.color = float4(0.0f, 0.0f, 1.0f, 1.0f); o.Append(v1); o.Append(v2); o.Append(v3); } float4 PS(Fragment fragment) : SV_Target { return fragment.color; } technique10 MyTechnique { pass P0 { SetVertexShader(CompileShader(vs_4_0, VS())); SetGeometryShader(CompileShader(gs_4_0, GS())); SetPixelShader(CompileShader(ps_4_0, PS())); } }
  14. D3D10 input signatures

    @DieterVW @Shd Thank you for your help, if I discover something on this missing field I'll post it. And I'll try the GetInputElementDesc() way. Thank you have a nice weekend! Dario
  15. Hi everybody, from what I read, it looks like D3D11 interfaces works on D3D10 class devices; I have a GeForce G210 which supposedly is a 10.1 device and I'm trying to convert a very simple working application I wrote yesterday for D3D10 to D3D11. Fifth line of WinMain is: D3D_DRIVER_TYPE DRIVER_TYPE = D3D_DRIVER_TYPE_REFERENCE; This way, everything works. With the following code: D3D_FEATURE_LEVEL featureLevel; hr = D3D11CreateDevice(NULL, DRIVER_TYPE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, &featureLevel, NULL); the detected feature level is D3D_FEATURE_LEVEL_11_0 which makes sense since it's a reference device. Not surprisingly, if I change the device to: D3D_DRIVER_TYPE DRIVER_TYPE = D3D_DRIVER_TYPE_HARDWARE; the detected feature level is D3D_FEATURE_LEVEL_10_1; and all the called methods seems to work, except the most important one: d3dDeviceContext->Draw(1, 0); which fails, epically, with an access violation exception: Unhandled exception at 0x6ea5a29d in First.exe: 0xC0000005: Access violation reading location 0x00000240. Full source code is provided below. Thank you for the time you will eventually spend to help me. Obviously if this source is useful for you in any way you are free to use it. I have also two more questions, regarding D3DX11CompileEffectFromFile: 1) What is an function name entry point for an effect file? I understand the concept of entry point for a shader file, but in an effect file to me seems redundant. What should I specify as parameter 4? 2) Why fx_5_0 seems to be the only supported profile for parameter 5? If I try to specify fx_4_0 it doesn't work. I would like to add a compute shader to perform a very simple N-Body simulation; it would be cool to have a simple application that in less than 400 lines shows how to use the four type of shaders supported by D3D10 devices. Obviously once it's done I will post the code here or on my journal. Thank you and have a nice day! #include <windows.h> #include <d3d11.h> #include <d3dx11effect.h> #include <d3dx11.h> #include <xnamath.h> struct VertexP { XMFLOAT4 position; }; LRESULT CALLBACK WndMainProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { int WIDTH = 640; int HEIGHT = 480; LPWSTR CLASSNAME = L"WndMain"; DWORD STYLE = WS_OVERLAPPEDWINDOW; D3D_DRIVER_TYPE DRIVER_TYPE = D3D_DRIVER_TYPE_REFERENCE; HRESULT hr; WNDCLASSEX wc; wc.cbClsExtra = 0; wc.cbSize = sizeof(wc); wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.hInstance = hInst; wc.lpfnWndProc = WndMainProc; wc.lpszClassName = CLASSNAME; wc.lpszMenuName = NULL; wc.style = 0; RegisterClassEx(&wc); RECT rect = {0, 0, WIDTH, HEIGHT}; AdjustWindowRectEx(&rect, STYLE, NULL, 0); HWND hWnd = CreateWindowEx(0, CLASSNAME, L"DirectX 11 Application", STYLE, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInst, NULL); DXGI_SWAP_CHAIN_DESC scDesc; scDesc.BufferCount = 1; scDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; scDesc.BufferDesc.Height = HEIGHT; scDesc.BufferDesc.Width = WIDTH; scDesc.BufferDesc.RefreshRate.Numerator = 60; scDesc.BufferDesc.RefreshRate.Denominator = 1; scDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; scDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; scDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; scDesc.Flags = 0; scDesc.OutputWindow = hWnd; scDesc.SampleDesc.Count = 1; scDesc.SampleDesc.Quality = 0; scDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; scDesc.Windowed = TRUE; D3D_FEATURE_LEVEL featureLevel; hr = D3D11CreateDevice(NULL, DRIVER_TYPE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, &featureLevel, NULL); D3D_FEATURE_LEVEL featLevels[1] = {featureLevel}; ID3D11Device *d3dDevice; ID3D11DeviceContext *d3dDeviceContext; IDXGISwapChain *swapChain; hr = D3D11CreateDeviceAndSwapChain(0, DRIVER_TYPE, 0, 0, featLevels, 1, D3D11_SDK_VERSION, &scDesc, &swapChain, &d3dDevice, NULL, NULL); d3dDevice->GetImmediateContext(&d3dDeviceContext); ID3D11Texture2D *backBuffer; hr = swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void **>(&backBuffer)); ID3D11RenderTargetView *renderTargetView; hr = d3dDevice->CreateRenderTargetView(backBuffer, 0, &renderTargetView); D3D11_TEXTURE2D_DESC depthStencilDesc; depthStencilDesc.ArraySize = 1; depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthStencilDesc.CPUAccessFlags = 0; depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthStencilDesc.Height = HEIGHT; depthStencilDesc.Width = WIDTH; depthStencilDesc.MipLevels = 1; depthStencilDesc.MiscFlags = 0; depthStencilDesc.SampleDesc.Count = 1; depthStencilDesc.SampleDesc.Quality = 0; depthStencilDesc.Usage = D3D11_USAGE_DEFAULT; ID3D11Texture2D *depthStencilBuffer; hr = d3dDevice->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer); ID3D11DepthStencilView *depthStencilView; hr = d3dDevice->CreateDepthStencilView(depthStencilBuffer, NULL, &depthStencilView); d3dDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView); D3D11_VIEWPORT vp; vp.TopLeftX = 0.0f; vp.TopLeftY = 0.0f; vp.Width = (FLOAT)WIDTH; vp.Height = (FLOAT)HEIGHT; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; d3dDeviceContext->RSSetViewports(1, &vp); D3D11_INPUT_ELEMENT_DESC iedP[] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0} }; ID3D10Blob *blob; ID3D10Blob *effectBytecode; ID3DX11Effect *effect; ID3DX11EffectTechnique *effectTechnique; ID3DX11EffectPass *effectPass; D3DX11_PASS_DESC passDesc; ID3D11InputLayout *ilP; hr = D3DX11CompileFromFile(L"effect.fx", NULL, NULL, "MyTechnique", "fx_5_0", 0, 0, 0, &effectBytecode, &blob, NULL); if (FAILED(hr)) { if (blob) { MessageBoxA(hWnd, reinterpret_cast<char *>(blob->GetBufferPointer()), "Error!", 0); } else { MessageBoxA(hWnd, "An error occurred.", "Error!", 0); } return -1; } hr = D3DX11CreateEffectFromMemory(effectBytecode->GetBufferPointer(), effectBytecode->GetBufferSize(), 0, d3dDevice, &effect); effectTechnique = effect->GetTechniqueByName("MyTechnique"); effectPass = effectTechnique->GetPassByIndex(0); hr = effectPass->GetDesc(&passDesc); hr = d3dDevice->CreateInputLayout(iedP, 1, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &ilP); VertexP vertices[1]; vertices[0].position = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); D3D11_SUBRESOURCE_DATA initData; initData.pSysMem = vertices; ID3D11Buffer *vertexBuffer; D3D11_BUFFER_DESC bufferDesc; bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bufferDesc.ByteWidth = sizeof(vertices); bufferDesc.CPUAccessFlags = 0; bufferDesc.MiscFlags = 0; bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; bufferDesc.StructureByteStride = 0; hr = d3dDevice->CreateBuffer(&bufferDesc, &initData, &vertexBuffer); ShowWindow(hWnd, nCmdShow); MSG msg; bool run = true; while (run) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { run = false; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { FLOAT clearColor[4] = {0.0f, 0.0f, 0.0f, 1.0f}; d3dDeviceContext->ClearRenderTargetView(renderTargetView, clearColor); d3dDeviceContext->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); hr = effectTechnique->GetPassByIndex(0)->Apply(0, d3dDeviceContext); UINT stride = sizeof(VertexP); UINT offset = 0; d3dDeviceContext->IASetInputLayout(ilP); d3dDeviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); d3dDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); d3dDeviceContext->Draw(1, 0); hr = swapChain->Present(0, 0); } } return msg.wParam; } LRESULT CALLBACK WndMainProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } } struct Vertex { float4 position : POSITION; }; struct Fragment { float4 position : SV_POSITION; float4 color : COLOR; }; Vertex VS(Vertex vertex) { return vertex; } [maxvertexcount(3)] void GS(point Vertex p[1], inout TriangleStream<Fragment> o) { Fragment v1; v1.position = p[0].position; v1.position.x += 0.1f; v1.position.y -= 0.1f; v1.color = float4(1.0f, 0.0f, 0.0f, 1.0f); Fragment v2; v2.position = p[0].position; v2.position.x -= 0.1f; v2.position.y -= 0.1f; v2.color = float4(0.0f, 1.0f, 0.0f, 1.0f); Fragment v3; v3.position = p[0].position; v3.position.y += 0.1f; v3.color = float4(0.0f, 0.0f, 1.0f, 1.0f); o.Append(v1); o.Append(v2); o.Append(v3); } float4 PS(Fragment fragment) : SV_Target { return fragment.color; } technique11 MyTechnique { pass P0 { SetVertexShader(CompileShader(vs_5_0, VS())); SetGeometryShader(CompileShader(gs_5_0, GS())); SetPixelShader(CompileShader(ps_5_0, PS())); } } [Edited by - damix911 on January 16, 2010 10:14:44 AM]