Jump to content
  • Advertisement

directx user

  • Content Count

  • Joined

  • Last visited

Community Reputation

155 Neutral

About directx user

  • Rank
  1. directx user

    X3000 using enum in hlsl shader

    Well thats unfortunate, I dont know why enum is listed in the msdn then.  http://msdn.microsoft.com/en-us/library/windows/desktop/bb509569(v=vs.85).aspx   Maybe they are only reserving it to implement it later.But anyway thx for the quick explanation.   But anyway I dont know, why it would be so difficult to implement something simple as enums, which is only a mater of replacing strings with numbers.
  2. Hi,   I am building an Algorithm, which is suposed to run on both, the cpu and the gpu. It would be really usefull if I could just use my enum in the shaders header file and could just include it in both, my cpp and the hlsl shader itself (enum determines which function is going to be executed). But Unluckily I always get the error X3000 unexspected token when i try to use enums in my shader.   On the internet I read that enum is a reserved keyword for HLSL though I found very few examples of HLSL Code using enums, it should be possible or am I wrong?   Not even this hlsl file compiles: enum { test1, test2}; [numthreads(8, 1, 1)] void CS_NEW( uint ID : SV_DispatchThreadID ) { } I am using the Inbuild HLSL Compiler from Visual Studio 2012, am I the only one having this Issue?
  3. directx user

    Exceptions using createcomputeshader

    Thank you very much, I didn´t even validated the device pointer, as I knew my other Shaders compiled fine with the device. I unluckily forgot there to be another device declared inside the class overwriting the definition of the one outside the scope of the class. The devicepointer was not assigned to that one yet and was a zero pointer...   Thank you very much for that hint, now I feel really bad having bothered you two with this laughable problem .       Besides from that, does anyone has a clue why I end up getting those redefinition warnings after transfering visual c++ 2010 projects to visual studio 2012?
  4. directx user

    Exceptions using createcomputeshader

    Unluckily even when everything except the naked function body is commented i get the same results (the compiled length decreased so I guess its updating the file), even though the array is still pretty large with 1000 lines of code, while everything thats left is: [numthreads(128, 1, 1)] void BACKPROPAGATE( uint ID : SV_DispatchThreadID  ) { } There are no erros or warnings being displayed about the shader file.   But I have extremly many warnings about makro redefinitions in the context of directx(80) which could eventually aflict that case (I have those warnings since I exported my project from visual c++ 2010 to visual studio 2012). I dont really knwo why.
  5. directx user

    Exceptions using createcomputeshader

    I added the shader definition. I thought the Array would be fixed size, since its getting written into the header file while compiling the project, its definition is const BYTE backpropshader[] = { ...... tons of code...... } so I thought I could just use its size to feed the function, relying on the msdn:   http://msdn.microsoft.com/en-us/library/windows/desktop/bb509633%28v=vs.85%29.aspx#compiling_at_build_time_to_header_files   I thought the blob method would only be used when creating the shader at runtime using compileshaderfromfile for example?
  6. Hi guys,   I am working in Visual Studio 2012 and I need to create a computeshader, which is with its 250 lines quite big, so i decided to precreate it with the inbuild HLSL compiler by generating a header file. The compiler didnt complained at all and the binary Array just got created, but if i want to bind the data to a shader object uisng the line: device->CreateComputeShader(backpropshader, sizeof(backpropshader), NULL, &berechner); backpropshader being the binary buffer in the header file, the Application raises an acess violation Exception. Does anyone know how this Exception could arise? I am also concerned about the binary array to be 23 thousand lines long, is that normal?   the Shader is suposed to use the Backpropagation algorithm on several neuronal systems parallely: This is the Shader reduced to a few lines, I hope its understandable though many of the variablenames are german.   cbuffer konstanten : register(b0) {     uint systemcount;     uint neuronencount;     uint ausgaenge;     uint eingaenge;     uint vorgabensegment;     uint vorgabencount;     uint aufgabencount;     uint lernschritte;     uint lernstaerke; }; struct Verbindung {     uint start;     uint ende;     float gewicht; }; struct neurondaten {     float eingabe;     float ausgabe;     uint transfermodus;     float fehler; }; StructuredBuffer<float> Vorgabentemplate : register(u0); RWStructuredBuffer<Verbindung> Verbindungen : register(u1); RWStructuredBuffer<neurondaten> Neurone : register(u2); void PROPAGATE(uint basisvorgabe, uint basisneuron, uint basisverbindung, uint endverbindung) {     Neurone[basisneuron].ausgabe = 1.0f; //Biasneuron gleich setzen     for (unsigned int einschreib1 = 1; einschreib1 < eingaenge; einschreib1++)     {         Neurone[basisneuron + einschreib1].ausgabe = Vorgabentemplate[basisvorgabe + einschreib1 - 1];     }     for (unsigned int einschreib2 = 1 + eingaenge; einschreib2 < neuronencount; einschreib2++)     {         Neurone[basisneuron + einschreib2].eingabe = 0;         Neurone[basisneuron + einschreib2].fehler = 0;     }     //Neurone sind im Grundzustand     for (unsigned int i = basisverbindung; i < endverbindung; i++)     {         if (Verbindungen[i].start == Verbindungen[i].ende)         {             switch (Neurone[Verbindungen[i].start].transfermodus)             {                  ....................             }         }         else         {             Neurone[Verbindungen[i].ende].eingabe += Neurone[Verbindungen[i].start].ausgabe * Verbindungen[i].gewicht;         }     } } [numthreads(128, 1, 1)] void BACKPROPAGATE( uint ID : SV_DispatchThreadID  ) {     if (ID < systemcount)     {         float restfehler = 0;         uint basisneuron = neuronencount * ID;         uint basisverbindung = aufgabencount * ID;         uint endbasisverbindung = aufgabencount * (ID + 1);         for (unsigned int durchgang = 0; durchgang < lernschritte; durchgang++)         {             restfehler = 0;             uint basisvorgabe = 0;             for (unsigned int vorgabenzaehler = 0; vorgabenzaehler < vorgabencount; vorgabenzaehler++)             {                 PROPAGATE(basisvorgabe,basisneuron,basisverbindung, endbasisverbindung);                 for (unsigned int fehlerstart = neuronencount - ausgaenge; fehlerstart < neuronencount; fehlerstart++)                 {                     Neurone[basisneuron + fehlerstart].fehler = Neurone[basisneuron + fehlerstart].eingabe - Vorgabentemplate[basisvorgabe + eingaenge];                     restfehler += Neurone[basisneuron + fehlerstart].fehler * Neurone[basisneuron + fehlerstart].fehler;                 }                                for (unsigned int i = endbasisverbindung - 1; i-- > basisverbindung;)                 {                     if (Verbindungen[i].start == Verbindungen[i].ende) //refreshe den fehler                     {                         switch (Neurone[Verbindungen[i].start].transfermodus)                         {                             ..........                         }                     }                     else                     {                         Verbindungen[i].gewicht -= lernschritte * Neurone[Verbindungen[i].ende].fehler * Neurone[Verbindungen[i].start].ausgabe;                         Neurone[Verbindungen[i].start].fehler += Neurone[Verbindungen[i].ende].fehler * Verbindungen[i].gewicht;                     }                 }                 basisvorgabe += vorgabensegment;             }         }           } }  
  7. directx user

    adress mode issues

    hi, iam currently having some issues with my sample texture to wrap proper on my geodesic sphere, actually it seems like the address mode of my sampler doesnt works. I need the texture to repeat on the other side of the sphere, so i assigned a wrap samplerstate: D3D11_SAMPLER_DESC samplerdesc = D3D11_SAMPLER_DESC();ZeroMemory( &samplerdesc, sizeof(samplerdesc) );samplerdesc.AddressU = D3D11_TEXTURE_ADDRESS_MODE::D3D11_TEXTURE_ADDRESS_WRAP;samplerdesc.AddressV = D3D11_TEXTURE_ADDRESS_MODE::D3D11_TEXTURE_ADDRESS_WRAP;samplerdesc.Filter = D3D11_FILTER::D3D11_FILTER_ANISOTROPIC;device->CreateSamplerState(&samplerdesc,&sampstate);////////////////////////////////immediatecontext->PSSetSamplers(0,1,&sampstate);immediatecontext->VSSetSamplers(0,1,&sampstate);Shadercode: Texture2D<float4> Textur : register(t0);sampler sampler1 : register(s0);cbuffer Matrix : register( b0 ){ row_major matrix World; row_major matrix View; row_major matrix Projection;};struct VS_INPUT{ float4 Pos : POSITION; float2 texcoord : TEXCOORD;};struct PS_INPUT{ float4 Pos : SV_POSITION; float2 texcoord : TEXCOORD;};//--------------------------------------------------------------------------------------// Vertex Shader//--------------------------------------------------------------------------------------PS_INPUT VS( VS_INPUT input ){ PS_INPUT output = (PS_INPUT)0; output.Pos = mul(input.Pos,World); output.Pos = mul(output.Pos,View); output.Pos = mul(output.Pos,Projection); output.texcoord = input.texcoord; return output;}//--------------------------------------------------------------------------------------// Pixel Shader//--------------------------------------------------------------------------------------float4 PS( PS_INPUT input) : SV_Target{ float4 ret = Textur.Sample(sampler1,input.texcoord); return ret;}Is there a problem with the shader itself? The resolution of the image is 512X512, so there shouldnt be a problem with it?[attachment=12894:merkurfail.PNG] the u coordinate ranges from 0 to 2, and the white strip has nothing to do with the texture, will replace it soon edit: Its working now, i missed to set the addressmode w parameter in the samplerstate, but i have another question anyway. While searching in the internet i saw this code snippet: Texture2D Textur : register(t0); SamplerState sampler1 : register(s0); while i used this one: Texture2D<float4> Textur : register(t0); sampler sampler1 : register(s0); both is working but where is the difference, besides the float4 telling hlsl the format.
  8. directx user

    DX11 multiple objects performance issue

    thx for your reply, i now got the instancing working but theres anyway still a question that i want to ask: As i set the vertexbuffers one for the model and the other one for the instance position etc., how does directx knows wich buffer is ment to be the geometrie buffer and which the instance buffer? I also experienced a graphic bug with using this code: struct instancedata { XMFLOAT3 Position; }; struct texturedvertex { XMFLOAT3 Pos; XMFLOAT2 uvkoord; }; struct geometry { ID3D11Buffer* vertexbuffer; int vertsanzahl; ID3D11Buffer* indicesbuffer; int indicesanzahl; }; geometry geometrybuffer; ID3D11Buffer* instancebuffer = NULL; ID3D11InputLayout* vertexlayouttextured = NULL; ::::: init buffers ::::: inp layout: D3D11_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "POSITION", 1, DXGI_FORMAT_R32G32B32_FLOAT, 1, 20, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, }; hr = device->CreateInputLayout( layout, numElements, pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), &vertexlayouttextured ); if( FAILED( hr ) ) return hr; rendering: UINT trianglebuff = sizeof(texturedvertex); UINT instancebuff = sizeof(instancedata); UINT zerooffset = 0; immediatecontext->IASetInputLayout( vertexlayouttextured ); immediatecontext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY::D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); //Triangle strip immediatecontext->IASetVertexBuffers( 0, 1, &geometrybuffer.vertexbuffer ,&trianglebuff , &zerooffset ); //set the geometrybuffer immediatecontext->IASetVertexBuffers( 1, 1, &instancebuffer ,&instancebuff , &zerooffset ); //set the instance buffer immediatecontext->VSSetShader( vertexshader, NULL, 0 ); //set vertexshader immediatecontext->VSSetConstantBuffers( 0, 1, &matrixbuffer ); //containing world view projection matrices immediatecontext->PSSetShader( pixelshader, NULL, 0 ); //set pixelshader immediatecontext->PSSetShaderResources(0,1,&textur); //set textur immediatecontext->Map( instancebuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource); instancedata *data = ( instancedata* )MappedResource.pData; //map the instance-data for (int i = 0; i < sys.bodiesl();i++) { data.Position = XMFLOAT3((float)(sys.hks.Position.x / scaler),(float)(sys.hks.Position.y / scaler),(float)(sys.hks.Position.z / scaler)); } immediatecontext->Unmap( instancebuffer, 0 ); //update positions immediatecontext->DrawIndexedInstanced(geometrybuffer.indicesanzahl,sys.bodies(),0,0,0); //draw as many instances as bodies hlsl shader: static const float PI = 3.14159265f; cbuffer matrix : register( b0 ) //matrices { row_major matrix World; row_major matrix View; row_major matrix Projection; }; Texture2D<float4> Textur : register(t0); SamplerState Meshtexturesampler { Filter = MIN_MAG_MIP_LINEAR; AddressU = Wrap; AddressV = Wrap; }; //textures, sampler struct VS_INPUT { float4 Pos : POSITION0; float2 Textcoord : TEXCOORD0; float4 instancepos : POSITION1; }; struct PS_INPUT { float4 Pos : SV_POSITION; float2 Textcoord : TEXCOORD0; }; //input structures PS_INPUT VS( VS_INPUT input ) { PS_INPUT output = (PS_INPUT)0; input.Pos.x += input.instancepos.x; input.Pos.y += input.instancepos.y; input.Pos.z += input.instancepos.z; output.Pos = mul(input.Pos,World); output.Pos = mul(output.Pos,View); output.Pos = mul(output.Pos,Projection); output.Textcoord = input.Textcoord; return output; } float4 PS( PS_INPUT input) : SV_Target { return Textur.Sample(Meshtexturesampler,input.Textcoord); } Now the problem is that the second instance always stays at the center of the scene but it should move i guess there are some errors in the input layout declaration?
  9. Hello, its me again. After i sucessfully initialised my shader code i experienced some performance issues with drawing my scene which contains spherical geometrie. The issue seems to be the seperate drawing calls which tookes about 0,3ms. first i thought my graphics card would be too slow to give me the necessary performance to render 1800 spheres but then i increased the vertex-count of my "sphere" and the rendering tooked the same time. Now i know that the Issue has to be the cpu-gpu-communication, but everything at all i cant imagine how a single draw call can cost that much time?... if i look at modern games having hundreds of models displayed at the same time. A solution would be to use instancing but iam not really sure how i can use it at dx11, basicly all that should be done is telling the gpu to loop my indexbuffer content n times insteat of calling the drawing such often. The problem is i have absolutly no idea how to do that? Creating the whole indesbuffer containing 1800 times the same index-sequence seams to be very messy and unnecessary. And if you use different models at the same time i guess a drawing call which takes 200 ms for 1000 different object buffers isnt really aceptable so how do YOU manage it?
  10. directx user

    problems with shader matrices

    thx for your reply, but i detected the problem. The Problem was the matrix assigment, i changed the assignment to the map-unmap solution and it worked. thx anyway for telling me the fact that the shader can handle the storaging of the matrice as column major or row major i will recognize it when i will have my next transformation Issues .
  11. Hello Forum, I have currently some issues with my shader code: cbuffer matrizen : register( b0 ) { row_major matrix World; row_major matrix View; row_major matrix Projection; }; struct VS_INPUT { float4 Pos : POSITION; }; struct PS_INPUT { float4 Pos : SV_POSITION; }; //-------------------------------------------------------------------------------------- // Vertex Shader //-------------------------------------------------------------------------------------- PS_INPUT VS( VS_INPUT input ) { PS_INPUT output = (PS_INPUT)0; output.Pos = mul(input.Pos,World); output.Pos = mul(output.Pos,View); output.Pos = mul(output.Pos,Projection); return output; } //-------------------------------------------------------------------------------------- // Pixel Shader //-------------------------------------------------------------------------------------- float4 PS( PS_INPUT input) : SV_Target { return float4(1.0f,0.0f,0.0f,1.0f); } actually this code is mostly copied from the directx sample browser and should work as it also works in the sample project. The Problem is, it doesnt displays anything if i apply the matrix transformations inside the vertex shader. The Matrices are assigned over this code. struct Mats { XMMATRIX World; XMMATRIX View; XMMATRIX Projection; }; ........................ Mats mat; mat.World = XMMatrixIdentity(); //no geometry transformations XMVECTOR Eye = XMVectorSet( 0.0f, 0.0f, 5.0f, 0.0f ); XMVECTOR At = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f ); XMVECTOR Up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f ); mat.View = XMMatrixLookAtLH( Eye, At, Up ); //looking on the triangle mat.Projection = XMMatrixPerspectiveFovLH( XM_PIDIV4, (FLOAT)width / (FLOAT)height, 0.01f, 100.0f ); //calculating perspective matrix immediatecontext->UpdateSubresource( Matrixbuffer 0, NULL, &mat, 0, 0 ); //updating matrices drawing the content: immediatecontext->VSSetShader( vertexshader, NULL, 0 ); //using the vertexshader immediatecontext->VSSetConstantBuffers( 0, 1, &Matrixbuffer ); //assign matrices to the vertexshader immediatecontext->PSSetShader( pixelshader, NULL, 0 ); //using the pixelshader immediatecontext->Draw( 3, 0 ); //drawing three vertices (one single triangle) swapchain->Present( 0, 0 ); I guess there is a really easy solution to this problem but currently i dont know how i could fix that. EDIT: Leaving the matrices Identity matrices doesnt solves the problem so the problem has to be inside the matrix assignment (without doing the matrix transformations it display the triangle)
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!