Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constant buffer packed values addressed erroneously #27

Open
albertodemichelis opened this issue Aug 25, 2014 · 0 comments
Open

constant buffer packed values addressed erroneously #27

albertodemichelis opened this issue Aug 25, 2014 · 0 comments

Comments

@albertodemichelis
Copy link

It look like if several constant buffer values get packed in a single "constant buffer register" the hlslcc addresses only the first value in the register

for example in the following shader the buffer is all packed in a single register ("cb[0]")

EDIT: the problem only occurs when 2 or more "variables" are accessed at once (by the D3D HLSL optimizer) using a swizzle like "cb[0].xy" (when the optimizer doesn't pack them in a swizzle it works fine)


INPUT

cbuffer RenderTargetParams {
int Width;
int Height;
float AspectRatio;
}

struct VS_model0_ZNORMAL_Input {
float4 ObjectPosition : POSITION;
float3 Normal : NORMAL;

};

struct VS_model0_GATHER_Output {
float4 PixelPosition : SV_Position;
};

VS_model0_GATHER_Output main(VS_model0_ZNORMAL_Input input)
{
VS_model0_GATHER_Output output = (VS_model0_GATHER_Output)0;
float2 _screenuvnormalized;

_screenuvnormalized = float2(input.ObjectPosition.x / Width, input.ObjectPosition.y / Height);
output.PixelPosition.xy = _screenuvnormalized;
output.PixelPosition.zw = float2(Width * 2, Height * 2);
return output;

}


ASM

// Buffer Definitions:
//
// cbuffer RenderTargetParams
// {
//
// int Width; // Offset: 0 Size: 4
// int Height; // Offset: 4 Size: 4
// float AspectRatio; // Offset: 8 Size: 4 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// RenderTargetParams cbuffer NA NA 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION 0 xyzw 0 NONE float xy
// NORMAL 0 xyz 1 NONE float
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position 0 xyzw 0 POS float xyzw
//
vs_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[1], immediateIndexed
dcl_input v0.xy
dcl_output_siv o0.xyzw, position
dcl_temps 1
itof r0.xy, cb0[0].xyxx
div o0.xy, v0.xyxx, r0.xyxx
ishl r0.xy, cb0[0].xyxx, l(1, 1, 0, 0)
itof o0.zw, r0.xxxy
ret


OUTPUT

version 430

extension GL_ARB_shader_bit_encoding : require

struct vec1 {
float x;
};
struct uvec1 {
uint x;
};
struct ivec1 {
int x;
};
out gl_PerVertex {
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];};
subroutine void SubroutineType();
layout(location = 0) uniform struct RenderTargetParamsVS_Type {
int Width;
int Height;
float AspectRatio;
} RenderTargetParamsVS;
layout(location = 0) in vec4 dcl_Input0;
vec4 Input0;

undef Output0

define Output0 phase0_Output0

vec4 phase0_Output0;
vec4 Temp[1];
ivec4 Temp_int[1];
uvec4 Temp_uint[1];
void main()
{
Input0 = dcl_Input0;
Temp_int[0].xy = floatBitsToInt(vec4(RenderTargetParamsVS.Width).xy);
Output0.xy = (vec4(Input0.xyxx / intBitsToFloat(Temp_int[0]).xyxx)).xy;
Temp_int[0].xy = (RenderTargetParamsVS.Width << ivec4(0x1, 0x1, 0x0, 0x0)).xy;
Output0.zw = (vec4(Temp_int[0].xxxy).zw);
gl_Position = vec4(phase0_Output0);
return;
}

the correct result should be more like

Temp_int[0].xy = (vec4(RenderTargetParamsVS.Width,RenderTargetParamsVS.Height,0,0) << ivec4(0x1, 0x1, 0x0, 0x0)).xy;

and

Temp_int[0].xy = floatBitsToInt(vec4(RenderTargetParamsVS.Width,RenderTargetParamsVS.Height,0,0).xy);

thank you for you time
Alberto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant