Windows Phone 8 Custom shaders?

Hello All,

Is support for custom shaders available for windows phone 8?

Cheers

Sorry, for the lack of information, I have no experience with WinPhone. Just some tip.
AFAIK WinRT and Windows Phone don’t allow runtime compilation of the shaders. Thus you should prebuild the shaders before uploading them to the device. Check the code of cocos2d-x to figure out how to load compiled shaders (since they are doing that somehow).

1 Like

Hey Dot,

Thanks for your reply.

I have already checked the way the Latest Port of Windows Phone 8 has been done.
The things which I figured out till now are:

  • ANGLE project is getting used for translation of OpenGL calls to D3D API calls.

  • Because Windows Phone 8 does not support compilation of shaders at runtime, so we need to use pre-compiled shaders.

  • The current cocod2dx windows phone 8 branch uses pre-compiled shader program Byte code array.

I have been able to convert my GLSL shaders to HLSL shaders and even can get pre-compiled forms of the vertex and pixel shaders either in Byte Code array or Compiled Shader Object.

The problem which I am facing is - " How to obtain Program Byte Code - the shader program linked with both shaders and get it saved to a file? "

Any help would be great :slight_smile:
I am still working on it, so hopefully something turns out well. :stuck_out_tongue:
Cheers

I have the same question. Cocos2d-x has precompiled shaders in a file, precompiledshaders.h (in the master repository).

But, how was this file generated? It is apparently different for each platform (winrt vs. wp8).

edit:

void CCPrecompiledShaders::savePrecompiledShaders()

Seems to be the trick. Unfortunately, I’m not sure I can access the output of this unless I run on WINRT. Seems we could take this code and run it on x86, no? I worry that the output might differ on different platforms, but it’s worth a shot.

Success! I have used custom shaders for winphone 8. It was not easy, though.

