unity-game-enginevisual-studio-codeshaderhlslcompute-shader

'redefinition of script' and 'type is ambiguous' errors


I'm writing a compute shader in unity and am writing various HLSL scripts which will be referenced in the compute shader using #include.

I have a struct called Move, in a script called MoveC.hlsl. I deleted and rewrote the reference to this script in another document. I then get an error on this struct, saying : "Redefinition of 'Move'". The script that is referancing 'MoveC.hlsl' is called 'GenerateMovesC.hlsl' and has errors under all references to the Move struct, with the error "Type 'Move' is ambiguous between 'Move' and 'Move'.

I'm still new to compute shaders and HLSL and so does any one know what's going on and what I can do to fix it?

The MoveC.hlsl document:

struct Move {
    int startSquare;
    int endSquare;
    uint capturedSquares;
    uint previousBoard[6];

    void SetMove(int startSquareNew, int endSquareNew, uint previousBoardNew[6])
    {
        startSquare = startSquareNew;
        endSquare = endSquareNew;
        previousBoard = previousBoardNew;
        capturedSquares = 0;
    }

    void SetMove(int startSquareNew, int endSquareNew, uint previousBoardNew[6], uint caputredSquaresNew)
    {
        startSquare = startSquareNew;
        endSquare = endSquareNew;
        capturedSquares = caputredSquaresNew;
        previousBoard = previousBoardNew;
    }
};

The GenerateMovesC.hlsl document:

#include "MoveC.hlsl"
#include "BoardC.hlsl"
#include "PieceC.hlsl"

class GenerateMoves {
    Move moves[49];
    Move captureMoves[13];
    Board previousBoard;
    int targetSquare;

    void generateMoves(Board board) {
        Move blankMoves[49];
        moves = blankMoves;
        Move blankCaptureMoves[13];
        previousBoard.SetBoard(board);
        captureMoves = blankCaptureMoves;
        int colourToMove = board.colourToMove;
        int startIndex = (colourToMove == white && board.bitBoard[whiteKing] == 0) ? 4 : 0; 
    }
};

I am using visual studio code with the HLSL tools extension


Solution

  • Alright, I've finally worked it out. So what was happening, was that I'd included a reference to the MoveGenerationC script in another hlsl script called MCCompute using #include, and also included the MoveC script as well. I think this meant I was actually referencing the MoveC script twice, once directly, and then a second time through the reference in the MoveGenerationC script, resulting in the 'redefinition of script' and 'type is ambiguous' errors. I wasn't using the move struct in MCCompute, so didn't get any errors in this script, which is why I didn't think to include it in my question. However, once I deleted the direct reference to MoveC in my MCCompute script, the errors disappeared. I though that I would only be able to use the Move struct in my MCCompute script if I referenced it directly, but I am still able to use it since it is referenced in the MoveGeneration script which is referenced in the MCCompute script.