Changeset 1590


Ignore:
Timestamp:
Jul 8, 2012, 12:25:52 AM (8 years ago)
Author:
sam
Message:

core: start working on a higher level LolFx compiler based on the latest
GLSL grammar and some personal attempts at writing an HLSL grammar.

Location:
trunk
Files:
6 added
4 deleted
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r1570 r1590  
    4949    gpu/vertexbuffer.cpp gpu/vertexbuffer.h \
    5050    gpu/framebuffer.cpp gpu/framebuffer.h \
     51    \
    5152    gpu/defaultmaterial.lolfx \
    5253    gpu/emptymaterial.lolfx \
    5354    gpu/testmaterial.lolfx \
     55    \
     56    gpu/lolfx-compiler.cpp gpu/lolfx-compiler.h \
     57    generated/lolfx-parser.cpp generated/lolfx-parser.h \
     58    generated/lolfx-scanner.cpp \
    5459    \
    5560    image/image.cpp image/image.h image/image-private.h \
     
    7580        bison -o generated/easymesh-parser.cpp --defines=generated/easymesh-parser.h \
    7681              -d -b generated/easymesh easymesh/easymesh-parser.y
     82        flex -o generated/lolfx-scanner.cpp gpu/lolfx-scanner.l
     83        bison -o generated/lolfx-parser.cpp --defines=generated/lolfx-parser.h \
     84              -d -b generated/lolfx gpu/lolfx-parser.y
    7785.FORCE:
    7886endif
    7987
    80 EXTRA_DIST = easymesh/easymesh-scanner.l easymesh/easymesh-parser.y
     88EXTRA_DIST = easymesh/easymesh-scanner.l easymesh/easymesh-parser.y \
     89             gpu/lolfx-scanner.l gpu/lolfx-parser.y
    8190
    8291sdl_sources = \
  • trunk/src/gpu/lolfx-parser.y

    r1589 r1590  
    11%{
    2 #include <cstdio>
    3 #include <iostream>
    4 
    5 extern "C" int yylex();
    6 extern "C" int yyparse();
    7 extern "C" FILE *yyin;
    8 extern "C" int yylineno;
    9 
    10 void yyerror(const char *s);
     2//
     3// Lol Engine
     4//
     5// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
     6//   This program is free software; you can redistribute it and/or
     7//   modify it under the terms of the Do What The Fuck You Want To
     8//   Public License, Version 2, as published by Sam Hocevar. See
     9//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
     10//
     11
     12#if defined HAVE_CONFIG_H
     13#   include "config.h"
     14#endif
     15
     16#include "core.h"
     17
     18#include <string>
     19
    1120%}
     21
     22%require "2.3"
     23%debug
     24%defines
     25%skeleton "lalr1.cc"
     26%name-prefix="lol"
     27%define parser_class_name "LolFxParser"
     28%locations
     29%parse-param { class LolFxCompiler& mc }
     30%error-verbose
    1231
    1332/* The classic Bison union trick */
     
    2039}
    2140
    22 %type <sval> lolfx_shader_name
     41/* %type <sval> lolfx_shader_name */
    2342
    2443 /*
     
    181200%token PREPROCESSOR_REGION
    182201
     202%token PRAGMA_LOLFX
     203
    183204 /*
    184205  * HLSL reserved keywords
     
    208229
    209230 /*
     231  * Special tokens
     232  */
     233
     234%token T_END 0
     235%token T_ERROR
     236
     237 /*
    210238  * Our entry point
    211239  */
    212240
    213241%start lolfx_file
     242
     243%{
     244#include "gpu/lolfx-compiler.h"
     245
     246#undef yylex
     247#define yylex mc.m_lexer->lex
     248%}
    214249
    215250%%
     
    692727
    693728lolfx_technique:
    694     HT_TECHNIQUE IDENTIFIER '{' pass_list '}' { std::cout << "New tech" << std::endl; }
     729    HT_TECHNIQUE IDENTIFIER '{' pass_list '}' { std::cout << "New tech " << $2 << std::endl; }
    695730    ;
    696731
     
    705740
    706741pass:
    707     HT_PASS IDENTIFIER '{' pass_stmt_list '}' { std::cout << "New pass" << std::endl; }
     742    HT_PASS IDENTIFIER '{' pass_stmt_list '}' { std::cout << "New pass " << $2 << std::endl; }
    708743    ;
    709744
     
    737772
    738773lolfx_shader:
    739     lolfx_shader_region glsl_translation_unit
    740   | lolfx_shader_region
    741     ;
    742 
    743 lolfx_shader_region:
    744     PREPROCESSOR_REGION lolfx_shader_name { std::cout << "new shader " << $2 << std::endl; }
    745     ;
    746 
    747 lolfx_shader_name:
    748     IDENTIFIER                            { $$ = $1; }
    749   | lolfx_shader_name '.' IDENTIFIER      { $$ = $3; } /* FIXME: concatenate */
     774    lolfx_shader_declaration glsl_translation_unit
     775    ;
     776
     777lolfx_shader_declaration:
     778    PRAGMA_LOLFX lolfx_shader_type '(' lolfx_shader_description_list ')' { std::cout << "new shader" << std::endl; }
     779    ;
     780
     781lolfx_shader_type:
     782    HT_VERTEXSHADER
     783  | HT_PIXELSHADER
     784    ;
     785
     786lolfx_shader_description_list:
     787    lolfx_shader_description ',' lolfx_shader_description
     788  | lolfx_shader_description
     789    ;
     790
     791lolfx_shader_description:
     792    IDENTIFIER '=' IDENTIFIER FLOATCONSTANT
     793  | IDENTIFIER '=' IDENTIFIER
    750794    ;
    751795
     
    13091353%%
    13101354
    1311 main()
     1355void lol::LolFxParser::error(const LolFxParser::location_type& l,
     1356                             const std::string& m)
    13121357{
    1313     yyin = stdin;//fopen("test.lolfx", "r");
    1314     do
    1315     {
    1316         yyparse();
    1317     }
    1318     while (!feof(yyin));
    1319 
    1320     fclose(yyin);
     1358    mc.Error(l, m);
    13211359}
    13221360
    1323 void yyerror(const char *s)
    1324 {
    1325     std::cout << "Parse error line " << yylineno << ": " << s << std::endl;
    1326     exit(-1);
    1327 }
    1328 
  • trunk/src/gpu/testmaterial.lolfx

    r1407 r1590  
    3333
    3434        // Ye old way
    35         vertexshader = ...
    36         geometryshader = ...
    37         pixelshader = ...
     35        vertexshader = blah;
     36        geometryshader = blah;
     37        pixelshader = blah;
    3838
    3939        // Ogre crap
    4040
    4141        // The D3D11 way, but we must make it work with GLSL too
    42         SetBlendState(AdditiveBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
    43         SetDepthStencilState(DisableDepth, 0);
    44         SetRasterizerState()
     42        //SetBlendState(AdditiveBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
     43        //SetDepthStencilState(DisableDepth, 0);
     44        //SetRasterizerState()
    4545
    46         SetVertexShader
    47         SetDomainShader
    48         SetHullShader
    49         SetGeometryShader
    50         SetPixelShader
    51         SetComputeShader /* WTF? */
     46        //SetVertexShader
     47        //SetDomainShader
     48        //SetHullShader
     49        //SetGeometryShader
     50        //SetPixelShader
     51        //SetComputeShader /* WTF? */
    5252
    53         SetRenderTargets(RTV0, DSV);
    54         SetRenderTargets(RTV0, RTV1, DSV);
    55         ...
    56         SetRenderTargets(RTV0, RTV1, RTV2, RTV3, RTV4, RTV5, RTV6, RTV7, DSV);
     53        //SetRenderTargets(RTV0, DSV);
     54        //SetRenderTargets(RTV0, RTV1, DSV);
     55        //...
     56        //SetRenderTargets(RTV0, RTV1, RTV2, RTV3, RTV4, RTV5, RTV6, RTV7, DSV);
    5757    }
    5858
     
    6161        // Autres vertex/pixel shaders avec éventuellement des
    6262        // dépendances sur le résultat des passes précédentes
    63         vertexshader = ...
     63        vertexshader = something_else;
    6464    }
    6565}
     
    6767/* Defines GLSL shader "Prout" */
    6868
    69 #section GLSL.Prout
     69#pragma lolfx vertexshader(lang=GLSL 1.20, name=prout)
    7070
    7171#version 120
    7272
    7373/* Valid with my GLSL compiler */
    74 #pragma lolfx semantic(in_Vertex, POSITION)
    75 #pragma lolfx semantic(in_Normal, NORMAL)
    76 #pragma lolfx semantic(in_Color, COLOR)
     74//#pragma lolfx semantic(in_Vertex, POSITION)
     75//#pragma lolfx semantic(in_Normal, NORMAL)
     76//#pragma lolfx semantic(in_Color, COLOR)
    7777attribute vec3 in_Vertex;
    7878attribute vec3 in_Normal;
     
    8181void main(void)
    8282{
    83     ...
     83    /* ... */
    8484}
    8585
    8686/* Defines GLSL shader "Zob" */
    87 
    88 #section GLSL.Zob
     87#pragma lolfx vertexshader(lang=GLSL 1.20, name=zob)
    8988
    9089void main(void)
    9190{
    92     shit fuck fuck shit;
     91    shit(); fuck(); fuck(); shit();
    9392}
    9493
    95 /* Defines HLSL shader "Prout" */
     94/* Defines HLSL vertex shader "Prout" */
    9695
    97 #section HLSL.Prout
     96#pragma lolfx vertexshader(lang=HLSL, name=prout)
    9897
    9998void main(void)
  • trunk/src/lolcore.vcxproj

    r1575 r1590  
    250250    <ClCompile Include="generated\easymesh-parser.cpp" />
    251251    <ClCompile Include="generated\easymesh-scanner.cpp" />
     252    <ClCompile Include="generated\lolfx-parser.cpp" />
     253    <ClCompile Include="generated\lolfx-scanner.cpp" />
    252254    <ClCompile Include="gpu\framebuffer.cpp" />
    253255    <ClCompile Include="gpu\indexbuffer.cpp" />
     256    <ClCompile Include="gpu\lolfx-compiler.cpp" />
    254257    <ClCompile Include="gpu\shader.cpp" />
    255258    <ClCompile Include="gpu\vertexbuffer.cpp" />
     
    562565    <ClInclude Include="generated\easymesh-parser.h" />
    563566    <ClInclude Include="generated\location.hh" />
     567    <ClInclude Include="generated\lolfx-parser.h" />
    564568    <ClInclude Include="generated\position.hh" />
    565569    <ClInclude Include="generated\stack.hh" />
    566570    <ClInclude Include="gpu\framebuffer.h" />
    567571    <ClInclude Include="gpu\indexbuffer.h" />
     572    <ClInclude Include="gpu\lolfx-compiler.h" />
    568573    <ClInclude Include="gpu\shader.h" />
    569574    <ClInclude Include="gpu\vertexbuffer.h" />
     
    622627    <None Include="easymesh\easymesh-parser.y" />
    623628    <None Include="easymesh\easymesh-scanner.l" />
     629    <None Include="gpu\lolfx-parser.y" />
     630    <None Include="gpu\lolfx-scanner.l" />
    624631  </ItemGroup>
    625632  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  • trunk/src/lolcore.vcxproj.filters

    r1577 r1590  
    240240    </ClCompile>
    241241    <ClCompile Include="generated\easymesh-scanner.cpp">
     242      <Filter>src\generated</Filter>
     243    </ClCompile>
     244    <ClCompile Include="generated\lolfx-parser.cpp">
     245      <Filter>src\generated</Filter>
     246    </ClCompile>
     247    <ClCompile Include="generated\lolfx-scanner.cpp">
    242248      <Filter>src\generated</Filter>
    243249    </ClCompile>
Note: See TracChangeset for help on using the changeset viewer.