It involved 4 parts.

  1. Modify glslprecompiler from angle project to work with CC compatible shaders.
    Apply my patch, open glslPrecompiler.sln, and do the below before compiling:

    • in libGLESv2 define these macros in the preprocessor tab of c/c++ in its project properties:
      • COMPILE_SHADER
      • USE_FEATURE_LEVEL_9_3
      • ANGLE_ENABLE_D3D11
  2. Modify CCGLProgram to accept binary shader data.

  3. Added a special folder called pcShaders to wp8 project, with a batch file for building them.

    set pc=C:\dev\cocos\cocos2dx\platform\third_party\winrt\angleproject\src\glslPrecompiler\Release\glslPrecompiler.exe

    del precompiledshaders.h
    for %%v in (…\Resources\shaders*.vsh) do (
    copy …\Resources\shaders%%~nv.vsh
    copy …\Resources\shaders%%~nv.fsh
    call :glslpc %%~nv
    )

    pause
    goto :eof

    :glslpc
    set shader=%1
    %pc% -o=%shader%.tmp.h -a=%shader%Program -v=%shader%.vsh -f=%shader%.fsh
    type %shader%.tmp.h >> precompiledshaders.h
    del *.vsh *.fsh *.tmp.h
    goto :eof

  4. Add a macro to use the precompiled data on wp8, instead of the old way.

    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CCPLATFORM_WINRT)
    #include “pcShaders/precompiledshaders.h”
    #define initShader(I_CCGLPROGRAM, I_CCGLSHADER)
    I_CCGLPROGRAM->initWithPrecompiledByteArray(##I_CCGLSHADER##Program, sizeof(##I_CCGLSHADER##Program));
    #else
    #define initShader(I_CCGLPROGRAM, I_CCGLSHADER) I_CCGLPROGRAM->initWithVertexShaderFilename(“shaders/”#I_CCGLSHADER".vsh", “shaders/”#I_CCGLSHADER".fsh");
    #endif

There is my macro. To initialized a shader, you run:

initShader(pBWShaderProgram, ShaderName);

As opposed to:

pBWShaderProgram->initWithVertexShaderFilename("shaders/ShaderName.vsh", "shaders/ShaderName.fsh");

I attached the changes I made to source in the form of patches. I compiled against latest cocos-master branch.

In the angleproject, I had to fix a compile bug. This is why the updateSurface signature is modified. It has nothing to do with my changes, but it was a required fix.

Hi Adipose, thanks for the instructions. Have you seen E_INVALIDARG error when loading the precompiled shader? It’s happening on this line in libGLESv2\renender\Renderer11.cpp:

HRESULT result = mDevice->CreatePixelShader(function, length, NULL, &pshader);
ASSERT(SUCCEEDED(result));

If I turn on DX debug log, console displays this error:
D3D11 ERROR: ID3D11Device::CreatePixelShader: Encoded Pixel Shader size doesn’t match specified size. [ STATE_CREATION ERROR #192: CREATEPIXELSHADER_INVALIDSHADERBYTECODE]

Haitao, I think I have seen it. Make sure to enable USE_FEATURE_LEVEL_9_3, for libGLESv2 project, in the solution for glslprecompiler. If you want to send me your shader I can try it out. They should probably include a binary version of glslprecompiler with cocos.

By the way, I believe for WinRT you need 9_1, which generates shaders of about half the size. Then it complains about the compile size if you try to use it for WinPhone.

Good luck.

I tried both adding USE_FEATURE_LEVEL_9_3 and setting “feature level limit” in DX control panel, but always get the same 1588 byte output. Please try with your compiler and see if it can generate something different. Thanks a lot, I appreciate your help.

Here is the output I got. The size is 3360 bytes. Not sure what you are doing different, but try this to see if it works.

unsigned char SoftBrushProgram[] = {
166, 147,   0,   0, 142,   9,   2,   1, 
  0, 128,   0,   0,  82, 139,   0,   0, 
 10,   0,   0,   0,  97,  95, 112, 111, 
115, 105, 116, 105, 111, 110,   1,   0, 
  0,   0,   6,  20,   0,   0,   7,   0, 
  0,   0,  97,  95,  97, 108, 112, 104, 
 97,   0,   0,   0,   0,  80, 139,   0, 
  0,  10,   0,   0,   0,  97,  95, 116, 
101, 120,  67, 111, 111, 114, 100,   2, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0, 255, 255, 255, 255,   0, 
  0,   0,   0,   0,   0,   0,   0, 255, 
255, 255, 255,   0,   0,   0,   0,   0, 
  0,   0,   0, 255, 255, 255, 255,   0, 
  0,   0,   0,   0,   0,   0,   0, 255, 
255, 255, 255,   0,   0,   0,   0,   0, 
  0,   0,   0, 255, 255, 255, 255,   0, 
  0,   0,   0,   0,   0,   0,   0, 255, 
255, 255, 255,   0,   0,   0,   0,   0, 
  0,   0,   0, 255, 255, 255, 255,   0, 
  0,   0,   0,   0,   0,   0,   0, 255, 
255, 255, 255,   0,   0,   0,   0,   0, 
  0,   0,   0, 255, 255, 255, 255,   0, 
  0,   0,   0,   0,   0,   0,   0, 255, 
255, 255, 255,   0,   0,   0,   0,   0, 
  0,   0,   0, 255, 255, 255, 255,   0, 
  0,   0,   0,   0,   0,   0,   0, 255, 
255, 255, 255,   0,   0,   0,   0,   0, 
  0,   0,   0, 255, 255, 255, 255,   1, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   1,   0,   0,   0,   0, 
  3,   0,   0,   0,  92, 139,   0,   0, 
242, 141,   0,   0,  12,   0,   0,   0, 
 67,  67,  95,  77,  86,  80,  77,  97, 
116, 114, 105, 120,   0,   0,   0,   0, 
255, 255, 255, 255,   0,   0,   0,   0, 
  4,   0,   0,   0,  86, 139,   0,   0, 
  0,   0,   0,   0,   9,   0,   0,   0, 
117,  95, 101, 114,  97, 115, 105, 110, 
103,   0,   0,   0,   0,   0,   0,   0, 
  0, 255, 255, 255, 255,   1,   0,   0, 
  0,  94, 139,   0,   0,   0,   0,   0, 
  0,   9,   0,   0,   0, 117,  95, 116, 
101, 120, 116, 117, 114, 101,   0,   0, 
  0,   0,   0,   0,   0,   0, 255, 255, 
255, 255,   1,   0,   0,   0,   3,   0, 
  0,   0,  12,   0,   0,   0,  67,  67, 
 95,  77,  86,  80,  77,  97, 116, 114, 
105, 120,   0,   0,   0,   0,   0,   0, 
  0,   0,   9,   0,   0,   0, 117,  95, 
101, 114,  97, 115, 105, 110, 103,   0, 
  0,   0,   0,   1,   0,   0,   0,   9, 
  0,   0,   0, 117,  95, 116, 101, 120, 
116, 117, 114, 101,   0,   0,   0,   0, 
  2,   0,   0,   0,  52,   5,   0,   0, 
  4,   5,   0,   0,   0,   0,   0,   0, 
110, 183,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
 68,  88,  66,  67,  54, 166,  38, 130, 
 89,  17, 118,  93,  97, 120, 135, 224, 
201, 198, 138, 201,   1,   0,   0,   0, 
 52,   5,   0,   0,   6,   0,   0,   0, 
 56,   0,   0,   0,  56,   1,   0,   0, 
188,   2,   0,   0,  56,   3,   0,   0, 
108,   4,   0,   0, 184,   4,   0,   0, 
 65, 111, 110,  57, 248,   0,   0,   0, 
248,   0,   0,   0,   0,   2, 255, 255, 
196,   0,   0,   0,  52,   0,   0,   0, 
  1,   0,  40,   0,   0,   0,  52,   0, 
  0,   0,  52,   0,   1,   0,  36,   0, 
  0,   0,  52,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   1,   0,   0,   0, 
  1,   0,   0,   0,   1,   2, 255, 255, 
 81,   0,   0,   5,   1,   0,  15, 160, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
 31,   0,   0,   2,   0,   0,   0, 128, 
  0,   0,   7, 176,  31,   0,   0,   2, 
  0,   0,   0, 144,   0,   8,  15, 160, 
 66,   0,   0,   3,   0,   0,  15, 128, 
  0,   0, 228, 176,   0,   8, 228, 160, 
 11,   0,   0,   3,   1,   0,   8, 128, 
  0,   0, 255, 128,   0,   0, 170, 176, 
 10,   0,   0,   3,   1,   0,   1, 128, 
  0,   0, 170, 176,   0,   0, 255, 128, 
 88,   0,   0,   4,   0,   0,   8, 128, 
  0,   0,   0, 161,   1,   0,   0, 128, 
  1,   0, 255, 128,   1,   0,   0,   2, 
  0,   0,   7, 128,   1,   0,   0, 160, 
  1,   0,   0,   2,   1,   0,  15, 128, 
  0,   0, 234, 128,   1,   0,   0,   2, 
  3,   8,  15, 128,   0,   0, 228, 128, 
  1,   0,   0,   2,   0,   8,  15, 128, 
  1,   0, 228, 128,   1,   0,   0,   2, 
  1,   8,  15, 128,   1,   0, 228, 128, 
  1,   0,   0,   2,   2,   8,  15, 128, 
  1,   0, 228, 128, 255, 255,   0,   0, 
 83,  72,  68,  82, 124,   1,   0,   0, 
 64,   0,   0,   0,  95,   0,   0,   0, 
 89,   0,   0,   4,  70, 142,  32,   0, 
  0,   0,   0,   0,   1,   0,   0,   0, 
 90,   0,   0,   3,   0,  96,  16,   0, 
  0,   0,   0,   0,  88,  24,   0,   4, 
  0, 112,  16,   0,   0,   0,   0,   0, 
 85,  85,   0,   0,  98,  16,   0,   3, 
 50,  16,  16,   0,   0,   0,   0,   0, 
 98,  16,   0,   3,  66,  16,  16,   0, 
  0,   0,   0,   0, 101,   0,   0,   3, 
242,  32,  16,   0,   0,   0,   0,   0, 
101,   0,   0,   3, 242,  32,  16,   0, 
  1,   0,   0,   0, 101,   0,   0,   3, 
242,  32,  16,   0,   2,   0,   0,   0, 
101,   0,   0,   3, 242,  32,  16,   0, 
  3,   0,   0,   0, 104,   0,   0,   2, 
  1,   0,   0,   0,  69,   0,   0,   9, 
242,   0,  16,   0,   0,   0,   0,   0, 
 70,  16,  16,   0,   0,   0,   0,   0, 
 70, 126,  16,   0,   0,   0,   0,   0, 
  0,  96,  16,   0,   0,   0,   0,   0, 
 52,   0,   0,   7,  18,   0,  16,   0, 
  0,   0,   0,   0,  58,   0,  16,   0, 
  0,   0,   0,   0,  42,  16,  16,   0, 
  0,   0,   0,   0,  51,   0,   0,   7, 
 34,   0,  16,   0,   0,   0,   0,   0, 
 58,   0,  16,   0,   0,   0,   0,   0, 
 42,  16,  16,   0,   0,   0,   0,   0, 
 55,   0,   0,  10, 130,   0,  16,   0, 
  0,   0,   0,   0,  10, 128,  32,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
 10,   0,  16,   0,   0,   0,   0,   0, 
 26,   0,  16,   0,   0,   0,   0,   0, 
 54,   0,   0,   8, 114,   0,  16,   0, 
  0,   0,   0,   0,   2,  64,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
 54,   0,   0,   5, 242,  32,  16,   0, 
  0,   0,   0,   0, 166,  14,  16,   0, 
  0,   0,   0,   0,  54,   0,   0,   5, 
242,  32,  16,   0,   1,   0,   0,   0, 
166,  14,  16,   0,   0,   0,   0,   0, 
 54,   0,   0,   5, 242,  32,  16,   0, 
  2,   0,   0,   0, 166,  14,  16,   0, 
  0,   0,   0,   0,  54,   0,   0,   5, 
242,  32,  16,   0,   3,   0,   0,   0, 
 70,  14,  16,   0,   0,   0,   0,   0, 
 62,   0,   0,   1,  83,  84,  65,  84, 
116,   0,   0,   0,  10,   0,   0,   0, 
  1,   0,   0,   0,   0,   0,   0,   0, 
  6,   0,   0,   0,   2,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  1,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   1,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  6,   0,   0,   0,   1,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
 82,  68,  69,  70,  44,   1,   0,   0, 
  1,   0,   0,   0, 172,   0,   0,   0, 
  3,   0,   0,   0,  28,   0,   0,   0, 
  0,   4, 255, 255,   0,  65,   0,   0, 
248,   0,   0,   0, 124,   0,   0,   0, 
  3,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   1,   0,   0,   0, 
  1,   0,   0,   0, 143,   0,   0,   0, 
  2,   0,   0,   0,   5,   0,   0,   0, 
  4,   0,   0,   0, 255, 255, 255, 255, 
  0,   0,   0,   0,   1,   0,   0,   0, 
 13,   0,   0,   0, 162,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   1,   0,   0,   0, 
  0,   0,   0,   0, 115,  97, 109, 112, 
108, 101, 114,  95,  95, 117,  95, 116, 
101, 120, 116, 117, 114, 101,   0, 116, 
101, 120, 116, 117, 114, 101,  95,  95, 
117,  95, 116, 101, 120, 116, 117, 114, 
101,   0,  36,  71, 108, 111,  98,  97, 
108, 115,   0, 171, 162,   0,   0,   0, 
  1,   0,   0,   0, 196,   0,   0,   0, 
 16,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0, 220,   0,   0,   0, 
  0,   0,   0,   0,   4,   0,   0,   0, 
  2,   0,   0,   0, 232,   0,   0,   0, 
  0,   0,   0,   0,  95, 117,  95, 101, 
114,  97, 115, 105, 110, 103,   0, 171, 
  0,   0,   1,   0,   1,   0,   1,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
 77, 105,  99, 114, 111, 115, 111, 102, 
116,  32,  40,  82,  41,  32,  72,  76, 
 83,  76,  32,  83, 104,  97, 100, 101, 
114,  32,  67, 111, 109, 112, 105, 108, 
101, 114,  32,  57,  46,  51,  48,  46, 
 57,  50,  48,  48,  46,  49,  54,  51, 
 56,  52,   0, 171,  73,  83,  71,  78, 
 68,   0,   0,   0,   2,   0,   0,   0, 
  8,   0,   0,   0,  56,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  3,   0,   0,   0,   0,   0,   0,   0, 
  3,   3,   0,   0,  56,   0,   0,   0, 
  1,   0,   0,   0,   0,   0,   0,   0, 
  3,   0,   0,   0,   0,   0,   0,   0, 
  4,   4,   0,   0,  84,  69,  88,  67, 
 79,  79,  82,  68,   0, 171, 171, 171, 
 79,  83,  71,  78, 116,   0,   0,   0, 
  4,   0,   0,   0,   8,   0,   0,   0, 
104,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   3,   0,   0,   0, 
  0,   0,   0,   0,  15,   0,   0,   0, 
104,   0,   0,   0,   1,   0,   0,   0, 
  0,   0,   0,   0,   3,   0,   0,   0, 
  1,   0,   0,   0,  15,   0,   0,   0, 
104,   0,   0,   0,   2,   0,   0,   0, 
  0,   0,   0,   0,   3,   0,   0,   0, 
  2,   0,   0,   0,  15,   0,   0,   0, 
104,   0,   0,   0,   3,   0,   0,   0, 
  0,   0,   0,   0,   3,   0,   0,   0, 
  3,   0,   0,   0,  15,   0,   0,   0, 
 83,  86,  95,  84,  97, 114, 103, 101, 
116,   0, 171, 171,  68,  88,  66,  67, 
137, 181, 165,   4, 113,  53,  37, 174, 
 48,  55, 177, 214, 174, 222,  31,  52, 
  1,   0,   0,   0,   4,   5,   0,   0, 
  6,   0,   0,   0,  56,   0,   0,   0, 
 92,   1,   0,   0, 224,   2,   0,   0, 
 92,   3,   0,   0,  48,   4,   0,   0, 
148,   4,   0,   0,  65, 111, 110,  57, 
 28,   1,   0,   0,  28,   1,   0,   0, 
  0,   2, 254, 255, 232,   0,   0,   0, 
 52,   0,   0,   0,   1,   0,  36,   0, 
  0,   0,  48,   0,   0,   0,  48,   0, 
  0,   0,  36,   0,   1,   0,  48,   0, 
  0,   0,   0,   0,   4,   0,   1,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  1,   2, 254, 255,  81,   0,   0,   5, 
  5,   0,  15, 160,   0,   0,   0,  63, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,  31,   0,   0,   2, 
  5,   0,   0, 128,   0,   0,  15, 144, 
 31,   0,   0,   2,   5,   0,   1, 128, 
  1,   0,  15, 144,  31,   0,   0,   2, 
  5,   0,   2, 128,   2,   0,  15, 144, 
  9,   0,   0,   3,   0,   0,   1, 128, 
  3,   0, 228, 160,   1,   0, 228, 144, 
  9,   0,   0,   3,   0,   0,   2, 128, 
  4,   0, 228, 160,   1,   0, 228, 144, 
  2,   0,   0,   3,   0,   0,   1, 128, 
  0,   0,  85, 128,   0,   0,   0, 128, 
  5,   0,   0,   3,   0,   0,   4, 192, 
  0,   0,   0, 128,   5,   0,   0, 160, 
  9,   0,   0,   3,   0,   0,   1, 128, 
  2,   0, 228, 160,   1,   0, 228, 144, 
  1,   0,   0,   2,   1,   0,   2, 128, 
  0,   0,   0, 129,   9,   0,   0,   3, 
  1,   0,   1, 128,   1,   0, 228, 160, 
  1,   0, 228, 144,   4,   0,   0,   4, 
  0,   0,   3, 192,   0,   0,  85, 128, 
  0,   0, 228, 160,   1,   0, 228, 128, 
  1,   0,   0,   2,   0,   0,   8, 192, 
  0,   0,  85, 128,   1,   0,   0,   2, 
  0,   0,   3, 224,   2,   0, 228, 144, 
  1,   0,   0,   2,   0,   0,   4, 224, 
  0,   0,   0, 144, 255, 255,   0,   0, 
 83,  72,  68,  82, 124,   1,   0,   0, 
 64,   0,   1,   0,  95,   0,   0,   0, 
 89,   0,   0,   4,  70, 142,  32,   0, 
  0,   0,   0,   0,   4,   0,   0,   0, 
 95,   0,   0,   3,  18,  16,  16,   0, 
  0,   0,   0,   0,  95,   0,   0,   3, 
242,  16,  16,   0,   1,   0,   0,   0, 
 95,   0,   0,   3,  50,  16,  16,   0, 
  2,   0,   0,   0, 101,   0,   0,   3, 
 50,  32,  16,   0,   0,   0,   0,   0, 
101,   0,   0,   3,  66,  32,  16,   0, 
  0,   0,   0,   0, 103,   0,   0,   4, 
242,  32,  16,   0,   1,   0,   0,   0, 
  1,   0,   0,   0, 104,   0,   0,   2, 
  1,   0,   0,   0,  54,   0,   0,   5, 
 50,  32,  16,   0,   0,   0,   0,   0, 
 70,  16,  16,   0,   2,   0,   0,   0, 
 54,   0,   0,   5,  66,  32,  16,   0, 
  0,   0,   0,   0,  10,  16,  16,   0, 
  0,   0,   0,   0,  17,   0,   0,   8, 
 18,   0,  16,   0,   0,   0,   0,   0, 
 70, 142,  32,   0,   0,   0,   0,   0, 
  1,   0,   0,   0,  70,  30,  16,   0, 
  1,   0,   0,   0,  54,   0,   0,   6, 
 34,  32,  16,   0,   1,   0,   0,   0, 
 10,   0,  16, 128,  65,   0,   0,   0, 
  0,   0,   0,   0,  17,   0,   0,   8, 
 18,   0,  16,   0,   0,   0,   0,   0, 
 70, 142,  32,   0,   0,   0,   0,   0, 
  2,   0,   0,   0,  70,  30,  16,   0, 
  1,   0,   0,   0,  17,   0,   0,   8, 
 34,   0,  16,   0,   0,   0,   0,   0, 
 70, 142,  32,   0,   0,   0,   0,   0, 
  3,   0,   0,   0,  70,  30,  16,   0, 
  1,   0,   0,   0,   0,   0,   0,   7, 
 18,   0,  16,   0,   0,   0,   0,   0, 
 26,   0,  16,   0,   0,   0,   0,   0, 
 10,   0,  16,   0,   0,   0,   0,   0, 
 54,   0,   0,   5, 130,  32,  16,   0, 
  1,   0,   0,   0,  26,   0,  16,   0, 
  0,   0,   0,   0,  56,   0,   0,   7, 
 66,  32,  16,   0,   1,   0,   0,   0, 
 10,   0,  16,   0,   0,   0,   0,   0, 
  1,  64,   0,   0,   0,   0,   0,  63, 
 17,   0,   0,   8,  18,  32,  16,   0, 
  1,   0,   0,   0,  70, 142,  32,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
 70,  30,  16,   0,   1,   0,   0,   0, 
 62,   0,   0,   1,  83,  84,  65,  84, 
116,   0,   0,   0,  11,   0,   0,   0, 
  1,   0,   0,   0,   0,   0,   0,   0, 
  6,   0,   0,   0,   7,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  1,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  4,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
 82,  68,  69,  70, 204,   0,   0,   0, 
  1,   0,   0,   0,  72,   0,   0,   0, 
  1,   0,   0,   0,  28,   0,   0,   0, 
  0,   4, 254, 255,   0,  65,   0,   0, 
152,   0,   0,   0,  60,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   1,   0,   0,   0, 
  0,   0,   0,   0,  36,  71, 108, 111, 
 98,  97, 108, 115,   0, 171, 171, 171, 
 60,   0,   0,   0,   1,   0,   0,   0, 
 96,   0,   0,   0,  64,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
120,   0,   0,   0,   0,   0,   0,   0, 
 64,   0,   0,   0,   2,   0,   0,   0, 
136,   0,   0,   0,   0,   0,   0,   0, 
 95,  67,  67,  95,  77,  86,  80,  77, 
 97, 116, 114, 105, 120,   0, 171, 171, 
  3,   0,   3,   0,   4,   0,   4,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
 77, 105,  99, 114, 111, 115, 111, 102, 
116,  32,  40,  82,  41,  32,  72,  76, 
 83,  76,  32,  83, 104,  97, 100, 101, 
114,  32,  67, 111, 109, 112, 105, 108, 
101, 114,  32,  57,  46,  51,  48,  46, 
 57,  50,  48,  48,  46,  49,  54,  51, 
 56,  52,   0, 171,  73,  83,  71,  78, 
 92,   0,   0,   0,   3,   0,   0,   0, 
  8,   0,   0,   0,  80,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0, 
  3,   0,   0,   0,   0,   0,   0,   0, 
  1,   1,   0,   0,  80,   0,   0,   0, 
  1,   0,   0,   0,   0,   0,   0,   0, 
  3,   0,   0,   0,   1,   0,   0,   0, 
 15,  15,   0,   0,  80,   0,   0,   0, 
  2,   0,   0,   0,   0,   0,   0,   0, 
  3,   0,   0,   0,   2,   0,   0,   0, 
  3,   3,   0,   0,  84,  69,  88,  67, 
 79,  79,  82,  68,   0, 171, 171, 171, 
 79,  83,  71,  78, 104,   0,   0,   0, 
  3,   0,   0,   0,   8,   0,   0,   0, 
 80,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   3,   0,   0,   0, 
  0,   0,   0,   0,   3,  12,   0,   0, 
 80,   0,   0,   0,   1,   0,   0,   0, 
  0,   0,   0,   0,   3,   0,   0,   0, 
  0,   0,   0,   0,   4,  11,   0,   0, 
 89,   0,   0,   0,   0,   0,   0,   0, 
  1,   0,   0,   0,   3,   0,   0,   0, 
  1,   0,   0,   0,  15,   0,   0,   0, 
 84,  69,  88,  67,  79,  79,  82,  68, 
  0,  83,  86,  95,  80, 111, 115, 105, 
116, 105, 111, 110,   0, 171, 171, 171
};

By the way, I am using Windows 8 + Visual Studio 2012. The version of d3dcompile used on Windows 8 may be different, but I wouldn’t think it would matter. Can you send me your project files for glslprecompiler so I can compare them to mine?

Your shader code passed It might be because I am on a different cocos2dx fork. I am on https://github.com/MSOpenTech/cocos2d-x/tree/wp8-xaml because it supports mixing XAML and DirectX. Is your code based on the 2.2.1 zip download?

Thanks

it was based on master, shortly before 2.2.1 release. But I doubt there was any change in ANGLE project.

I made some progress. Now I can compile one of cocos2dx’s builtin shaders and it actually works Thanks a lot for your help. One more question about your change in main.cpp:

    glBindAttribLocation(program, kCCVertexAttrib_Color, kCCAttributeNameColor);
    glBindAttribLocation(program, kCCVertexAttrib_Position, kCCAttributeNamePosition);
    glBindAttribLocation(program, kCCVertexAttrib_TexCoords, kCCAttributeNameTexCoord);

These appear to be necessary for the compiled shaders to work. I defined other attributes in my shaders. Do I need to add them all here? I hope there is a way to do it at runtime like in OpenGL, so I don’t have to modify compiler code with every shader change.

No, I don’t think you need to do this for other attributes. As long as you use “glgetattriblocation”, you should be fine. The reason this is necessary is because in cocos, they bound these 3 attributes to specific indexes, and throughout cocos they use the hardcoded indexes. As a result, your compiled shader needs to place them at the same, hardcoded indexes.

When the compilation is done dynamically, you don’t have to worry about it because you can bind them at runtime (if you are using them):

    pBWShaderProgram->initWithVertexShaderFilename("shaders/ColorATOP.vsh",  "shaders/ColorATOP.fsh");
    pBWShaderProgram->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
    pBWShaderProgram->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
    pBWShaderProgram->link();

Notice how they come before the “link()” command. Well, in our case the link is occurring in the glslprecompiler, so we have to hardcode it then.

What did you have to do to get it working? Or did you just compile glslprecompiler from 2.2.1? Because I updated my tree, and it broke my precompiler. I see there was an update to ANGLE, and it seems to have broken something. I am going to try to track it down, but did you already figure it out?

I switched to cocos2d-x master branch (mostly 2.2.1), then applied your macro definitions and glBindAttribLocation changes. I added my own attributes as well. I think you are right, it must be because I was calling addAttribute before link(). I will try glGetAttribLocation(). I have 2 shaders, now I got one of them to work…

The other shader wasn’t working because I passed unsigned byte for one of the attributes, and DirectX didn’t like it. I fixed it by switching to float type. I also replaced addAttribute() before link() with glGetAttribLocation() after link() for attribute names other than those 3 so I don’t have to hard code them in glslPrecompiler. Now everything seems ok on emulator. Just need to figure out why the app always freezes WP8 on Lumia 920… :frowning:

So, I figured out the issue with the latest tree, then went to report it, and it was already reported… :slight_smile:

https://github.com/stammen/angleproject/issues/4

Basically, the flag has been removed that let you specify the shader level (9_3), so that won’t work. But you can do this:

For now, in Visual Studio, from the Debug menu select Graphics/DirectX Control Panel. Click
on Edit List and select the glslPrecompiler.exe in the src/glslPrecompiler/Debug folder.
Then Under Device Settings Select 9_3 for the Feature level limit.

Or, you can use my new patch and add back the feature for now.

I created a new patch which I am trying to get added to the angle code base. It requires us doing “-t=cocos” in order to compile the cocos compatible shaders.

Another topic related How could I extend new shaders for win8

Adipose Dan wrote:

I created a new patch which I am trying to get added to the angle code base. It requires us doing “-t=cocos” in order to compile the cocos compatible shaders.

Adipose Dan’s patch works well with angleproject wp8-xaml branch.
And maybe _Windows Software Development Kit (SDK) for Windows 8(.1)_ is needed if you can’t compile angleproject\src\glslPrecompiler\glslPrecompiler.sln.