Skip to content

Commit fcea4a1

Browse files
committed
xrRender_R3-R4: removed code duplication from shaders creation code
1 parent 0e88131 commit fcea4a1

File tree

2 files changed

+19
-77
lines changed

2 files changed

+19
-77
lines changed

src/Layers/xrRenderPC_R3/r3_shaders.cpp

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ template <typename T>
77
static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name,
88
T*& result, bool const disasm)
99
{
10-
// XXX: disasm it
11-
1210
result->sh = ShaderTypeTraits<T>::CreateHWShader(buffer, buffer_size);
1311

1412
ID3DShaderReflection* pReflection = 0;
@@ -23,7 +21,7 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
2321
}
2422
else
2523
{
26-
Msg("! D3DReflectShader %s hr == 0x%08x", file_name, _hr);
24+
Msg("! D3D10ReflectShader %s hr == 0x%08x", file_name, _hr);
2725
}
2826

2927
return _hr;
@@ -34,58 +32,32 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
3432
{
3533
// XXX: what's going on with casts here???
3634
HRESULT _result = E_FAIL;
35+
pcstr extension = ".hlsl";
3736
if (pTarget[0] == 'p')
3837
{
38+
extension = ".ps";
3939
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SPS*&)result, disasm);
4040
}
4141
else if (pTarget[0] == 'v')
4242
{
43-
// XXX: try to use code below
44-
// _result = create_shader(pTarget, buffer, buffer_size, file_name, (SVS*&)result, disasm);
45-
43+
extension = ".vs";
4644
SVS* svs_result = (SVS*)result;
47-
_result = HW.pDevice->CreateVertexShader(buffer, buffer_size, &svs_result->sh);
48-
49-
if (!SUCCEEDED(_result))
50-
{
51-
Log("! VS: ", file_name);
52-
Msg("! CreatePixelShader hr == 0x%08x", _result);
53-
return E_FAIL;
54-
}
55-
56-
ID3DShaderReflection* pReflection = 0;
57-
_result = D3D10ReflectShader(buffer, buffer_size, &pReflection);
58-
59-
// Parse constant, texture, sampler binding
60-
// Store input signature blob
61-
if (SUCCEEDED(_result) && pReflection)
45+
_result = create_shader(pTarget, buffer, buffer_size, file_name, svs_result, disasm);
46+
if (SUCCEEDED(_result))
6247
{
63-
// TODO: DX10: share the same input signatures
64-
6548
// Store input signature (need only for VS)
66-
// CHK_DX( D3DxxGetInputSignatureBlob(pShaderBuf->GetBufferPointer(), pShaderBuf->GetBufferSize(),
67-
// &_vs->signature) );
6849
ID3DBlob* pSignatureBlob;
6950
CHK_DX(D3DGetInputSignatureBlob(buffer, buffer_size, &pSignatureBlob));
7051
VERIFY(pSignatureBlob);
7152

7253
svs_result->signature = RImplementation.Resources->_CreateInputSignature(pSignatureBlob);
7354

7455
_RELEASE(pSignatureBlob);
75-
76-
// Let constant table parse it's data
77-
svs_result->constants.parse(pReflection, RC_dest_vertex);
78-
79-
_RELEASE(pReflection);
80-
}
81-
else
82-
{
83-
Log("! VS: ", file_name);
84-
Msg("! D3DXFindShaderComment hr == 0x%08x", _result);
8556
}
8657
}
8758
else if (pTarget[0] == 'g')
8859
{
60+
extension = ".gs";
8961
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SGS*&)result, disasm);
9062
}
9163
else
@@ -96,11 +68,9 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
9668
if (disasm)
9769
{
9870
ID3DBlob* disasm = 0;
99-
D3DDisassemble(buffer, buffer_size, FALSE, 0, &disasm);
100-
// D3DXDisassembleShader (LPDWORD(code->GetBufferPointer()), FALSE, 0, &disasm );
71+
D3DDisassemble(buffer, buffer_size, FALSE, nullptr, &disasm);
10172
string_path dname;
102-
strconcat(sizeof(dname), dname, "disasm" DELIMITER, file_name,
103-
('v' == pTarget[0]) ? ".vs" : ('p' == pTarget[0]) ? ".ps" : ".gs");
73+
strconcat(sizeof(dname), dname, "disasm" DELIMITER, file_name, extension);
10474
IWriter* W = FS.w_open("$logs$", dname);
10575
W->w(disasm->GetBufferPointer(), (u32)disasm->GetBufferSize());
10676
FS.w_close(W);

src/Layers/xrRenderPC_R4/r4_shaders.cpp

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ template <typename T>
1313
static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name,
1414
T*& result, bool const disasm)
1515
{
16-
// XXX: disasm it
17-
1816
result->sh = ShaderTypeTraits<T>::CreateHWShader(buffer, buffer_size);
1917

2018
ID3DShaderReflection* pReflection = 0;
@@ -38,72 +36,48 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
3836
static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name,
3937
void*& result, bool const disasm)
4038
{
41-
// XXX: what's going on with casts here???
4239
HRESULT _result = E_FAIL;
40+
pcstr extension = ".hlsl";
4341
if (pTarget[0] == 'p')
4442
{
43+
extension = ".ps";
4544
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SPS*&)result, disasm);
4645
}
4746
else if (pTarget[0] == 'v')
4847
{
49-
// XXX: try to use code below
50-
// _result = create_shader(pTarget, buffer, buffer_size, file_name, (SVS*&)result, disasm);
51-
48+
extension = ".vs";
5249
SVS* svs_result = (SVS*)result;
53-
_result = HW.pDevice->CreateVertexShader(buffer, buffer_size, 0, &svs_result->sh);
54-
55-
if (!SUCCEEDED(_result))
56-
{
57-
Log("! VS: ", file_name);
58-
Msg("! CreatePixelShader hr == 0x%08x", _result);
59-
return E_FAIL;
60-
}
61-
62-
ID3DShaderReflection* pReflection = 0;
63-
_result = D3DReflect(buffer, buffer_size, IID_ID3DShaderReflection, (void**)&pReflection);
64-
65-
// Parse constant, texture, sampler binding
66-
// Store input signature blob
67-
if (SUCCEEDED(_result) && pReflection)
50+
_result = create_shader(pTarget, buffer, buffer_size, file_name, svs_result, disasm);
51+
if (SUCCEEDED(_result))
6852
{
69-
// TODO: DX10: share the same input signatures
70-
7153
// Store input signature (need only for VS)
72-
// CHK_DX( D3DxxGetInputSignatureBlob(pShaderBuf->GetBufferPointer(), pShaderBuf->GetBufferSize(),
73-
// &_vs->signature) );
7454
ID3DBlob* pSignatureBlob;
7555
CHK_DX(D3DGetInputSignatureBlob(buffer, buffer_size, &pSignatureBlob));
7656
VERIFY(pSignatureBlob);
7757

7858
svs_result->signature = RImplementation.Resources->_CreateInputSignature(pSignatureBlob);
7959

8060
_RELEASE(pSignatureBlob);
81-
82-
// Let constant table parse it's data
83-
svs_result->constants.parse(pReflection, RC_dest_vertex);
84-
85-
_RELEASE(pReflection);
86-
}
87-
else
88-
{
89-
Log("! VS: ", file_name);
90-
Msg("! D3DXFindShaderComment hr == 0x%08x", _result);
9161
}
9262
}
9363
else if (pTarget[0] == 'g')
9464
{
65+
extension = ".gs";
9566
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SGS*&)result, disasm);
9667
}
9768
else if (pTarget[0] == 'c')
9869
{
70+
extension = ".cs";
9971
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SCS*&)result, disasm);
10072
}
10173
else if (pTarget[0] == 'h')
10274
{
75+
extension = ".hs";
10376
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SHS*&)result, disasm);
10477
}
10578
else if (pTarget[0] == 'd')
10679
{
80+
extension = ".ds";
10781
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SDS*&)result, disasm);
10882
}
10983
else
@@ -115,10 +89,8 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
11589
{
11690
ID3DBlob* disasm = 0;
11791
D3DDisassemble(buffer, buffer_size, FALSE, 0, &disasm);
118-
// D3DXDisassembleShader (LPDWORD(code->GetBufferPointer()), FALSE, 0, &disasm );
11992
string_path dname;
120-
strconcat(sizeof(dname), dname, "disasm" DELIMITER, file_name,
121-
('v' == pTarget[0]) ? ".vs" : ('p' == pTarget[0]) ? ".ps" : ".gs");
93+
strconcat(sizeof(dname), dname, "disasm" DELIMITER, file_name, extension);
12294
IWriter* W = FS.w_open("$logs$", dname);
12395
W->w(disasm->GetBufferPointer(), (u32)disasm->GetBufferSize());
12496
FS.w_close(W);

0 commit comments

Comments
 (0)