• 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
directx user

Exceptions using createcomputeshader

7 posts in this topic

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;
            }
        }
      

    }
}


 

Edited by directx user
0

Share this post


Link to post
Share on other sites

Can you give the definition of backpropshader and how you initialize it? Normally you don't use sizeof nor feed a raw pointer to the CreateComputeShader method, generally you are returned a compiled binary blob which contains the shader binary and its size (among other metadata) and use GetBufferPointer() and GetBufferSize() to pass the correct values to this method. Also, I think it's not unusual for compiled shaders to be several kilobytes large, if the compiler is doing optimizations it may unroll loops inside the shader.to improve performance.

 

By the way, if backpropshader is not a fixed size array then sizeof is not doing what you think it is doing.

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

I think you are correct about that, my mistake. Does the debug layer return anything? Have you tried with a much simpler compute shader and getting the same error?

0

Share this post


Link to post
Share on other sites

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.

Edited by directx user
0

Share this post


Link to post
Share on other sites

Well, I have no proof that device or berechner are valid, so I blame one of them.

 

It would be nice to know what your callstack and the full text of the exception look like. Those will have more clues.

0

Share this post


Link to post
Share on other sites

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 huh.png .

 

 

 

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?

Edited by directx user
0

Share this post


Link to post
Share on other sites


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?

 

I'd need more information to help with this.

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